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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. # This script does automate the install but you will need to adjust the
  12. # variables in the following section to suit your desired install. The
  13. # installation process will not proceed unless 'PartitionBoot' and
  14. # 'VideoCards' are set though some example values have been provided. If
  15. # you are unsure how to proceed, consult the Gentoo Handbook.
  16. #
  17. # This section defines the basic variables needed in order to complete
  18. # the installation. Your root password is set to the value of $Hostname
  19. # for simplicity. Change your root password with 'passwd' after the
  20. # installation completes. Be sure to set $PartitionBoot to your intended
  21. # Grub destination. The default value will install to the master boot
  22. # record (MBR) of '/dev/sda'. You will also need to uncomment the line
  23. # pertaining to your GPU and modify it as needed.
  24. CPUCores="$(grep -c ^processor /proc/cpuinfo)"
  25. Hostname="gein"
  26. Locale="en_US.UTF-8 UTF-8"
  27. #PartitionBoot="/dev/sda"
  28. SwapSize="2G"
  29. TimeZone="America/New_York"
  30. #VideoCards="i915 i965 intel"
  31. #VideoCards="amdgpu radeonsi"
  32. #VideoCards="nouveau nvidia"
  33. #VideoCards="virtualbox vmware"
  34. # This script relies on downloading configuration files from the main
  35. # repository. Here we will create the $Source variable to simplify
  36. # future sections.
  37. Source="https://raw.githubusercontent.com/jcmdln/gein/master"
  38. # By default, $AutoKernel is set to 'true' which means that the kernel
  39. # will be built using 'make defconfig'. If you want to run
  40. # 'make defconfig; make menuconfig' then set $AutoKernel to 'false'. You
  41. # may also supply your own URL to $KernelConfig while setting
  42. # $AutoKernel to 'false' to use a pre-built kernel config. An example
  43. # kernel config is provided though commented out.
  44. AutoKernel="true"
  45. #KernelConfig="$Source/usr/src/linux/x.x.config"
  46. # Much work has been done to simplify or in most cases fully automate
  47. # interacting with Portage though this section simply creates easily
  48. # referenced variables that may be called later in this script. At the
  49. # time of writing, the Gentoo stage3 no longer includes 'git' which
  50. # prevents using the GitHub mirror. Please leave this commented unless
  51. # you plan to emerge git ahead of time.
  52. MakeConf="$Source/etc/portage/make.conf"
  53. PackageAcceptKeywords="$Source/etc/portage/package.accept_keywords"
  54. PackageEnv="$Source/etc/portage/package.env"
  55. PackageLicense="$Source/etc/portage/package.license"
  56. PackageUse="$Source/etc/portage/package.use"
  57. #ReposConf="$Source/etc/portage/repos.conf/gentoo.conf"
  58. # This section exists to automate identifying and downloading the latest
  59. # stage3 archive under the condition that cURL is present. This is not
  60. # an issue when using the Gentoo installation CD's though prevents
  61. # errors when executing MINIMAL() or DESKTOP() due to cURL missing
  62. # after completing the BOOTSTRAP().
  63. S3_Arch="amd64"
  64. S3_Source="http://distfiles.gentoo.org/releases/$S3_Arch/autobuilds"
  65. S3_Release="curl -s $S3_Source/latest-stage3-$S3_Arch.txt"
  66. [ -x "$(command -v curl)" ] &&
  67. S3_Current="$($S3_Release|tail -1|awk '{print $1}')" &&
  68. Stage3="$S3_Source/$S3_Current"
  69. # Bootstrapping a Gentoo stage3 archive is a fairly quick process though
  70. # we must also ensure this script will be accessible from the chroot as
  71. # well as other housekeeping tasks. The Portage configuration files are
  72. # setup in this section.
  73. BOOTSTRAP() {
  74. echo "Please ensure that you have performed the following: "
  75. echo " - Edited the environment variables at the top of this script."
  76. echo " - Partitioned and mounted your disk(s)."
  77. read -ep "Proceed with installation? [Y/N]: " Proceed
  78. if echo "$Proceed" | grep -iq "^y"; then
  79. echo "gein: Proceeding with installation..."
  80. else
  81. echo "gein: Exiting as requested..."
  82. exit
  83. fi
  84. if [ -z "$VideoCards" ] || [ -z "$PartitionBoot" ]; then
  85. echo "gein: You didn't read $0 and adjust the variables! Exiting..."
  86. exit
  87. fi
  88. echo "gein: Ensuring we are in /mnt/gentoo..."
  89. [ ! -e /mnt/gentoo/$(basename "$0") ] &&
  90. cp "$0" /mnt/gentoo/ &&
  91. cd /mnt/gentoo
  92. echo "gein: Setting system time via ntpd..."
  93. [ -x "$(command -v ntpd)" ] && ntpd -q -g
  94. echo "gein: Downloading and extracting Stage3 tarball..."
  95. if [ ! -z "$Stage3" ]; then
  96. wget -q "$Stage3"
  97. tar -xpf stage3-* --xattrs --numeric-owner
  98. rm -rf stage3-*
  99. else
  100. echo "gein: 'S3Tgt' is not set! Is cURL missing? Exiting..."
  101. exit
  102. fi
  103. echo "gein: Mounting hardware devices..."
  104. HW="proc sys dev"
  105. for target in "$HW"; do
  106. if [ -e /mnt/gentoo/"$target" ]; then
  107. case "$target" in
  108. proc) mount -t proc /proc /mnt/gentoo/proc;;
  109. sys ) mount --rbind /sys /mnt/gentoo/sys &&
  110. mount --make-rslave /mnt/gentoo/sys;;
  111. dev ) mount --rbind /dev /mnt/gentoo/dev &&
  112. mount --make-rslave /mnt/gentoo/dev;;
  113. *) echo "gein: $target: Improper hardware device"
  114. exit
  115. esac
  116. else
  117. echo "gein: $target unable to be mounted! Exiting..."
  118. exit
  119. fi
  120. done
  121. echo "gein: Setting up swapfile..."
  122. SwapFile="/mnt/gentoo/swapfile"
  123. if [ ! -e "$SwapFile" ]; then
  124. fallocate -l "$SwapSize" "$SwapFile" && chmod 0600 "$SwapFile"
  125. mkswap "$SwapFile" && swapon "$SwapFile"
  126. echo "/swapfile none swap sw 0 0" >> /mnt/gentoo/etc/fstab
  127. fi
  128. echo "gein: Copying '/etc/resolv.conf'..."
  129. cp -L /etc/resolv.conf /mnt/gentoo/etc/
  130. echo "gein: Downloading Portage configuration files..."
  131. [ ! -z "$MakeConf" ] &&
  132. wget -q "$MakeConf" \
  133. -O /mnt/gentoo/etc/portage/make.conf
  134. [ ! -z "$PackageAcceptKeywords" ] &&
  135. wget -q "$PackageAcceptKeywords" \
  136. -O /mnt/gentoo/etc/portage/package.accept_keywords
  137. [ ! -z "$PackageEnv" ] &&
  138. wget -q "$PackageEnv" \
  139. -O /mnt/gentoo/etc/portage/package.env
  140. [ ! -z "$PackageLicense" ] &&
  141. wget -q "$PackageLicense" \
  142. -O /mnt/gentoo/etc/portage/package.license
  143. [ ! -z "$PackageUse" ] &&
  144. rm -rf /mnt/gentoo/etc/portage/package.use &&
  145. wget -q "$PackageUse" \
  146. -O /mnt/gentoo/etc/portage/package.use
  147. [ ! -z "$ReposConf" ] &&
  148. mkdir -p /mnt/gentoo/etc/portage/repos.conf &&
  149. wget -q "$ReposConf" \
  150. -O /mnt/gentoo/etc/portage/repos.conf/gentoo.conf
  151. echo "gein: Downloading gein Portage package sets..."
  152. mkdir -p /mnt/etc/portage/sets
  153. PortageSets="
  154. /etc/portage/sets/gein-base
  155. /etc/portage/sets/gein-i3wm
  156. /etc/portage/sets/gein-laptop
  157. /etc/portage/sets/gein-lxqt
  158. /etc/portage/sets/gein-steam
  159. "
  160. for Set in "$PortageSets"; do
  161. wget -q "$Source"/"$Set" -O /mnt/gentoo/"$Set"
  162. done
  163. echo "gein: Chroot'ing into /mnt/gentoo..."
  164. chroot /mnt/gentoo /usr/bin/env -i \
  165. HOME="/root" TERM="$TERM" PS1="[chroot \u@\h \W]$ " \
  166. PATH="/usr/local/sbin/:/usr/local/bin:/usr/sbin:/usr/bin" \
  167. PATH="$PATH:/sbin:/bin:/opt/bin" \
  168. MANPATH="/usr/man:/usr/share/man:/usr/local/man" \
  169. MANPATH="$MANPATH:/usr/local/share/man" \
  170. /bin/bash --login
  171. }
  172. # In this section we will update various configuration files, select the
  173. # desired profile, compile the kernel, and install some basic packages.
  174. MINIMAL() {
  175. echo "gein: Setting CPU cores and GPU type..."
  176. sed -i "s/Video_Cards/$VideoCards/g; s/Make_Opts/-j$CPUCores/g" \
  177. /etc/portage/make.conf
  178. echo "gein: Syncing Portage and selecting profile..."
  179. emerge -q --sync
  180. eselect profile list
  181. echo "gein: Hint: choose the latest 'default/linux/amd64/xx.x'"
  182. read -ep "Which profile?: " TargetProfile
  183. [ -z "$TargetProfile" ] && TargetProfile="1"
  184. eselect profile set "$TargetProfile"
  185. emerge -vuDN --quiet-build @world
  186. echo "gein: Setting timezone..."
  187. echo "$TimeZone" > /etc/timezone
  188. emerge -v --quiet-build --config sys-libs/timezone-data
  189. echo "gein: Setting locale..."
  190. echo "$Locale" > /etc/locale.gen
  191. locale-gen && locale -a && eselect locale list
  192. read -ep "Target locale: " TargetLocale
  193. eselect locale set "$TargetLocale"
  194. env-update && source /etc/profile && export PS1="[chroot \u@\h \W]$ "
  195. echo "gein: Emerging minimal packages..."
  196. emerge -v --quiet-build @gein-base
  197. if grep -Rqi 'intel' /proc/cpuinfo; then
  198. echo "gein: emerging intel-microcode"
  199. emerge -v --quiet-build intel-microcode
  200. fi
  201. echo "gein: Configuring Linux kernel..."
  202. cd /usr/src/linux
  203. if [ "$AutoKernel" = "true" ]; then
  204. if [ -z "$KernelConfig" ]; then
  205. make defconfig
  206. else
  207. wget -q "$KernelConfig" -O /usr/src/linux/.config
  208. fi
  209. elif [ "$AutoKernel" = "false" ]; then
  210. if [ -z "$KernelConfig" ]; then
  211. make defconfig
  212. make menuconfig
  213. else
  214. wget -q "$KernelConfig" -O /usr/src/linux/.config
  215. make menuconfig
  216. fi
  217. else
  218. echo "gein: Error: AutoKernel isn't true or false. Exiting..."
  219. fi
  220. echo "gein: Compiling Linux kernel, modules, and initramfs..."
  221. make -j"$CPUCores" && make modules_install && make install
  222. cd /
  223. echo "gein: Adding services to OpenRC..."
  224. rc-update add dhcpcd default
  225. rc-update add cronie default
  226. echo "gein: Setting hostname..."
  227. echo "hostname=$Hostname" > /etc/conf.d/hostname
  228. echo "gein: Installing Grub to $PartitionBoot..."
  229. grub-install "$PartitionBoot"
  230. grub-mkconfig -o /boot/grub/grub.cfg
  231. echo "gein: Adding userland configurations..."
  232. CfgFiles="
  233. /etc/bash/bashrc
  234. /etc/profile
  235. /etc/profile.d/alias.sh
  236. /etc/profile.d/defaults.sh
  237. /etc/profile.d/gein.sh
  238. /etc/profile.d/golang.sh
  239. /etc/profile.d/kernel.sh
  240. /etc/profile.d/racket.sh
  241. "
  242. for cfg in "$CfgFiles"; do
  243. wget -q "$Source"/"$cfg" -O "$cfg"
  244. done
  245. echo "gein: Setting root password..."
  246. [ -x $(command -v chpasswd) ] && \
  247. echo root:"$Hostname" | chpasswd
  248. }
  249. # In this section we will install the chosen xorg-driver and packages
  250. # for i3wm as the desktop of choice. Some additional packages are added
  251. # as a convenience.
  252. DESKTOP() {
  253. echo "gein: Installing Xorg drivers..."
  254. emerge -v --quiet-build x11-base/xorg-drivers
  255. env-update && source /etc/profile && export PS1="[chroot \u@\h \W]$ "
  256. echo "gein: Installing desktop packages..."
  257. emerge -v --quiet-build @gein-base "$DesktopChoice"
  258. if [ ! -z "$DesktopConfig" ]; then
  259. echo "gein: Adding configuration files..."
  260. for cfg in "$DesktopConfig"; do
  261. wget -q "$Source"/"$cfg" -O "$cfg"
  262. done
  263. fi
  264. }
  265. LAPTOP() {
  266. echo "gein: Installing laptop packages..."
  267. emerge -v --quiet-build @gein-laptop
  268. echo "azryn: Add laptop_mode to OpenRC..."
  269. rc-update add laptop_mode default
  270. }
  271. # This section is for completing tasks after the installation is
  272. # complete. The user will have a complete system already installed and
  273. # may skip these steps if desired.
  274. POSTINSTALL() {
  275. # echo "gein: Creating 'power' group"
  276. # groupadd power
  277. # poweroff reboot shutdown
  278. read -ep "gein: Install laptop packages? [Y/N]: " SetupUser
  279. if echo "$SetupUser" | grep -iq "^y"; then
  280. emerge -v --quiet-build @gein-laptop
  281. fi
  282. read -ep "gein: Setup a standard user? [Y/N]: " SetupUser
  283. if echo "$SetupUser" | grep -iq "^y"; then
  284. read -ep "Username: " Username
  285. read -ep "Password: " Password
  286. useradd -m -G wheel,audio,video,power -s /bin/bash "$Username"
  287. echo "$Username":"$Password" | chpasswd
  288. fi
  289. echo "gein: Installation complete."
  290. }
  291. # This is the CLI that controls what will be run. Keep in mind that the
  292. # BOOTSTRAP() needs to be run to completion before running the MINIMAL()
  293. # or DESKTOP() passes.
  294. shopt -s nocasematch
  295. case $1 in
  296. -b|bootstrap)
  297. BOOTSTRAP
  298. ;;
  299. -m|minimal)
  300. MINIMAL
  301. POSTINSTALL
  302. ;;
  303. -d|desktop)
  304. case $2 in
  305. i3wm)
  306. DesktopChoice="@gein-i3wm"
  307. DesktopConfig="
  308. /etc/i3status.conf
  309. /etc/xinitrc
  310. /etc/Xresources
  311. /etc/i3/config
  312. "
  313. MINIMAL && DESKTOP && POSTINSTALL
  314. ;;
  315. lxqt)
  316. DesktopChoice="@gein-lxqt"
  317. MINIMAL && DESKTOP
  318. echo "azryn: Set SDDM as the display manager"
  319. sed -i 's/DISPLAYMANAGER="xdm"/DISPLAYMANAGER="sddm"/g' \
  320. /etc/conf.d/xdm
  321. sed -i 's/startl|xqt/"ck-launch-session dbus-launch startlxqt"/g' \
  322. /usr/share/xsessions/lxqt.desktop
  323. rc-update add xdm default
  324. rc-update add dbus default
  325. POSTINSTALL
  326. ;;
  327. *)
  328. echo "gein: $2 not an available desktop"
  329. echo ""
  330. echo "Available desktops:"
  331. echo " i3wm A complete i3wm desktop"
  332. echo " lxqt A complete LXQT desktop"
  333. esac
  334. ;;
  335. *)
  336. echo "gein: Linux-based derivative of Gentoo"
  337. echo " -h, help Shows this output"
  338. echo " -b, bootstrap Bootstrap the stage3 tarball"
  339. echo ""
  340. echo "Post-bootstrap:"
  341. echo " -m, minimal Perform a basic Gentoo installation"
  342. echo " -d, desktop Install a gein desktop"
  343. echo " i3wm A complete i3wm desktop"
  344. echo " lxqt A complete LXQT desktop"
  345. esac
  346. shopt -u nocasematch