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.

install.sh 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. #!/usr/bin/env sh
  2. #
  3. # Copyright (C) 2017 Azryn Software Labs contact@azryn.org
  4. # This software is licensed under the Azryn Software Labs Public License
  5. # of version 1.1.0 or later. You should have received a copy of the Azryn
  6. # Software Labs Public License along with this program. If not, please
  7. # see https://apl.azryn.org/ for a copy.
  8. #
  9. ##################################################
  10. #
  11. # This script does automate the install but you will need to adjust the
  12. # variables in 'Setup' to suit your desired install. The installation
  13. # process will not proceed unless 'PartitionBoot' and 'VideoCards' are
  14. # set though some example values have been provided. If you are unsure
  15. # how to proceed, consult the Gentoo Handbook.
  16. #
  17. # === WARNINGS ===
  18. # - Your root password is set to the value of $Hostname for simplicity.
  19. # Change your root password with 'passwd' after the MINIMAL install.
  20. #
  21. # - Be sure to set $PartitionBoot to your boot target, though the
  22. # default value of '/dev/sda' will install to the master boot record.
  23. #
  24. # - By default, $AutoKernel is set to 'true' which means that the kernel
  25. # will be built using 'make defconfig'. If you want to run
  26. # 'make defconfig; make menuconfig' then set $AutoKernel to 'false'.
  27. # You may also supply your own URL to $KernelConfig while setting
  28. # $AutoKernel to 'false' to use a pre-built kernel config. And example
  29. # kernel config is provided though commented out.
  30. #
  31. ##################################################
  32. ### Setup ########################################
  33. ## Azryn
  34. CPUCores="$(grep -c ^processor /proc/cpuinfo)"
  35. Hostname="azryn"
  36. Locale="en_US.UTF-8 UTF-8"
  37. #PartitionBoot="/dev/sda"
  38. Source="https://raw.githubusercontent.com/Azryn/AzrynOS/master"
  39. SwapSize="2G"
  40. TimeZone="America/New_York"
  41. #VideoCards="amdgpu radeonsi"
  42. #VideoCards="i965 intel"
  43. #VideoCards="nouveau nvidia"
  44. #VideoCards="virtualbox vmware"
  45. ## Kernel
  46. AutoKernel="true"
  47. #KernelVersion="4.14"
  48. #KernelConfig="$Source/usr/src/linux/$KernelVersion.config"
  49. ## Portage
  50. MakeConf="$Source/etc/portage/make.conf"
  51. PackageAcceptKeywords="$Source/etc/portage/package.accept_keywords"
  52. PackageEnv="$Source/etc/portage/package.env"
  53. PackageLicense="$Source/etc/portage/package.license"
  54. PackageUse="$Source/etc/portage/package.use"
  55. ## Stage3
  56. S3Arch="amd64"
  57. S3Url="http://distfiles.gentoo.org/releases/$S3Arch/autobuilds"
  58. [ -x "$(command -v curl)" ] && \
  59. S3Tgt="$(curl -s $S3Url/latest-stage3-$S3Arch.txt|tail -1|awk '{print $1}')"
  60. ### Passes #######################################
  61. BOOTSTRAP() {
  62. echo "Please ensure that you have performed the following: "
  63. echo " - Edited the environment variables at the top of this script."
  64. echo " - Partitioned and mounted your disk(s)."
  65. read -ep "Proceed with installation? [Y/N]: " Proceed
  66. if echo $Proceed | grep -iq "^n"; then exit; fi
  67. if [ -z $VideoCards || -z $PartitionBoot ]; then
  68. echo "azryn: You didn't read $0 and adjust the variables! Exiting..."
  69. exit
  70. fi
  71. echo "azryn: Ensuring we are in /mnt/gentoo..."
  72. [ ! -e /mnt/gentoo/$(basename $0) ] && cp $0 /mnt/gentoo/
  73. cd /mnt/gentoo
  74. echo "azryn: Setting system time via ntpd..."
  75. ntpd -q -g
  76. echo "azryn: Downloading and extracting Stage3 tarball..."
  77. if [ -z $S3Tgt ]; then
  78. wget -q $S3Url/$S3Tgt
  79. tar -xjpf stage3-*.tar.bz2 --xattrs --numeric-owner
  80. else
  81. echo "azryn: 'S3Tgt' is not set! Is cURL missing? Exiting..."
  82. exit
  83. fi
  84. echo "azryn: Mounting hardware devices..."
  85. mount -t proc /proc /mnt/gentoo/proc
  86. mount --rbind /sys /mnt/gentoo/sys
  87. mount --make-rslave /mnt/gentoo/sys
  88. mount --rbind /dev /mnt/gentoo/dev
  89. mount --make-rslave /mnt/gentoo/dev
  90. echo "azryn: Setting up swapfile..."
  91. SwapFile="/mnt/gentoo/swapfile"
  92. if [ ! -e $SwapFile ]; then
  93. fallocate -l $SwapSize $SwapFile && chmod 0600 $SwapFile
  94. mkswap $SwapFile && swapon $SwapFile
  95. echo "/swapfile none swap sw 0 0" >> /mnt/gentoo/etc/fstab
  96. fi
  97. echo "azryn: Downloading portage configuration files..."
  98. [ ! -z $MakeConf ] && \
  99. wget -q $MakeConf \
  100. -O /mnt/gentoo/etc/portage/make.conf
  101. [ ! -z $PackageAcceptKeywords ] && \
  102. wget -q $PackageAcceptKeywords \
  103. -O /mnt/gentoo/etc/portage/package.accept_keywords
  104. [ ! -z $PackageEnv ] && \
  105. wget -q $PackageEnv \
  106. -O /mnt/gentoo/etc/portage/package.env
  107. [ ! -z $PackageLicense ] && \
  108. wget -q $PackageLicense \
  109. -O /mnt/gentoo/etc/portage/package.license
  110. [ ! -z $PackageUse ] && \
  111. rm -rf /mnt/gentoo/etc/portage/package.use && \
  112. wget -q $PackageUse \
  113. -O /mnt/gentoo/etc/portage/package.use
  114. echo "azryn: Setting up Portage mirrors..."
  115. mkdir -vp /mnt/gentoo/etc/portage/repos.conf
  116. wget -q $Source/etc/portage/repos.conf/gentoo.conf \
  117. -O /etc/portage/repos.conf/gentoo.conf
  118. cp -vL /etc/resolv.conf /mnt/gentoo/etc/
  119. echo "azryn: Chroot'ing into /mnt/gentoo..."
  120. chroot /mnt/gentoo /usr/bin/env -i \
  121. HOME="/root" TERM="$TERM" PS1="[chroot \u@\h \w]$" \
  122. PATH="/bin:/sbin:/usr/bin:/usr/sbin" \
  123. /bin/bash --login
  124. }
  125. MINIMAL() {
  126. echo "azryn: Setting CPU cores and GPU type..."
  127. sed -i "s/Video_Cards/$VideoCards/g; s/Make_Opts/-j$CPUCores/g" \
  128. /etc/portage/make.conf
  129. echo "azryn: Syncing Portage and selecting profile..."
  130. emerge -q --sync
  131. eselect profile list
  132. echo "azryn: Hint: choose the latest 'default/linux/amd64/xx.x'"
  133. read -ep "Which profile? : " TargetProfile
  134. [ -z $TargetProfile ] && TargetProfile="1"
  135. eselect profile set $TargetProfile
  136. emerge -quDN @world
  137. echo "azryn: Setting timezone..."
  138. echo $TimeZone > /etc/timezone
  139. emerge -q --config sys-libs/timezone-data
  140. echo "azryn: Setting locale..."
  141. echo $Locale > /etc/locale.gen
  142. locale-gen && locale -a && eselect locale list
  143. read -ep "Target locale: " TargetLocale
  144. eselect locale set $TargetLocale
  145. env-update && source /etc/profile && export PS1="[chroot \u@\h \w]$"
  146. echo "azryn: Emerge/install Linux kernel and modules..."
  147. emerge -q \
  148. sys-kernel/gentoo-sources \
  149. sys-kernel/linux-firmware \
  150. sys-apps/pciutils \
  151. sys-kernel/genkernel \
  152. net-misc/connman \
  153. sys-boot/grub:2
  154. if grep -Rqi 'intel' /proc/cpuinfo; then
  155. echo "azryn: emerging intel-microcode"
  156. emerge -q intel-microcode
  157. fi
  158. echo "azryn: Configuring Linux kernel..."
  159. cd /usr/src/linux
  160. if [ "$AutoKernel" = "true" && -z $KernelConfig ]; then
  161. make defconfig
  162. elif [ "$AutoKernel" = "false" ]; then
  163. if [ ! -z $KernelConfig ]; then
  164. wget -q $KernelConfig -O /usr/src/linux/.config
  165. else
  166. make defconfig
  167. fi
  168. make menuconfig
  169. fi
  170. echo "azryn: Compiling Linux kernel, modules, and initramfs..."
  171. make -j$CPUCores && make modules_install && make install
  172. genkernel --install initramfs
  173. cd /
  174. echo "azryn: Install netifrc..."
  175. emerge -qn net-misc/netifrc
  176. echo "azryn: Add connman to OpenRC..."
  177. rc-update add connman default
  178. echo "azryn: Setting hostname..."
  179. echo "hostname=$Hostname" > /etc/conf.d/hostname
  180. echo "azryn: Installing Grub to $PartitionBoot..."
  181. grub-install $PartitionBoot
  182. grub-mkconfig -o /boot/grub/grub.cfg
  183. echo "azryn: Adding bash configuration..."
  184. wget -q $Source/etc/bash/bashrc -O /etc/bash/bashrc
  185. echo "azryn: Adding profile configuration..."
  186. wget -q $Source/etc/profile -O /etc/profile
  187. wget -q $Source/etc/profile.d/alias.sh -O /etc/profile.d/alias.sh
  188. wget -q $Source/etc/profile.d/azryn.sh -O /etc/profile.d/azryn.sh
  189. wget -q $Source/etc/profile.d/environment.sh \
  190. -O /etc/profile.d/environment.sh
  191. echo "azryn: Adding sudo, vim, tmux, and htop..."
  192. emerge -q \
  193. app-admin/sudo \
  194. app-editors/vim \
  195. app-misc/tmux \
  196. dev-vcs/git \
  197. sys-process/htop
  198. echo "azryn: Adding userland configurations..."
  199. wget -q $Source/etc/sudoers -O /etc/sudoers
  200. wget -q $Source/etc/tmux.conf -O /etc/tmux.conf
  201. wget -q $Source/etc/vimrc -O /etc/vimrc
  202. echo "azryn: Setting root password..."
  203. echo "root:$Hostname" | chpasswd
  204. }
  205. DESKTOP() {
  206. echo "azryn: Installing Xorg drivers..."
  207. emerge -q x11-base/xorg-drivers
  208. env-update && source /etc/profile && export PS1="[chroot \u@\h \w]$"
  209. echo "azryn: Installing base desktop packages..."
  210. emerge -q \
  211. app-admin/eclean-kernel \
  212. app-editors/emacs \
  213. app-laptop/laptop-mode-tools \
  214. app-portage/gentoolkit \
  215. app-text/aspell \
  216. kde-frameworks/breeze-icons \
  217. kde-plasma/breeze-gtk \
  218. media-fonts/noto \
  219. media-libs/alsa-lib \
  220. media-sound/alsa-utils \
  221. media-video/mpv \
  222. net-misc/youtube-dl \
  223. sys-apps/mlocate \
  224. x11-apps/xbacklight \
  225. x11-apps/xrandr \
  226. x11-apps/xset \
  227. x11-misc/wmctrl \
  228. x11-misc/xclip \
  229. x11-misc/xdotool
  230. echo "azryn: Add laptop_mode to OpenRC..."
  231. rc-update add laptop_mode default
  232. echo "azryn: Adding userland configuration files..."
  233. wget -q $Source/etc/Xresources -O /etc/Xresources
  234. wget -q $Source/etc/emacs/default.el -O /etc/emacs/default.el
  235. wget -q $Source/etc/i3/config -O /etc/i3/config
  236. wget -q $Source/etc/xinitrc -O /etc/xinitrc
  237. }
  238. I3WM() {
  239. echo "azryn: Installing i3wm desktop..."
  240. emerge -q \
  241. lxde-base/lxappearance \
  242. x11-misc/dmenu \
  243. x11-misc/i3lock \
  244. x11-misc/i3status \
  245. x11-terms/gnome-terminal \
  246. x11-wm/i3
  247. }
  248. LXQT() {
  249. echo "azryn: Installing LXQT desktop..."
  250. emerge -q \
  251. kde-plasma/breeze \
  252. kde-plasma/breeze-grub \
  253. kde-plasma/kwin \
  254. kde-plasma/sddm-kcm \
  255. lxqt-base/lxqt-meta \
  256. x11-terms/qterminal
  257. echo "azryn: Set SDDM as the display manager"
  258. sed -i 's/DISPLAYMANAGER="xdm"/DISPLAYMANAGER="sddm"/g' \
  259. /etc/conf.d/xdm
  260. sed -i 's/startlxqt/"ck-launch-session dbus-launch startlxqt"/g' \
  261. /usr/share/xsessions/lxqt.desktop
  262. rc-update add xdm default
  263. rc-update add dbus default
  264. }
  265. CLEANUP() {
  266. echo "azryn: Updating @world and removing unused packages..."
  267. emerge -quDN @world
  268. emerge -q --depclean
  269. emerge -quD --changed-use @world
  270. eclean --deep distfiles
  271. echo "azryn: Removing stage3 tarball..."
  272. rm -rf /stage3*.tar.bz2
  273. }
  274. ### Execution ####################################
  275. shopt -s nocasematch
  276. case $1 in
  277. bootstrap)
  278. BOOTSTRAP
  279. ;;
  280. minimal)
  281. MINIMAL
  282. ;;
  283. i3wm)
  284. MINIMAL
  285. DESKTOP
  286. I3WM
  287. ;;
  288. lxqt)
  289. MINIMAL
  290. DESKTOP
  291. LXQT
  292. ;;
  293. cleanup)
  294. CLEANUP
  295. ;;
  296. *)
  297. echo "AzrynOS: Linux-based derivative of Gentoo"
  298. echo " help Shows help output"
  299. echo ""
  300. echo "Pre-install tasks:"
  301. echo " bootstrap Bootstrap the stage3 tarball"
  302. echo ""
  303. echo "Installation options:"
  304. echo " minimal Install minimal Gentoo"
  305. echo " i3wm Install Gentoo and i3wm desktop"
  306. echo " lxqt Install Gentoo and LXQT desktop"
  307. echo ""
  308. echo "Post-install tasks:"
  309. echo " cleanup Remove junk created during install"
  310. esac
  311. shopt -u nocasematch