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.

279 lines
6.8 KiB

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