Gentoo installation script
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gein 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. #!/usr/bin/env sh
  2. ## Helpers #######################################
  3. Logger() {
  4. #cat >> /gi_log
  5. printf "$Log\n"
  6. unset Log
  7. }
  8. Clean_Packages() {
  9. Log="Removing packages that are no longer needed..." && Logger
  10. emerge -uDN @world && \
  11. emerge -av --depclean && \
  12. emerge --update --changed-use --deep @world
  13. }
  14. Clean_Source() {
  15. Log="Removing temporary files..." && Logger
  16. rm -rf /usr/portage/packages/* \
  17. /usr/portage/distfiles/* \
  18. /var/tmp/portage/* \
  19. /stage3*.tar.bz2
  20. }
  21. Detect_Cores() {
  22. Log="Detecting total number of cores to compile with..." && Logger
  23. export CPU_CORES=$(grep -c ^processor /proc/cpuinfo)
  24. }
  25. Setup_Ssh() {
  26. Log="Setting up SSH..." && Logger
  27. rc-update add sshd default
  28. }
  29. ## Boot ##########################################
  30. Boot_Config() {
  31. Log="Editing system defaults..." && Logger
  32. nano /etc/rc.conf
  33. nano /etc/conf.d/keymaps
  34. nano /etc/conf.d/hwclock
  35. }
  36. Boot_Grub() {
  37. Log="Installing Grub..." && Logger
  38. read -ep "Where to install Grub: " Grub_Target && \
  39. emerge --ask --verbose sys-boot/grub:2 && \
  40. grub-install $Grub_Target && \
  41. grub-mkconfig -o /boot/grub/grub.cfg
  42. }
  43. ## Disks #########################################
  44. Disk_Fstab() {
  45. Log="Editing '/etc/fstab'..." && Logger
  46. echo "/swapfile none swap sw 0 0" >> /etc/fstab && \
  47. nano /etc/fstab
  48. }
  49. Disk_Setup() {
  50. Log="Please setup partitions and mount them before proceeding!" && Logger
  51. read -ep "Proceed with installation? [Y/N]: " Proceed && \
  52. if echo $Proceed | grep -iq "^n" ; then
  53. exit
  54. fi
  55. }
  56. ## Environment ###################################
  57. Env_Chroot() {
  58. Log="Chrooting into the environment..." && Logger
  59. cd /mnt/gentoo && \
  60. chroot /mnt/gentoo /bin/bash
  61. }
  62. Env_Reload() {
  63. Log="Reloading the environment..." && Logger
  64. source /etc/profile && \
  65. export PS1="(chroot) $PS1"
  66. }
  67. Env_Update() {
  68. Log="Updating the environment..." && Logger
  69. env-update && \
  70. Env_Reload
  71. }
  72. ## Host ##########################################
  73. HostsFile() {
  74. Log="Updating hosts file..." && Logger
  75. nano /etc/hosts
  76. }
  77. HostName() {
  78. Log="Setting hostname..." && Logger
  79. read -ep "Hostname: " Target_Hostname && \
  80. echo hostname="$Target_Hostname" > /etc/conf.d/hostname && \
  81. nano /etc/conf.d/hostname
  82. }
  83. ## Kernel ########################################
  84. Kernel_Install() {
  85. Log="Downloading, building, and installing kernel..." && Logger
  86. emerge --ask \
  87. sys-kernel/gentoo-sources \
  88. sys-kernel/linux-firmware \
  89. sys-apps/pciutils \
  90. sys-kernel/genkernel &&
  91. cd /usr/src/linux && \
  92. make -j${CPU_CORES} defconfig && \
  93. make -j${CPU_CORES} menuconfig && \
  94. make -j${CPU_CORES} && \
  95. make -j${CPU_CORES} modules_install && \
  96. make -j${CPU_CORES} install && \
  97. genkernel --install initramfs
  98. }
  99. ## Locale ########################################
  100. Locales() {
  101. Log="Setting desired locales..." && Logger
  102. nano /etc/locale.gen && \
  103. locale-gen && locale -a && \
  104. eselect locale list && \
  105. read -ep "Target locale: " Target_Locale && \
  106. eselect locale set ${Target_Locale}
  107. }
  108. ## Networking ####################################
  109. Network_Wired() {
  110. Log="Configuring wired networking..." && Logger
  111. USE="ipv6" emerge --ask --noreplace net-misc/netifrc && \
  112. emerge --ask net-misc/dhcpcd
  113. }
  114. Network_Wireless() {
  115. Log="Configuring wireless networking..." && Logger
  116. USE="dbus" emerge --ask net-wireless/wpa_supplicant && \
  117. USE="ethernet openvpn wifi" emerge --ask net-misc/connman
  118. }
  119. ## Portage #######################################
  120. Portage_MakeConf() {
  121. Log="Downloading portage 'make.conf'..." && Logger
  122. echo "Available GPU drivers: AMD, Intel, Nouveau, Virt (vbox & vmware)"
  123. read -ep "Which GPU's do you have?: " Target_GPU && \
  124. case $Target_GPU in
  125. amd|AMD)
  126. export Active_GPU="amdgpu radeonsi radeon"
  127. ;;
  128. intel|intel)
  129. export Active_GPU="intel"
  130. ;;
  131. nouveau|Nouveau)
  132. export Active_GPU="nouveau"
  133. ;;
  134. virt|Virt)
  135. export Active_GPU="virtualbox vmware"
  136. ;;
  137. *)
  138. echo "You must select one of the available options!"
  139. ;;
  140. esac
  141. echo '# /etc/portage/make.conf
  142. CHOST="x86_64-pc-linux-gnu"
  143. PORTDIR="/usr/portage"
  144. DISTDIR="${PORTDIR}/distfiles"
  145. PKGDIR="${PORTDIR}/packages"
  146. MAKEOPTS="-j${CPU_CORES}"
  147. EMERGE_DEFAULT_OPTS="--jobs=2"
  148. CFLAGS="-march=native -O3 -pipe"
  149. CXXFLAGS="${CFLAGS}"
  150. CPU_FLAGS_X86="mmx mmxext sse sse2 sse3"
  151. INPUT_DEVICES="libinput"
  152. VIDEO_CARDS="$Active_GPU"
  153. USE_Allow="bindist deblob minimal"
  154. USE_Block="-avahi -doc -llvm -multilib -systemd"
  155. USE="${USE_Block} ${USE_Allow}"' \
  156. > /mnt/gentoo/etc/portage/make.conf
  157. }
  158. Portage_Mirrors() {
  159. Log="Setting up portage mirrors..." && Logger
  160. mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf && \
  161. mkdir -vp /mnt/gentoo/etc/portage/repos.conf && \
  162. cp -v /mnt/gentoo/usr/share/portage/config/repos.conf \
  163. /mnt/gentoo/etc/portage/repos.conf/gentoo.conf && \
  164. cp -vL /etc/resolv.conf /mnt/gentoo/etc/
  165. }
  166. Portage_Sync() {
  167. Log="Syncing emerge and setting profile..." && Logger
  168. emerge-webrsync && \
  169. eselect profile list && \
  170. read -ep "Which profile?: " Target_Profile && \
  171. eselect profile set $Target_Profile && \
  172. emerge --ask --update --deep --newuse @world
  173. }
  174. ## Stage #########################################
  175. Stage_Download() {
  176. Log="Downloading and extracting Stage3 release..." && Logger
  177. S3_ARCH="amd64"
  178. S3_DATE="20170727"
  179. cd /mnt/gentoo
  180. wget http://distfiles.gentoo.org/releases/${S3_ARCH}/autobuilds/${S3_DATE}/stage3-${S3_ARCH}-nomultilib-${S3_DATE}.tar.bz2 && \
  181. tar xvjpf stage3-*.tar.bz2 --xattrs --numeric-owner
  182. }
  183. Stage_Mounts() {
  184. Log="Mounting hardware..." && Logger
  185. mount -t proc /proc /mnt/gentoo/proc && \
  186. mount --rbind /sys /mnt/gentoo/sys && \
  187. mount --make-rslave /mnt/gentoo/sys && \
  188. mount --rbind /dev /mnt/gentoo/dev && \
  189. mount --make-rslave /mnt/gentoo/dev
  190. }
  191. Stage_Swap() {
  192. Log="Setting up temporary swapfile..." && Logger
  193. SwapFile="/mnt/gentoo/swapfile"
  194. fallocate -l 4096M $SwapFile && \
  195. mkswap $SwapFile && \
  196. chmod 0600 $SwapFile && \
  197. swapon $SwapFile
  198. }
  199. ## Time ##########################################
  200. Time_Date() {
  201. Log="Setting current time via 'date'..." && Logger
  202. Ye=""; Mo=""; Da=""; Ho=""; Mi=""; Se=""
  203. date ${Ye}${Mo}${Da}${Ho}${Mi}${Se}
  204. }
  205. Time_Ntpd() {
  206. Log="Setting current time via 'ntpd'..." && Logger
  207. ntpd -q -g
  208. }
  209. Time_Zone() {
  210. Log="Setting timezone..." && Logger
  211. ls /usr/share/zoneinfo && \
  212. read -ep "Target region: " Target_Region && \
  213. ls /usr/share/zoneinfo/${Target_Region} && \
  214. read -ep "Target city: " Target_City && \
  215. TimeZone=${Target_Region}"/"${Target_City} && \
  216. echo "${TimeZone}" > /etc/timezone && \
  217. emerge --config sys-libs/timezone-data
  218. }
  219. ## User ##########################################
  220. User_Make() {
  221. Log="Creating user account..." && Logger
  222. read -ep "Setup a standard user? [Y/N]: " Proceed
  223. if echo $Proceed | grep -iq "^y"; then
  224. read -ep "Username: " Target_User && \
  225. useradd -m -G wheel $Target_User && \
  226. passwd $Target_User
  227. fi
  228. }
  229. User_Root() {
  230. Log="Setting root password..." && Logger
  231. passwd
  232. }
  233. ## Utilities #####################################
  234. Utils_Base() {
  235. Log="Adding Base utilities..." && Logger
  236. emerge --ask sudo
  237. if grep -Rqi 'intel' /proc/cpuinfo; then
  238. emerge --ask intel-microcode
  239. fi
  240. }
  241. Utils_Desktop() {
  242. Log="Installing desktop utilities..." && Logger
  243. USE="-minimal" emerge --ask --verbose x11-base/xorg-drivers && \
  244. emerge --ask x11-misc/xdotool x11-misc/wmctrl && \
  245. Env_Update && \
  246. USE="opengl vdpau" emerge --ask media-video/mpv && \
  247. USE="X" emerge --ask app-editors/vim && \
  248. MAKEOPTS="-j1" emerge --ask dev-util/cmake && \
  249. USE="-bindist" emerge --ask net-misc/openssh && \
  250. USE="minizip" emerge --ask sys-libs/zlib && \
  251. USE="text" emerge --ask app-text/xmlto && \
  252. USE="X xcb" emerge --ask x11-libs/cairo && \
  253. USE="icu" emerge --ask media-libs/harfbuzz && \
  254. USE="X" emerge --ask media-libs/imlib2 && \
  255. USE="xkb" emerge --ask x11-libs/libxcb && \
  256. USE="X" emerge --ask x11-libs/libxkbcommon && \
  257. USE="X" emerge --ask x11-libs/pango && \
  258. emerge --ask \
  259. media-fonts/dejavu \
  260. media-gfx/scrot \
  261. media-sound/cmus \
  262. media-video/ffmpeg \
  263. net-misc/youtube-dl \
  264. media-sound/alsa-utils \
  265. app-misc/ranger \
  266. app-misc/tmux \
  267. dev-vcs/git \
  268. net-misc/curl \
  269. www-client/elinks \
  270. x11-terms/rxvt-unicode \
  271. x11-wm/i3 \
  272. x11-misc/dmenu \
  273. x11-misc/i3lock \
  274. x11-misc/i3status && \
  275. USE="system-ffmpeg" L10N="en-us" emerge --ask www-client/chromium && \
  276. USE="ppapi" emerge --ask www-plugins/adobe-flash
  277. }
  278. Utils_Laptop() {
  279. Log="Installing laptop utilities..." && Logger
  280. USE="acpi bluetooth" emerge --ask app-laptop/laptop-mode-tools && \
  281. rc-update add laptop_mode default
  282. }
  283. Utils_Server() {
  284. Log="Installing server utilities..." && Logger
  285. # WIP
  286. }
  287. ## Execution #####################################
  288. case $1 in
  289. init|-i)
  290. Disk_Setup
  291. Time_Ntpd
  292. Stage_Download
  293. Stage_Mounts
  294. Stage_Swap
  295. Portage_MakeConf
  296. Portage_Mirrors
  297. Env_Chroot
  298. ;;
  299. base|-b)
  300. Env_Reload
  301. Detect_Cores
  302. Portage_Sync
  303. Time_Zone
  304. Locales
  305. Env_Update
  306. Kernel_Install
  307. Disk_Fstab
  308. HostName
  309. Network_Wired
  310. HostsFile
  311. User_Root
  312. Boot_Config
  313. Boot_Grub
  314. Utils_Base
  315. User_Make
  316. ;;
  317. desktop|-d)
  318. Utils_Desktop
  319. ;;
  320. laptop|-l)
  321. Network_Wireless
  322. Utils_Laptop
  323. ;;
  324. server|-s)
  325. Utils_Server
  326. ;;
  327. clean|-c)
  328. Clean_Packages
  329. Clean_Source
  330. ;;
  331. *)
  332. Log="You entered an invalid option.\n"
  333. Log=${Log}"Available options: init (-i), base (-b), "
  334. Log=${Log}"desktop (-d), laptop(-l), server (-s), clean (-c)"
  335. Logger
  336. ;;
  337. esac