Yeet's Automatic Arch Setup Scripts. Or YAASS for short.
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.

289 lines
7.2 KiB

4 years ago
4 years ago
  1. #!/bin/bash
  2. export NC='\033[0m'
  3. export RED='\033[0;31m'
  4. export GREEN='\033[0;32m'
  5. export ORANGE='\033[0;33m'
  6. export BLUE='\033[0;34m'
  7. export PURPLE='\033[0;35m'
  8. export CYAN='\033[0;36m'
  9. export LIGHTGRAY='\033[0;37m'
  10. export DARKGRAY='\033[1;30m'
  11. export LIGHTRED='\033[1;31m'
  12. export LIGHTGREEN='\033[1;32m'
  13. export YELLOW='\033[1;33m'
  14. export LIGHTBLUE='\033[1;34m'
  15. export LIGHTPURPLE='\033[1;35m'
  16. export LIGHTCYAN='\033[1;36m'
  17. export WHITE='\033[1;37m'
  18. verbose=0
  19. info(){
  20. printf "[\e[32mINFO\e[0m]:%s\n" "$1"
  21. }
  22. debug(){
  23. if [ $verbose ]; then
  24. printf "[\e[33mDEBUG\e[0m]:%s\n" "$1"
  25. fi
  26. }
  27. error(){
  28. printf "[\e[31mERROR\e[0m]:%s\n" "$1"
  29. }
  30. prompt(){
  31. 1>&2 printf "[\e[35mPROMPT\e[0m]: %s" "$1"
  32. read -r ans
  33. printf "%s" "$ans"
  34. printf "\n"
  35. }
  36. banner(){
  37. echo "${CYAN}
  38. dP dP .d888888 .d888888 .d88888b .d88888b
  39. Y8. .8P d8' 88 d8' 88 88. \"' 88. \"'
  40. Y8aa8P 88aaaaa88a 88aaaaa88a \`Y88888b. \`Y88888b.
  41. 88 88 88 88 88 \`8b \`8b
  42. 88 88 88 88 88 d8' .8P d8' .8P
  43. dP 88 88 88 88 Y88888P Y88888P
  44. ${NC}"
  45. echo " ${PURPLE}Yeet's Automated Arch Setup Script${NC}"
  46. }
  47. clear
  48. encryption=$1
  49. root=$3
  50. swap=$4
  51. home=$5
  52. zone=$(prompt "Please enter timezone: ")
  53. while [ ! -f "/usr/share/zoneinfo/$zone" ]; do
  54. zone=$(prompt "Please enter timezone: ")
  55. done
  56. ln -sf "/usr/share/zoneinfo/$zone" /etc/localtime
  57. hwclock --systohc
  58. echo -e "en_US.UTF-8 UTF-8\ntr_TR.UTF-8 UTF-8" > /etc/locale.gen
  59. locale-gen
  60. echo "LANG=en_US.UTF-8" > /etc/locale.conf
  61. if [ ! -f "/tmp/.blackarch" ]; then
  62. curl https://blackarch.org/strap.sh > /tmp/strap.sh
  63. chmod +x /tmp/strap.sh
  64. /tmp/strap.sh
  65. printf "\n[multilib]\nInclude = /etc/pacman.d/mirrorlist-arch" >> /etc/pacman.conf
  66. printf "\n[lib32]\nInclude = /etc/pacman.d/mirrorlist\n\n[options]\nILoveCandy\nTotalDownload\nColor" >> /etc/pacman.conf
  67. flexo=$(prompt "Are you going to use a flexo server?(y/N): ")
  68. if [ "$flexo" = "y" ]; then
  69. flexo_ip=$(prompt "Please enter ip address of flexo server: ")
  70. echo -e "\nServer = http://$flexo_ip:7878/\$repo/os/\$arch\n" >> /etc/pacman.d/mirrorlist
  71. fi
  72. pacman -Syy
  73. errors=$(prompt "Did any errors occur?(y/N): ")
  74. if [ "$errors" = "y" ]; then
  75. echo "Dropping you into a shell so that you can fix them, once you quit the shell, the installation will continue from where you left off."
  76. bash
  77. fi
  78. touch /tmp/.blackarch
  79. fi
  80. clear
  81. hostname=$(prompt "Please enter hostname: ")
  82. echo "$hostname" > /etc/hostname
  83. info "Set password for root: "
  84. passwd root
  85. username=$(prompt "Please enter name for regular user: ")
  86. useradd -m "$username"
  87. info "Set password for user $username: "
  88. passwd "$username"
  89. usermod -aG wheel "$username"
  90. echo -e "127.0.0.1 localhost\n::1 localhost\n127.0.0.1 $hostname.localdomain $hostname" > /etc/hosts
  91. if [ "$encryption" = "1" ]; then
  92. cat << EOF > /etc/initcpio/hooks/openswap
  93. run_hook ()
  94. {
  95. x=0;
  96. while [ ! -b /dev/mapper/root ] && [ \$x -le 10 ]; do
  97. x=\$(( x+1 ))
  98. sleep .2
  99. done
  100. mkdir crypto_key_device
  101. mount /dev/mapper/root crypto_key_device
  102. cryptsetup open --key-file crypto_key_device/root/.keys/swap-keyfile $swap swap
  103. umount crypto_key_device
  104. }
  105. EOF
  106. cat << EOF > /etc/initcpio/install/openswap
  107. build ()
  108. {
  109. add_runscript
  110. }
  111. help ()
  112. {
  113. cat<<HELPEOF
  114. This opens the swap encrypted partition $swap in /dev/mapper/swap
  115. HELPEOF
  116. }
  117. EOF
  118. if [ ! "$home" = "" ]; then
  119. cat << EOF > /etc/initcpio/hooks/openhome
  120. run_hook ()
  121. {
  122. x=0;
  123. while [ ! -b /dev/mapper/root ] && [ \$x -le 10 ]; do
  124. x=\$((x+1))
  125. sleep .2
  126. done
  127. mkdir crypto_key_device
  128. mount /dev/mapper/root crypto_key_device
  129. cryptsetup open --key-file crypto_key_device/root/.keys/home-keyfile $home home
  130. umount crypto_key_device
  131. }
  132. EOF
  133. cat << EOF > /etc/initcpio/install/openhome
  134. build ()
  135. {
  136. add_runscript
  137. }
  138. help ()
  139. {
  140. cat<<HELPEOF
  141. This opens the swap encrypted partition $home in /dev/mapper/home
  142. HELPEOF
  143. }
  144. EOF
  145. cat << EOF > /etc/mkinitcpio.conf
  146. MODULES=(vfat i915)
  147. BINARIES=()
  148. FILES=()
  149. HOOKS=(base udev plymouth autodetect keyboard keymap consolefont modconf block plymouth-encrypt openswap openhome resume filesystems fsck)
  150. EOF
  151. else
  152. cat << EOF > /etc/mkinitcpio.conf
  153. MODULES=(vfat i915)
  154. BINARIES=()
  155. FILES=()
  156. HOOKS=(base udev plymouth autodetect keyboard keymap consolefont modconf block plymouth-encrypt openswap resume filesystems fsck)
  157. EOF
  158. fi
  159. else
  160. cat << EOF > /etc/mkinitcpio.conf
  161. MODULES=(vfat i915)
  162. BINARIES=()
  163. FILES=()
  164. HOOKS=(base udev plymouth autodetect keyboard keymap consolefont modconf block plymouth resume filesystems fsck)
  165. EOF
  166. fi
  167. pacman -Syu --noconfirm "$(xargs < /install/pkg.list)"
  168. refind-install
  169. clear
  170. if [ "$encryption" = "1" ]; then
  171. line=1
  172. blkid | while IFS= read -r i; do
  173. echo "$line: $i"
  174. ((line=line+1))
  175. done
  176. keydev=$(prompt "Please select the device you will save the LUKS key to: ")
  177. # TODO automatically copy key files and format device
  178. uuid=$(blkid | sed -n 's/.*UUID=\"\([^\"]*\)\".*/\1/p' | sed -n "$keydev"p)
  179. cat << EOF > /boot/refind_linux.conf
  180. "Boot with encryption" "root=/dev/mapper/root resume=/dev/mapper/swap cryptdevice=UUID=$(blkid -s UUID -o value "$root"):root:allow-discards cryptkey=UUID=$uuid:vfat:key.yeet rw loglevel=3 quiet splash"
  181. EOF
  182. clear
  183. else
  184. cat << EOF > /boot/refind_linux.conf
  185. "Boot without encryption" "root=UUID=$(blkid -s UUID -o value "$root") resume=UUID=$(blkid -s UUID -o value "$swap") rw loglevel=3 quiet splash"
  186. EOF
  187. fi
  188. mkdir -p /etc/sudoers.d
  189. echo "%wheel ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/nopwd
  190. info "Installing yay"
  191. sudo -u "$username" bash -c "git clone https://aur.archlinux.org/yay.git /tmp/yay"
  192. sudo -u "$username" bash -c "(cd /tmp/yay; makepkg --noconfirm -si)"
  193. sudo -u "$username" bash -c "yay --noconfirm -S plymouth"
  194. sudo -u "$username" bash -c "yay --noconfirm -S plymouth-openrc-plugin"
  195. clear
  196. dotfiles=$(prompt "Would you like to automatically install my dotfiles?(y/N): ")
  197. if [ "$dotfiles" = "y" ]; then
  198. pacman -R --noconfirm vim
  199. sudo -u "$username" bash -c "git clone --recurse-submodules https://github.com/theFr1nge/dotfiles.git ~/.dotfiles"
  200. sudo -u "$username" bash -c "(cd ~/.dotfiles; ./install.sh)"
  201. clear
  202. fi
  203. info "Installing Plymouth theme"
  204. git clone https://github.com/adi1090x/plymouth-themes.git /tmp/pthemes
  205. cat << EOF > /etc/plymouth/plymouthd.conf
  206. [Daemon]
  207. Theme=sphere
  208. ShowDelay=0
  209. DeviceTimeout=8
  210. EOF
  211. cp -r /tmp/pthemes/pack_4/sphere /usr/share/plymouth/themes
  212. clear
  213. echo -e "/boot/EFI/refind\n2\n2" | sudo bash -c "$(curl -fsSL https://raw.githubusercontent.com/bobafetthotmail/refind-theme-regular/master/install.sh)"
  214. sudo rc-update add cronie
  215. sudo rc-update add acpi
  216. sudo rc-update add dbus
  217. sudo rc-update add connmand
  218. sudo rc-update add syslog-ng
  219. clear
  220. info "Running mkinitcpio"
  221. mkinitcpio -P
  222. if [ "$encryption" = "$1" ]; then
  223. vim /etc/fstab
  224. fi
  225. clear
  226. rm -rf /etc/sudoers.d/nopwd
  227. echo "Defaults env_reset,pwfeedback" > /etc/sudoers.d/wheel
  228. echo "%wheel ALL=(ALL) ALL" >> /etc/sudoers.d/wheel
  229. echo "$username $hostname =NOPASSWD: /sbin/shutdown ,/sbin/halt,/sbin/reboot,/sbin/hibernate, /bin/pacman -Syyuw --noconfirm" >> /etc/sudoers.d/wheel
  230. ln -sf /bin/dash /bin/sh
  231. clear
  232. echo "SETUP COMPLETE"
  233. bash
  234. rm -rf /install