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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. #!/usr/bin/env sh
  2. #
  3. # While this script does assist with installing Gentoo, it is NOT a
  4. # replacement for reading and understanding the Gentoo Handbook for your
  5. # system. See https://gentoo.org/get-started/ for information on getting
  6. # started with Gentoo.
  7. #
  8. # This file uses inline documentation whenever possible to preserve
  9. # context, situational or otherwise. Please read the entire file before
  10. # continuing to ensure you are aware of how this script functions, as
  11. # undesired behaviors for your use-case may exist.
  12. #
  13. # This script does NOT automatically partition your disk(s). You MUST
  14. # partition and mount your disk(s) before running this script.
  15. #
  16. # This file uses a modified 0-clause MIT license. If you did not receive
  17. # a copy of the license, please visit https://gein.io/License.md for a
  18. # copy.
  19. #
  20. ###
  21. # This section describes variables that will define the resulting
  22. # system. '$Hostname', '$Locale', and '$TimeZone' are mostly obvious in
  23. # terms of their use, though '$VideoCards' is used as the value of
  24. # 'VIDEO_CARDS' within '/etc/portage/make.conf'.
  25. cpu_cores="$(grep -c ^processor /proc/cpuinfo)"
  26. hostname="gein"
  27. locale="en_US.UTF-8 UTF-8"
  28. timezone="America/New_York"
  29. video_cards="false"
  30. # This section contains aliases for commands which are used throughout
  31. # the script. By default commands have their output and prompts
  32. # suppressed, though should you want to review or debug this script you
  33. # may want to adjust these as desired.
  34. curl="curl -sSf"
  35. emerge="emerge -v --quiet-build"
  36. emerge_sync="emerge -q --sync"
  37. make="make -s -j$cpu_cores"
  38. mkdir="mkdir -p"
  39. rm="rm"
  40. wget="wget -q"
  41. # This section describes how the kernel will be built, and whether the
  42. # user will be prompted to configure their kernel. The two mentioned
  43. # variables may be used together to suit a variety of use-cases.
  44. #
  45. # kernel_autobuild
  46. #
  47. # When 'true', this implies that the user does not want to perform
  48. # any manual configuration of the kernel, regardless of whether a
  49. # configuration file was provided. '$ make menuconfig' will NOT be
  50. # run before compiling the kernel.
  51. #
  52. # When any value OTHER than 'true', this implies that the use DOES
  53. # want to perform manual configuration on the kernel, regardless
  54. # of whether a configuration file was provided. '$ make menuconfig'
  55. # will be run before compiling the kernel.
  56. #
  57. # kernel_config
  58. #
  59. # The URL location of a kernel configuration file. If this variable
  60. # is unset, no attempt to download a configuration file will be
  61. # made, instead using the kernel defconfig.
  62. kernel_autobuild="true"
  63. #kernel_config=""
  64. #
  65. #
  66. #partition_boot=""
  67. #partition_uefi=""
  68. #partition_swap=""
  69. #
  70. #
  71. case "$(uname -m)" in
  72. i486|i586)
  73. cpu_dir="x86"
  74. cpu_arch="i486";;
  75. i686|x86|x86_32)
  76. cpu_dir="x86"
  77. cpu_arch="i686";;
  78. amd64|x86_64)
  79. cpu_dir="amd64"
  80. cpu_arch="amd64";;
  81. *)
  82. echo "gein: error: your architecture has not been defined yet." \
  83. "Submit an issue with the output of 'uname -m'" | fold -s
  84. echo "gein: Exiting..." \
  85. | fold -s
  86. exit 1
  87. esac
  88. #
  89. #
  90. config_source="https://gein.io"
  91. CONFIG() {
  92. config_files="
  93. /etc/portage/make.conf
  94. /etc/portage/package.accept_keywords/development
  95. /etc/portage/package.accept_keywords/lxqt
  96. /etc/portage/package.accept_keywords/media
  97. /etc/portage/package.accept_keywords/system
  98. /etc/portage/package.env
  99. /etc/portage/package.license
  100. /etc/portage/package.use/global
  101. /etc/portage/package.use/local
  102. /etc/portage/package.use/multilib
  103. /etc/portage/sets/gein-base
  104. /etc/portage/sets/gein-i3wm
  105. /etc/portage/sets/gein-lxqt
  106. /etc/portage/sets/gein-laptop
  107. /usr/local/sbin/gpkg
  108. /usr/local/sbin/kbuild
  109. "
  110. config_dirs="
  111. /etc/portage/package.accept_keywords
  112. /etc/portage/package.use
  113. /etc/portage/sets
  114. "
  115. for dir in $config_dirs; do
  116. if [ ! -d "$dir" ]; then
  117. $rm "$dir"
  118. fi
  119. if [ ! -e "$dir" ]; then
  120. $mkdir "$dir"
  121. fi
  122. done
  123. unset config_dirs dir
  124. for file in $config_files; do
  125. $wget "$config_source/$file" -O "$file"
  126. done
  127. unset config_files file
  128. config_complete="true"
  129. }
  130. #
  131. #
  132. PREREQUISITES() {
  133. if [ -z "$partition_boot" ] || [ -z "$video_cards" ]; then
  134. echo "gein: error: required variables are unset!" | fold -s
  135. echo "gein: please ensure you have partitioned and mounted" \
  136. "your disks, as well as updated the variables associated" \
  137. "with the required partitions. You must also declare" \
  138. "your VideoCard. Please see gein.sh for instructions." \
  139. | fold -s
  140. echo "gein: Exiting..." | fold -s
  141. exit 1
  142. fi
  143. prerequisites_complete="true"
  144. }
  145. #
  146. #
  147. PARTITION() {
  148. if [ ! -e /mnt/gentoo ]; then
  149. echo "gein: error: '/mnt/gentoo' does not exist!" | fold -s
  150. echo "gein: '/mnt/gentoo' is referred to later in this script," \
  151. "and is required to continue. Please ensure your mounted" \
  152. "partitions are correct." | fold -s
  153. echo "gein: Exiting..." | fold -s
  154. exit 1
  155. fi
  156. partition_complete="true"
  157. }
  158. #
  159. #
  160. BOOTSTRAP() {
  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..." | fold -s
  167. if [ -x "$(command -v ntpd)" ]; then
  168. ntpd -q -g
  169. fi
  170. echo "gein: Downloading and extracting Stage3 tarball..."
  171. if [ -x "$(command -v curl)" ]; then
  172. stage3_source="http://distfiles.gentoo.org/releases/$cpu_dir/autobuilds"
  173. stage3_release="curl -s $stage3_source/latest-stage3-$cpu_arch.txt"
  174. stage3_current="$($stage3_release|tail -1|awk '{print $1}')"
  175. $wget "$stage3_source/$stage3_current"
  176. tar -xpf stage3-* --xattrs --numeric-owner
  177. rm -rf stage3-*
  178. unset stage3_source stage3_release stage3_current
  179. else
  180. echo "gein: error: curl not present!"
  181. echo "gein: Exiting..."
  182. exit 1
  183. fi
  184. echo "gein: Mounting hardware devices..."
  185. hardware_mountpoints="proc sys dev"
  186. for target in $hardware_mountpoints; do
  187. if [ -e /mnt/gentoo/"$target" ]; then
  188. case "$target" in
  189. proc) mount -t proc /proc /mnt/gentoo/proc ;;
  190. sys ) mount --rbind /sys /mnt/gentoo/sys
  191. mount --make-rslave /mnt/gentoo/sys ;;
  192. dev ) mount --rbind /dev /mnt/gentoo/dev
  193. mount --make-rslave /mnt/gentoo/dev ;;
  194. *) echo "gein: $target: Improper hardware device" \
  195. | fold -s
  196. exit
  197. esac
  198. else
  199. echo "gein: $target unable to be mounted! Exiting..." \
  200. | fold -s
  201. exit
  202. fi
  203. done
  204. unset hardware_mountpoints target
  205. if [ ! -e "$partition_swap" ]; then
  206. echo "gein: Setting up swapfile..." | fold -s
  207. mkswap "$partition_swap"
  208. swapon "$partition_swap"
  209. echo "/swapfile none swap sw 0 0" >> /mnt/gentoo/etc/fstab
  210. fi
  211. echo "gein: Copying '/etc/resolv.conf'..." | fold -s
  212. cp -L /etc/resolv.conf /mnt/gentoo/etc/
  213. echo "gein: Chroot'ing into /mnt/gentoo..." | fold -s
  214. chroot \
  215. /mnt/gentoo /usr/bin/env -i \
  216. HOME="/root" \
  217. TERM="$TERM" \
  218. PS1="[chroot \u@\h \W]$ " \
  219. PATH="/usr/local/sbin/:/usr/local/bin:/usr/sbin" \
  220. PATH="$PATH:/usr/bin:/sbin:/bin:/opt/bin" \
  221. MANPATH="/usr/man:/usr/share/man:/usr/local/man" \
  222. MANPATH="$MANPATH:/usr/local/share/man" \
  223. /bin/bash --login
  224. bootstrap_complete="true"
  225. }
  226. #
  227. #
  228. INSTALL() {
  229. CONFIG
  230. echo "gein: Setting CPU cores and GPU type..." | fold -s
  231. sed -i "s/Video_Cards/$VideoCards/g; s/Make_Opts/-j$CPUCores/g" \
  232. /etc/portage/make.conf
  233. echo "gein: Syncing Portage and selecting profile..." | fold -s
  234. $emerge_sync
  235. eselect profile list | grep -Evi "dev|exp"
  236. echo "gein: Choose the latest stable release" | fold -s
  237. profile_target=""
  238. while [ -z "$profile_target" ]; do
  239. read -p "Which profile?: " profile_target
  240. done
  241. eselect profile set "$profile_target"
  242. $emerge -uDN @world
  243. echo "gein: Setting timezone..." | fold -s
  244. echo "$timezone" > /etc/timezone
  245. $emerge --config sys-libs/timezone-data
  246. echo "gein: Setting locale..." | fold -s
  247. echo "$Locale" > /etc/locale.gen && locale-gen
  248. L="$(echo $Locale | awk -F '[-]' '{print $1}')"
  249. LL="$(eselect locale list|grep -i $L|awk -F '[][]' '{print $2}')"
  250. eselect locale set "$LL"
  251. env-update && source /etc/profile
  252. export PS1="[chroot \u@\h \W]$ "
  253. echo "gein: Emerging base system packages..." | fold -s
  254. $emerge @gein-base
  255. if grep -Rqi 'intel' /proc/cpuinfo; then
  256. echo "gein: Emerging intel-microcode"
  257. $emerge intel-microcode
  258. fi
  259. echo "gein: Configuring Linux kernel..."
  260. cd /usr/src/linux
  261. if [ "$kernel_autobuild" = "true" ]; then
  262. if [ -z "$kernel_config" ]; then
  263. make defconfig
  264. else
  265. $wget "$kernel_config" -O /usr/src/linux/.config
  266. fi
  267. elif [ "$kernel_autobuild" = "false" ]; then
  268. if [ -z "$kernel_config" ]; then
  269. make defconfig
  270. make menuconfig
  271. else
  272. $wget "$kernel_config" -O /usr/src/linux/.config
  273. make menuconfig
  274. fi
  275. else
  276. echo "gein: Error: AutoKernel isn't true or false. Exiting..."
  277. fi
  278. echo "gein: Compiling Linux kernel and modules..."
  279. $make && $make modules && \
  280. $make install && $make modules install && \
  281. $make distclean
  282. cd /
  283. echo "gein: Adding services to OpenRC..."
  284. rc-update add dhcpcd default
  285. rc-update add cronie default
  286. echo "gein: Setting hostname..."
  287. echo "hostname=$hostname" > /etc/conf.d/hostname
  288. echo "gein: Installing Grub to $partition_boot..."
  289. grub-install "$partition_boot"
  290. grub-mkconfig -o /boot/grub/grub.cfg
  291. install_complete="true"
  292. }
  293. #
  294. #
  295. POSTINSTALL() {
  296. echo "gein: Setting root password..."
  297. passwd
  298. # echo "gein: Creating 'power' group"
  299. # groupadd power
  300. # poweroff reboot shutdown
  301. read -p "gein: Setup a standard user? [Y/N]: " user_setup
  302. if echo "$user_setup" | grep -iq "^y"; then
  303. echo "gein: Creating user account"
  304. read -p "Username: " username
  305. useradd -m -G wheel,audio,video \
  306. -s /bin/bash "$username"
  307. passwd "$username"
  308. fi
  309. echo "gein: Installation complete."
  310. postinstall_complete="true"
  311. }
  312. #
  313. #
  314. case $1 in
  315. -p|--partition)
  316. PREREQUISITES
  317. PARTITION
  318. ;;
  319. -b|--bootstrap)
  320. PREREQUISITES
  321. BOOTSTRAP
  322. ;;
  323. -i|--install)
  324. PREREQUISITES
  325. INSTALL
  326. POSTINSTALL
  327. ;;
  328. *)
  329. echo "gein: Linux-based derivative of Gentoo"
  330. echo " -p, partition Partition and mount disk(s)"
  331. echo " -b. bootstrap Bootstrap the stage3 tarball"
  332. echo " -i, install Install Gentoo"
  333. esac