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.

288 lines
7.1 KiB

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