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

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