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.

275 lines
6.6 KiB

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