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

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