Gentoo installation script
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

gein.sh 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. #!/usr/bin/env sh
  2. #
  3. #
  4. #
  5. ##
  6. # $Source is the protocol and domain that will be the top-level reference
  7. # when retrieving configuration files.
  8. Source="https://gein.io"
  9. # This section defines some command aliases that will be used later on,
  10. # and is primarily used as a mechanism to inhibit or control output in a
  11. # way that can be easily updated or changed if needed.
  12. Emerge="emerge -v --quiet-build"
  13. EmergeSync="emerge -q --sync"
  14. Make="make -s -j$CPUCores"
  15. Mkdir="mkdir -p"
  16. Rm="rm"
  17. Wget="wget -q"
  18. # The following variables will be called later on to perform the
  19. # following:
  20. #
  21. # * $Hostname is used to set the hostname.
  22. # * $Locale is your language and encoding of choice
  23. # * $TimeZone is the target within '/usr/share/zoneinfo' of your region
  24. Hostname="gein"
  25. Locale="en_US.UTF-8 UTF-8"
  26. TimeZone="America/New_York"
  27. # The 'PartitionBoot' variable *MUST* be set to proceed with the
  28. # installation. The example uses '/dev/sda' which will later install
  29. # GRUB to the MBR rather than a partition. Change this to your desired
  30. # '/boot' partition.
  31. #PartitionBoot="/dev/sda1"
  32. #PartitionUefi="/dev/sda2"
  33. #PartitionRoot="/dev/sda3"
  34. #PartitionHome="/dev/sda4"
  35. #PartitionSwap="/dev/sda5"
  36. # The 'VideoCards' variable *MUST* be set to proceed with the
  37. # installation. Several examples have been provided based on brand or
  38. # target, though if you have any specific needs then set this variable
  39. # accordingly. If you don't need any video support, then set
  40. # 'VideoCards' to false like the last example.
  41. #VideoCards="i915 i965 intel"
  42. #VideoCards="amdgpu radeonsi"
  43. #VideoCards="nouveau nvidia"
  44. #VideoCards="virtualbox vmware"
  45. #VideoCards="false"
  46. ## Portage
  47. #
  48. # Leave 'CPUCores' as-is. It will count the number of available cores
  49. # which will be used during this script and set in the 'make.conf'.
  50. # Changing this to 'Cores + 1', despite this being suggested in many
  51. # corners of the web, is not a good idea and will actually increase the
  52. # total time needed to compile.
  53. case "$(uname -m)" in
  54. i486|i586)
  55. CPUDir="x86"
  56. CPUArch="i486";;
  57. i686|x86|x86_32)
  58. CPUDir="x86"
  59. CPUArch="i686";;
  60. amd64|x86_64)
  61. CPUDir="amd64"
  62. CPUArch="amd64";;
  63. *)
  64. echo "gein: error: your architecture has not been defined yet" \
  65. | fold -s
  66. echo "gein: Submit an issue with the output of 'uname -m'" \
  67. | fold -s
  68. exit 1
  69. esac
  70. CPUCores="$(grep -c ^processor /proc/cpuinfo)"
  71. ## Gentoo Stage3
  72. #
  73. # This section exists to automate identifying and downloading the latest
  74. # stage3 archive under the condition that cURL is present. This is not
  75. # an issue when using the Gentoo installation CD's though prevents
  76. # errors when executing MINIMAL() or DESKTOP() due to cURL missing
  77. # after completing the BOOTSTRAP().
  78. S3_Source="http://distfiles.gentoo.org/releases/$CPUDir/autobuilds"
  79. if [ -x "$(command -v curl)" ]; then
  80. S3_Release="curl -s $S3_Source/latest-stage3-$CPUArch.txt"
  81. S3_Current="$($S3_Release|tail -1|awk '{print $1}')"
  82. Stage3="$S3_Source/$S3_Current"
  83. else
  84. echo "gein: error: curl not present!"
  85. echo "gein: Exiting..."
  86. exit 1
  87. fi
  88. # By default, 'AutoKernel' is set to 'true' which means that the kernel
  89. # will be built using 'make defconfig'. If you want to run
  90. # 'make defconfig; make menuconfig' then set $AutoKernel to 'false'. You
  91. # may also supply your own URL to $KernelConfig while setting
  92. # 'AutoKernel' to 'false' to use a pre-built kernel config. An example
  93. # kernel config is provided though commented out as it may quickly become
  94. # irrelevant or dangerous to use.
  95. AutoKernel="true"
  96. #KernelConfig=""
  97. # `gein` relies on downloading configuration files from the main
  98. # repository. Here we will create the 'Source' variable which points to
  99. # the main repository, and 'Config' is the list of all configuration
  100. # files that will be installed.
  101. ConfigSource="$Source"
  102. CONFIG() {
  103. # This is a list of all config files that need to be downloaded and
  104. # moved into place.
  105. Configs="
  106. /etc/portage/make.conf
  107. /etc/portage/package.accept_keywords/development
  108. /etc/portage/package.accept_keywords/lxqt
  109. /etc/portage/package.accept_keywords/media
  110. /etc/portage/package.accept_keywords/system
  111. /etc/portage/package.env
  112. /etc/portage/package.license
  113. /etc/portage/package.use/global
  114. /etc/portage/package.use/local
  115. /etc/portage/package.use/multilib
  116. /etc/portage/sets/gein-base
  117. /etc/portage/sets/gein-i3wm
  118. /etc/portage/sets/gein-lxqt
  119. /etc/portage/sets/gein-laptop
  120. /usr/local/sbin/gpkg
  121. /usr/local/sbin/kbuild
  122. "
  123. # Files/Folders that need to be removed and re-created. Sometimes
  124. # 'package.use' is a file, sometimes it's a folder. We need it to
  125. # be a folder so we'll remove it outright and create what we need.
  126. # Sure, this is wasting a little time, I know.
  127. ConfigFolders="
  128. /etc/portage/package.accept_keywords
  129. /etc/portage/package.use
  130. /etc/portage/sets
  131. "
  132. for Folder in $ConfigFolders; do
  133. if [ ! -d "$Folder" ]; then
  134. $Rm "$Folder"
  135. fi
  136. if [ ! -e "$Folder" ]; then
  137. $Mkdir "$Folder"
  138. fi
  139. done
  140. for File in $Configs; do
  141. $Wget "$Source/$File" -O "$File"
  142. done
  143. }
  144. #
  145. #
  146. PREREQUISITES() {
  147. if [ -z "$PartitionBoot" ] || [ -z "$VideoCards" ]; then
  148. echo "gein: error: required variables are unset!" | fold -s
  149. echo "gein: please ensure you have partitioned and mounted" \
  150. "your disks, as well as updated the variables associated" \
  151. "with the required partitions. You must also declare" \
  152. "your VideoCard. Please see gein.sh for instructions." \
  153. | fold -s
  154. echo "gein: Exiting..." | fold -s
  155. exit 1
  156. fi
  157. }
  158. #
  159. #
  160. PARTITION() {
  161. if [ ! -e /mnt/gentoo ]; then
  162. echo "gein: error: '/mnt/gentoo' does not exist!" | fold -s
  163. echo "gein: '/mnt/gentoo' is referred to later in this script," \
  164. "and is required to continue. Please ensure your mounted" \
  165. "partitions are correct." | fold -s
  166. echo "gein: Exiting..." | fold -s
  167. exit 1
  168. fi
  169. }
  170. # Bootstrapping a Gentoo stage3 archive is a fairly quick process though
  171. # we must also ensure this script will be accessible from the chroot as
  172. # well as other housekeeping tasks. The Portage configuration files are
  173. # setup in this section.
  174. BOOTSTRAP() {
  175. echo "gein: Ensuring we are in /mnt/gentoo..."
  176. if [ ! -e /mnt/gentoo/$(basename "$0") ]; then
  177. cp "$0" /mnt/gentoo/
  178. cd /mnt/gentoo
  179. fi
  180. echo "gein: Setting system time via ntpd..." | fold -s
  181. if [ -x "$(command -v ntpd)" ]; then
  182. ntpd -q -g
  183. fi
  184. echo "gein: Downloading and extracting Stage3 tarball..."
  185. if [ -n "$Stage3" ]; then
  186. $Wget "$Stage3"
  187. tar -xpf stage3-* --xattrs --numeric-owner
  188. rm -rf stage3-*
  189. else
  190. echo "gein: 'Stage3' variable is not set! Is cURL missing?" | fold -s
  191. echo "gein: Exiting..." | fold -s
  192. exit
  193. fi
  194. echo "gein: Mounting hardware devices..."
  195. HW="proc sys dev"
  196. for target in $HW; do
  197. if [ -e /mnt/gentoo/"$target" ]; then
  198. case "$target" in
  199. proc) mount -t proc /proc /mnt/gentoo/proc ;;
  200. sys ) mount --rbind /sys /mnt/gentoo/sys
  201. mount --make-rslave /mnt/gentoo/sys ;;
  202. dev ) mount --rbind /dev /mnt/gentoo/dev
  203. mount --make-rslave /mnt/gentoo/dev ;;
  204. *) echo "gein: $target: Improper hardware device" \
  205. | fold -s
  206. exit
  207. esac
  208. else
  209. echo "gein: $target unable to be mounted! Exiting..." \
  210. | fold -s
  211. exit
  212. fi
  213. done
  214. if [ ! -e "$SwapFile" ]; then
  215. echo "gein: Setting up swapfile..." | fold -s
  216. mkswap "$PartitionSwap"
  217. swapon "$PartitionSwap"
  218. echo "/swapfile none swap sw 0 0" >> /mnt/gentoo/etc/fstab
  219. fi
  220. echo "gein: Copying '/etc/resolv.conf'..." | fold -s
  221. cp -L /etc/resolv.conf /mnt/gentoo/etc/
  222. echo "gein: Chroot'ing into /mnt/gentoo..." | fold -s
  223. chroot /mnt/gentoo /usr/bin/env -i \
  224. HOME="/root" TERM="$TERM" PS1="[chroot \u@\h \W]$ " \
  225. PATH="/usr/local/sbin/:/usr/local/bin:/usr/sbin" \
  226. PATH="$PATH:/usr/bin:/sbin:/bin:/opt/bin" \
  227. MANPATH="/usr/man:/usr/share/man:/usr/local/man" \
  228. MANPATH="$MANPATH:/usr/local/share/man" \
  229. /bin/bash --login
  230. }
  231. # In this section we will update various configuration files, select the
  232. # desired profile, compile the kernel, and install some basic packages.
  233. MINIMAL() {
  234. CONFIG
  235. echo "gein: Setting CPU cores and GPU type..." | fold -s
  236. sed -i "s/Video_Cards/$VideoCards/g; s/Make_Opts/-j$CPUCores/g" \
  237. /etc/portage/make.conf
  238. echo "gein: Syncing Portage and selecting profile..." | fold -s
  239. $EmergeSync
  240. eselect profile list | grep -Evi "dev|exp"
  241. echo "gein: Choose the latest stable release" | fold -s
  242. TargetProfile=""
  243. while [ -z "$TargetProfile" ]; do
  244. read -p "Which profile?: " TargetProfile
  245. done
  246. eselect profile set "$TargetProfile"
  247. $Emerge -uDN @world
  248. echo "gein: Setting timezone..." | fold -s
  249. echo "$TimeZone" > /etc/timezone
  250. $Emerge --config sys-libs/timezone-data
  251. echo "gein: Setting locale..." | fold -s
  252. echo "$Locale" > /etc/locale.gen
  253. locale-gen
  254. L="$(echo $Locale | awk -F '[-]' '{print $1}')"
  255. LSet="$(eselect locale list|grep -i $L|awk -F '[][]' '{print $2}')"
  256. eselect locale set "$LSet"
  257. env-update && source /etc/profile
  258. export PS1="[chroot \u@\h \W]$ "
  259. echo "gein: Emerging base system packages..." | fold -s
  260. $Emerge @gein-base
  261. if grep -Rqi 'intel' /proc/cpuinfo; then
  262. echo "gein: Emerging intel-microcode"
  263. $Emerge intel-microcode
  264. fi
  265. echo "gein: Configuring Linux kernel..."
  266. cd /usr/src/linux
  267. if [ "$AutoKernel" = "true" ]; then
  268. if [ -z "$KernelConfig" ]; then
  269. make defconfig
  270. else
  271. $Wget "$KernelConfig" -O /usr/src/linux/.config
  272. fi
  273. elif [ "$AutoKernel" = "false" ]; then
  274. if [ -z "$KernelConfig" ]; then
  275. make defconfig
  276. make menuconfig
  277. else
  278. $Wget "$KernelConfig" -O /usr/src/linux/.config
  279. make menuconfig
  280. fi
  281. else
  282. echo "gein: Error: AutoKernel isn't true or false. Exiting..."
  283. fi
  284. echo "gein: Compiling Linux kernel and modules..."
  285. $Make && $Make modules && $Make install && $Make modules install
  286. $Make distclean
  287. cd /
  288. echo "gein: Adding services to OpenRC..."
  289. rc-update add dhcpcd default
  290. rc-update add cronie default
  291. echo "gein: Setting hostname..."
  292. echo "hostname=$Hostname" > /etc/conf.d/hostname
  293. echo "gein: Installing Grub to $PartitionBoot..."
  294. grub-install "$PartitionBoot"
  295. grub-mkconfig -o /boot/grub/grub.cfg
  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. -p|--partition)
  321. PREREQUISITES
  322. PARTITION
  323. ;;
  324. -b|--bootstrap)
  325. PREREQUISITES
  326. BOOTSTRAP
  327. ;;
  328. -i|--install)
  329. PREREQUISITES
  330. MINIMAL
  331. POSTINSTALL
  332. ;;
  333. *)
  334. echo "gein: Linux-based derivative of Gentoo"
  335. echo " -p, partition Partition and mount disk(s)"
  336. echo " -b. bootstrap Bootstrap the stage3 tarball"
  337. echo " -i, install Install Gentoo"
  338. esac