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.sh 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. #!/usr/bin/env sh
  2. #
  3. # Copyright (C) 2017, 2018
  4. # * Johnathan C Maudlin <jcmdln@gmail.com>
  5. #
  6. # This software is licensed under the Azryn Software Labs Public License
  7. # of version 1.1.0 or later. You should have received a copy of the
  8. # Azryn Software Labs Public License along with this program. If not,
  9. # please see https://apl.azryn.org/ for a copy.
  10. #
  11. ## Grub installation path
  12. #
  13. # The 'PartitionBoot' variable *MUST* be set to proceed with the
  14. # installation. The example uses '/dev/sda' which will later install
  15. # GRUB to the MBR rather than a partition. Change this to your desired
  16. # '/boot' partition.
  17. #PartitionBoot="/dev/sda"
  18. ## GPU/VGA drivers
  19. #
  20. # The 'VideoCards' variable *MUST* be set to proceed with the
  21. # installation. Several examples have been provided based on brand or
  22. # target, though if you have any specific needs then set this variable
  23. # accordingly. If you don't need any video support, then set
  24. # 'VideoCards' to false like the last example.
  25. #VideoCards="i915 i965 intel"
  26. #VideoCards="amdgpu radeonsi"
  27. #VideoCards="nouveau nvidia"
  28. #VideoCards="virtualbox vmware"
  29. #VideoCards="false"
  30. ## Configuration
  31. #
  32. # This script relies on downloading configuration files from the main
  33. # repository. Here we will create the 'Source' variable which points to
  34. # the main repository, and 'Config' is the list of all configuration
  35. # files that will be installed.
  36. Source="https://raw.githubusercontent.com/jcmdln/gein/master"
  37. CONFIG() {
  38. # This is a list of all config files that need to be downloaded and
  39. # moved into place.
  40. Configs="
  41. /etc/portage/make.conf
  42. /etc/portage/package.accept_keywords
  43. /etc/portage/package.env
  44. /etc/portage/package.license
  45. /etc/portage/package.use/defaults
  46. /etc/portage/package.use/multilib
  47. /etc/portage/package.use/packages
  48. /etc/portage/sets/gein-base
  49. /etc/portage/sets/gein-i3wm
  50. /etc/portage/sets/gein-laptop
  51. /etc/portage/sets/gein-lxqt
  52. /etc/portage/sets/gein-steam
  53. /etc/profile
  54. /etc/profile.d/alias.sh
  55. /etc/profile.d/defaults.sh
  56. /etc/profile.d/golang.sh
  57. /etc/profile.d/gpkg.sh
  58. /etc/profile.d/racket.sh
  59. /etc/emacs/default.el
  60. /etc/i3/config
  61. /etc/Xresources
  62. /etc/i3status.conf
  63. /etc/tmux.conf
  64. /etc/vimrc
  65. /etc/xinitrc
  66. "
  67. # Files/Folders that need to be removed and re-created. Sometimes
  68. # 'package.use' is a file, sometimes it's a folder. We need it to
  69. # be a folder so we'll remove it outright and create what we need.
  70. # Sure, this is wasting a little time, I know.
  71. ConfigFolders="
  72. /etc/portage/package.use
  73. /etc/portage/sets
  74. /etc/profile.d
  75. /etc/emacs
  76. /etc/i3
  77. "
  78. for Folder in $ConfigFolders; do
  79. rm -rf $Folder
  80. mkdir -p $Folder
  81. done
  82. for File in $Configs; do
  83. wget -q "$Source/$File" -O "$File"
  84. done
  85. }
  86. ## System
  87. #
  88. # The 'Hostname' is used to set the 'Hostname'.
  89. #
  90. # Change 'Locale' to your language and encoding of choice as needed.
  91. #
  92. # A 2G 'SwapSize' seems to be plenty, even for compiling chromium or
  93. # firefox. Make this larger if needed.
  94. #
  95. # Change 'TimeZone' as needed. 'ls /usr/share/zoneinfo' for your region
  96. # and so on.
  97. #
  98. # By default, 'AutoKernel' is set to 'true' which means that the kernel
  99. # will be built using 'make defconfig'. If you want to run
  100. # 'make defconfig; make menuconfig' then set $AutoKernel to 'false'. You
  101. # may also supply your own URL to $KernelConfig while setting
  102. # 'AutoKernel' to 'false' to use a pre-built kernel config. An example
  103. # kernel config is provided though commented out.
  104. Hostname="gein"
  105. Locale="en_US.UTF-8 UTF-8"
  106. SwapSize="2G"
  107. TimeZone="America/New_York"
  108. AutoKernel="true"
  109. #KernelConfig="$Source/usr/src/linux/x.x.config"
  110. ## Portage
  111. #
  112. # Leave 'CPUCores' as-is. It will count the number of available cores
  113. # which will be used during this script and set in the 'make.conf'.
  114. # Changing this to 'Cores + 1', despite this being suggested in many
  115. # corners of the web, is not a good idea and will actually increase the
  116. # total time needed to compile.
  117. #
  118. case "$(uname -m)" in
  119. amd64|x86_64) CPUArch="amd64" ;;
  120. *)
  121. echo "gein: CPU arch has not been defined yet"
  122. exit
  123. esac
  124. CPUCores="$(grep -c ^processor /proc/cpuinfo)"
  125. ## Command Aliases
  126. #
  127. # This section defines some command aliases that will be used later on,
  128. # and is primarily used as a mechanism to inhibit or control output in a
  129. # way that can be easily updated or changed if needed.
  130. Emerge="emerge -v --quiet-build"
  131. Make="make -s -j$CPUCores"
  132. Wget="wget -q"
  133. ## Gentoo Stage3
  134. #
  135. # This section exists to automate identifying and downloading the latest
  136. # stage3 archive under the condition that cURL is present. This is not
  137. # an issue when using the Gentoo installation CD's though prevents
  138. # errors when executing MINIMAL() or DESKTOP() due to cURL missing
  139. # after completing the BOOTSTRAP().
  140. S3_Source="http://distfiles.gentoo.org/releases/$CPUArch/autobuilds"
  141. S3_Release="curl -s $S3_Source/latest-stage3-$CPUArch.txt"
  142. if [ -x "$(command -v curl)" ]; then
  143. S3_Current="$($S3_Release|tail -1|awk '{print $1}')"
  144. Stage3="$S3_Source/$S3_Current"
  145. fi
  146. # Bootstrapping a Gentoo stage3 archive is a fairly quick process though
  147. # we must also ensure this script will be accessible from the chroot as
  148. # well as other housekeeping tasks. The Portage configuration files are
  149. # setup in this section.
  150. BOOTSTRAP() {
  151. echo "Please ensure that you have performed the following: "
  152. echo " - Edited the environment variables at the top of this script."
  153. echo " - Partitioned and mounted your disk(s)."
  154. read -ep "Proceed with installation? [Y/N]: " Proceed
  155. if echo "$Proceed" | grep -iq "^y"; then
  156. echo "gein: Proceeding with installation..."
  157. else
  158. echo "gein: Exiting..."
  159. exit
  160. fi
  161. if [ -z "$VideoCards" ] || [ -z "$PartitionBoot" ]; then
  162. echo "gein: You didn't read $0 and adjust the variables!"
  163. echo "gein: Exiting..."
  164. exit
  165. fi
  166. echo "gein: Ensuring we are in /mnt/gentoo..."
  167. [ ! -e /mnt/gentoo/$(basename "$0") ] &&
  168. cp "$0" /mnt/gentoo/ &&
  169. cd /mnt/gentoo &&
  170. echo "gein: Setting system time via ntpd..."
  171. [ -x "$(command -v ntpd)" ] &&
  172. ntpd -q -g &&
  173. echo "gein: Downloading and extracting Stage3 tarball..."
  174. if [ -n "$Stage3" ]; then
  175. $Wget "$Stage3" &&
  176. tar -xpf stage3-* --xattrs --numeric-owner &&
  177. rm -rf stage3-*
  178. else
  179. echo "gein: 'Stage3' variable is not set! Is cURL missing?"
  180. echo "gein: Exiting..."
  181. exit
  182. fi
  183. echo "gein: Mounting hardware devices..."
  184. HW="proc sys dev"
  185. for target in $HW; do
  186. if [ -e /mnt/gentoo/"$target" ]; then
  187. case "$target" in
  188. proc) mount -t proc /proc /mnt/gentoo/proc ;;
  189. sys ) mount --rbind /sys /mnt/gentoo/sys &&
  190. mount --make-rslave /mnt/gentoo/sys ;;
  191. dev ) mount --rbind /dev /mnt/gentoo/dev &&
  192. mount --make-rslave /mnt/gentoo/dev ;;
  193. *) echo "gein: $target: Improper hardware device"
  194. exit
  195. esac
  196. else
  197. echo "gein: $target unable to be mounted! Exiting..."
  198. exit
  199. fi
  200. done
  201. SwapFile="/mnt/gentoo/swapfile"
  202. if [ ! -e "$SwapFile" ]; then
  203. echo "gein: Setting up swapfile..." &&
  204. fallocate -l "$SwapSize" "$SwapFile" &&
  205. chmod 0600 "$SwapFile" &&
  206. mkswap "$SwapFile" &&
  207. swapon "$SwapFile" &&
  208. echo "/swapfile none swap sw 0 0" >> /mnt/gentoo/etc/fstab
  209. fi
  210. echo "gein: Copying '/etc/resolv.conf'..." &&
  211. cp -L /etc/resolv.conf /mnt/gentoo/etc/
  212. echo "gein: Chroot'ing into /mnt/gentoo..." &&
  213. chroot /mnt/gentoo /usr/bin/env -i \
  214. HOME="/root" TERM="$TERM" PS1="[chroot \u@\h \W]$ " \
  215. PATH="/usr/local/sbin/:/usr/local/bin:/usr/sbin" \
  216. PATH="$PATH:/usr/bin:/sbin:/bin:/opt/bin" \
  217. MANPATH="/usr/man:/usr/share/man:/usr/local/man" \
  218. MANPATH="$MANPATH:/usr/local/share/man" \
  219. /bin/bash --login
  220. }
  221. # In this section we will update various configuration files, select the
  222. # desired profile, compile the kernel, and install some basic packages.
  223. MINIMAL() {
  224. echo "gein: Setting CPU cores and GPU type..." &&
  225. sed -i "s/Video_Cards/$VideoCards/g; s/Make_Opts/-j$CPUCores/g" \
  226. /etc/portage/make.conf
  227. echo "gein: Syncing Portage and selecting profile..." &&
  228. emerge -q --sync &&
  229. eselect profile list | grep -Evi "dev|exp"
  230. echo "gein: choose the latest stable release" &&
  231. TargetProfile="" &&
  232. while [ -z "$TargetProfile" ]; do
  233. read -ep "Which profile?: " TargetProfile
  234. done &&
  235. eselect profile set "$TargetProfile" &&
  236. $Emerge -uDN @world
  237. echo "gein: Setting timezone..." &&
  238. echo "$TimeZone" > /etc/timezone &&
  239. $Emerge --config sys-libs/timezone-data
  240. echo "gein: Setting locale..." &&
  241. echo "$Locale" > /etc/locale.gen &&
  242. locale-gen && locale -a &&
  243. LocaleMain=$(echo $Locale | awk -F '[-]' '{print $1}') &&
  244. LocaleSet=$(eselect locale list | grep -i $LocaleMain | \
  245. awk -F '[][]' '{print $2}') &&
  246. eselect locale set $LocaleSet &&
  247. env-update && source /etc/profile &&
  248. export PS1="[chroot \u@\h \W]$ "
  249. echo "gein: Emerging minimal packages..." &&
  250. $Emerge @gein-base
  251. if grep -Rqi 'intel' /proc/cpuinfo; then
  252. echo "gein: emerging intel-microcode" &&
  253. $Emerge intel-microcode
  254. fi
  255. echo "gein: Configuring Linux kernel..."
  256. cd /usr/src/linux
  257. if [ "$AutoKernel" = "true" ]; then
  258. if [ -z "$KernelConfig" ]; then
  259. make defconfig
  260. else
  261. $Wget "$KernelConfig" -O /usr/src/linux/.config
  262. fi
  263. elif [ "$AutoKernel" = "false" ]; then
  264. if [ -z "$KernelConfig" ]; then
  265. make defconfig &&
  266. make menuconfig
  267. else
  268. $Wget "$KernelConfig" -O /usr/src/linux/.config &&
  269. make menuconfig
  270. fi
  271. else
  272. echo "gein: Error: AutoKernel isn't true or false. Exiting..."
  273. fi
  274. echo "gein: Compiling Linux kernel and modules..." &&
  275. $Make && $Make modules &&
  276. $Make install && $Make modules install &&
  277. $Make distclean &&
  278. cd /
  279. echo "gein: Adding services to OpenRC..." &&
  280. rc-update add dhcpcd default &&
  281. rc-update add cronie default
  282. echo "gein: Setting hostname..." &&
  283. echo "hostname=$Hostname" > /etc/conf.d/hostname
  284. echo "gein: Installing Grub to $PartitionBoot..." &&
  285. grub-install "$PartitionBoot" &&
  286. grub-mkconfig -o /boot/grub/grub.cfg
  287. }
  288. # In this section we will install the chosen xorg-driver and packages
  289. # for i3wm as the desktop of choice. Some additional packages are added
  290. # as a convenience.
  291. DESKTOP() {
  292. echo "gein: Installing Xorg drivers..." &&
  293. $Emerge x11-base/xorg-drivers &&
  294. env-update && source /etc/profile &&
  295. export PS1="[chroot \u@\h \W]$ "
  296. echo "gein: Installing desktop packages..." &&
  297. $Emerge @gein-base "$DesktopChoice"
  298. read -ep "gein: Install laptop packages? [Y/N]: " SetupUser
  299. if echo "$SetupUser" | grep -iq "^y"; then
  300. $Emerge @gein-laptop
  301. rc-update add laptop_mode default
  302. fi
  303. }
  304. # This section is for completing tasks after the installation is
  305. # complete. The user will have a complete system already installed and
  306. # may skip these steps if desired.
  307. POSTINSTALL() {
  308. echo "gein: Setting root password..."
  309. passwd
  310. # echo "gein: Creating 'power' group"
  311. # groupadd power
  312. # poweroff reboot shutdown
  313. read -ep "gein: Setup a standard user? [Y/N]: " SetupUser
  314. if echo "$SetupUser" | grep -iq "^y"; then
  315. echo "gein: Creating user account" &&
  316. read -ep "Username: " Username &&
  317. useradd -m -G wheel,audio,video \
  318. -s /bin/bash "$Username" &&
  319. passwd $Username
  320. fi
  321. echo "gein: Installation complete."
  322. }
  323. # This is the CLI that controls what will be run. Keep in mind that the
  324. # BOOTSTRAP() needs to be run to completion before running the MINIMAL()
  325. # or DESKTOP() passes.
  326. shopt -s nocasematch
  327. case $1 in
  328. -b|bootstrap)
  329. BOOTSTRAP
  330. ;;
  331. -m|minimal)
  332. CONFIG
  333. MINIMAL
  334. POSTINSTALL
  335. ;;
  336. -d|desktop)
  337. case $2 in
  338. i3wm)
  339. DesktopChoice="@gein-i3wm"
  340. sed -i '2,$s/^# //g' /etc/portage/package.use/defaults
  341. CONFIG
  342. MINIMAL
  343. DESKTOP
  344. POSTINSTALL
  345. ;;
  346. lxqt)
  347. DesktopChoice="@gein-lxqt"
  348. sed -i '2,$s/^# //g' /etc/portage/package.use/defaults
  349. CONFIG
  350. MINIMAL
  351. DESKTOP
  352. echo "azryn: Set SDDM as the display manager" &&
  353. sed -i 's/DISPLAYMANAGER="xdm"/DISPLAYMANAGER="sddm"/g' \
  354. /etc/conf.d/xdm &&
  355. sed -i 's/startl|xqt/"ck-launch-session dbus-launch startlxqt"/g' \
  356. /usr/share/xsessions/lxqt.desktop &&
  357. rc-update add xdm default &&
  358. rc-update add dbus default
  359. POSTINSTALL
  360. ;;
  361. *)
  362. echo "gein: $2 not an available desktop"
  363. echo ""
  364. echo "Available desktops:"
  365. echo " i3wm A complete i3wm desktop"
  366. echo " lxqt A complete LXQT desktop"
  367. esac
  368. ;;
  369. *)
  370. echo "gein: Linux-based derivative of Gentoo"
  371. echo " -h, help Shows this output"
  372. echo " -b, bootstrap Bootstrap the stage3 tarball"
  373. echo ""
  374. echo "Post-bootstrap:"
  375. echo " -m, minimal Perform a basic Gentoo installation"
  376. echo " -d, desktop Install a gein desktop"
  377. echo " i3wm A complete i3wm desktop"
  378. echo " lxqt A complete LXQT desktop"
  379. esac
  380. shopt -u nocasematch