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

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