Gentoo installation script
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

gein.sh 9.5KB

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