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.

282 lines
6.9 KiB

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