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 13KB

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