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
8.0 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. install_deps(){
  36. info "Installing dependencies"
  37. sudo pacman -Sy --needed --noconfirm git tmux 2> /dev/null > /dev/null
  38. }
  39. banner(){
  40. echo "${CYAN}
  41. dP dP .d888888 .d888888 .d88888b .d88888b
  42. Y8. .8P d8' 88 d8' 88 88. \"' 88. \"'
  43. Y8aa8P 88aaaaa88a 88aaaaa88a \`Y88888b. \`Y88888b.
  44. 88 88 88 88 88 \`8b \`8b
  45. 88 88 88 88 88 d8' .8P d8' .8P
  46. dP 88 88 88 88 Y88888P Y88888P
  47. ${NC}"
  48. echo " ${PURPLE}Yeet's Automated Arch Setup Script${NC}"
  49. }
  50. help(){
  51. printf"
  52. ${GREEN} Usage:${NC}\n
  53. -o Select the OS you are installing this on
  54. -v Run in verbose mode
  55. ${ORANGE}Author:${NC} Yigit Colakoglu aka. ${BLUE}<===8 Fr1nge 8===>${NC}\n"
  56. exit 0
  57. }
  58. os=""
  59. while [[ $# -gt 0 ]]
  60. do
  61. key="$1"
  62. case $key in
  63. -o|--os)
  64. os="$(echo "$2" | tr '[:upper:]' '[:lower:]')"
  65. shift 2
  66. ;;
  67. -v|--verbose)
  68. verbose=1
  69. shift
  70. ;;
  71. *)
  72. help
  73. ;;
  74. esac
  75. done
  76. if [ "$os" = "" ]; then
  77. os=$(prompt "Please enter the OS you want to install on(Arch/Artix): " | tr '[:upper:]' '[:lower:]')
  78. fi
  79. if [ ! "$os" = "arch" ] && [ ! "$os" = "artix" ]; then
  80. error "OS must be Arch or Artix"
  81. exit 1
  82. fi
  83. # Disk setup
  84. lsblk
  85. device=$(prompt "What is the install device: ")
  86. info "Installing to $device... (Enter to continue)"
  87. read -r _
  88. clear
  89. wipe=$(prompt "Would you like to wipe and re-partition the disk $device?(Y/n): ")
  90. if [ ! "$wipe" = "n" ]; then
  91. # Disk wipe
  92. secure=$(prompt "Should I do a secure wipe?(y/N): ")
  93. if [ "$secure" = "y" ]; then
  94. info "Writing random data to disk, this might take a while if you have a large drive..."
  95. cryptsetup open -q --type plain -d /dev/urandom "$device" wipe
  96. dd if=/dev/zero of=/dev/mapper/wipe status=progress
  97. cryptsetup -q close wipe
  98. fi
  99. info "Wiping the partition table..."
  100. cryptsetup erase "$device"
  101. wipefs -a -f "$device"
  102. sleep 1
  103. fi
  104. clear
  105. # Run cfdisk for manual partitioning
  106. cfdisk "$device"
  107. clear
  108. sleep 2
  109. [ ! "$(command -v partprobe)" = "" ] && partprobe
  110. lsblk "$device"
  111. satisfied=$(prompt "Are you satisfied with your partitions?(Y/n): ")
  112. while [ "$satisfied" = "n" ]; do
  113. cfdisk "$device"
  114. clear
  115. [ ! "$(command -v partprobe)" = "" ] && partprobe
  116. lsblk "$device"
  117. satisfied=$(prompt "Are you satisfied with your partitions?(Y/n): ")
  118. done
  119. clear
  120. lsblk "$device"
  121. echo ""
  122. echo "Now you will specify the partitions you have created"
  123. echo "Please enter the suffix for each partition. For Ex:"
  124. echo "1 if boot partition is /dev/sda1 or p1 if boot is on /dev/nvme0n1p1 and the disk is /dev/nvme0n1"
  125. boot_p=$(prompt "Please enter boot partition suffix: ")
  126. root_p=$(prompt "Please enter root partition suffix: ")
  127. swap_p=$(prompt "Please enter swap partition suffix: ")
  128. boot=$device$boot_p
  129. root=$device$root_p
  130. swap=$device$swap_p
  131. if [ -z "$home_s" ]; then
  132. home_s=$(prompt "Did you create a home partition as well?(y/N): ")
  133. fi
  134. if [ "$home_s" = "y" ]; then
  135. home_p=$(prompt "Please enter home partition suffix: ")
  136. home=$device$home_p
  137. fi
  138. clear
  139. # Create the boot partition
  140. info "Formatting boot partition"
  141. mkfs.fat -F32 "$boot"
  142. encryption=$(prompt "Would you like to enrypt your disks?(y/N): ")
  143. if [ "$encryption" = "y" ]; then
  144. clear
  145. info "Running benchmark"
  146. cryptsetup benchmark
  147. cipher=$(prompt "Please select the ciphering algorithm(aes-xts-plain64): ")
  148. if [ "$cipher" = "" ]; then
  149. cipher="aes-xts-plain64"
  150. fi
  151. iter=$("Please select the iter time(750): ")
  152. if [ "$iter" = "" ]; then
  153. iter="750"
  154. fi
  155. keysize=$("Please select the key size(512): ")
  156. if [ "$keysize" = "" ]; then
  157. keysize="512"
  158. fi
  159. # Create the swap partition
  160. mkdir /root/.keys
  161. dd if=/dev/urandom of=/root/.keys/swap-keyfile bs=1024 count=4
  162. chmod 600 /root/.keys/swap-keyfile
  163. cryptsetup --key-size "$keysize" --cipher "$cipher" --iter-time "$iter" -q luksFormat "$swap" < /root/.keys/swap-keyfile
  164. info "Keyfile saved to /root/.keys/swap-keyfile"
  165. cryptsetup open --key-file="/root/.keys/swap-keyfile" "$swap" swap
  166. mkswap /dev/mapper/swap
  167. swapon /dev/mapper/swap
  168. # Create the root partition
  169. root_pass="$(prompt "Enter password for root encryption")"
  170. echo "$root_pass" | cryptsetup --key-size "$keysize" --cipher "$cipher" --iter-time "$iter" -q luksFormat "$root"
  171. dd bs=512 count=4 if=/dev/random of=/root/.keys/root-keyfile iflag=fullblock
  172. chmod 600 /root/.keys/root-keyfile
  173. echo "$root_pass" | cryptsetup luksAddKey "$root" /root/.keys/root-keyfile
  174. echo "[INFO]: Keyfile saved to /root/.keys/root-keyfile"
  175. cryptsetup open --key-file="/root/.keys/root-keyfile" "$root" root
  176. mkfs.ext4 -F /dev/mapper/root
  177. mkdir /mnt/sys
  178. mount /dev/mapper/root /mnt/sys
  179. if [ "$home_s" = "y" ]; then
  180. home_pass="$(prompt "Enter password for home encryption")"
  181. echo "$home_pass" | cryptsetup --key-size "$keysize" --cipher "$cipher" --iter-time "$iter" -q luksFormat "$home"
  182. dd bs=512 count=4 if=/dev/random of=/root/.keys/home-keyfile iflag=fullblock
  183. chmod 600 /root/.keys/home-keyfile
  184. echo "$home_pass" | cryptsetup luksAddKey "$home" /root/.keys/home-keyfile
  185. echo "[INFO]: Keyfile saved to /root/.keys/home-keyfile"
  186. cryptsetup open --key-file="/root/.keys/home-keyfile" "$home" home
  187. mkfs.ext4 -F /dev/mapper/home
  188. mkdir /mnt/sys/home
  189. mount "/dev/mapper/home" /mnt/sys/home
  190. fi
  191. else
  192. mkswap "$swap"
  193. swapon "$swap"
  194. mkfs.ext4 -F "$root"
  195. mkdir /mnt/sys
  196. mount "$root" /mnt/sys
  197. if [ "$home_s" = "y" ]; then
  198. mkfs.ext4 -F "$home"
  199. mkdir /mnt/sys/home
  200. mount "$home" /mnt/sys/home
  201. fi
  202. fi
  203. mkdir /mnt/sys/boot
  204. mount "$boot" /mnt/sys/boot
  205. clear
  206. mkdir /mnt/sys/install
  207. case $os in
  208. arch)
  209. pacstrap /mnt/sys base linux linux-firmware base-devel vi nano
  210. genfstab -U /mnt/sys >> /mnt/sys/etc/fstab
  211. curl https://raw.githubusercontent.com/theFr1nge/YAASS/main/arch/pkg.list > /mnt/sys/install/packages.base
  212. curl https://raw.githubusercontent.com/theFr1nge/YAASS/main/arch/stage2.sh > /mnt/sys/install/stage2.sh
  213. ;;
  214. artix)
  215. basestrap /mnt/sys base linux linux-firmware base-devel vi nano openrc
  216. fstabgen -U /mnt/sys >> /mnt/sys/etc/fstab
  217. curl https://raw.githubusercontent.com/theFr1nge/YAASS/main/artix/pkg.list > /mnt/sys/install/packages.base
  218. curl https://raw.githubusercontent.com/theFr1nge/YAASS/main/artix/stage2.sh > /mnt/sys/install/stage2.sh
  219. ;;
  220. esac
  221. chmod +x /mnt/sys/install/stage2.sh
  222. tmpfs_ok=$(prompt "Would you like to use tmpfs (This can drastically improve performance)?(Y/n): ")
  223. if [ ! "$tmpfs_ok" = "n" ]; then
  224. tmpfs_size=$("How big should the tmpfs be?(end with G or M): ")
  225. printf "\n#tmpfs\ntmpfs /tmp tmpfs rw,nodev,nosuid,size=%s 0 0\n" "$tmpfs_size" >> /mnt/sys/etc/fstab
  226. fi
  227. clear
  228. encryption_param="1"
  229. if [ ! "$encryption" = "n" ]; then
  230. cp -r /root/.keys /mnt/sys/root
  231. encryption_param="0"
  232. fi
  233. if [ "$os" = "arch" ];then
  234. tmux new-session -s "arch-setup" "arch-chroot /mnt/sys /install/stage2.sh \"$encryption_param\" \"$boot\" \"$root\" \"$swap\" \"$home\"" || arch-chroot /mnt/sys /install/stage2.sh "$encryption_param" "$boot" "$root" "$swap" "$home"
  235. else
  236. tmux new-session -s "artix-setup" "artix-chroot /mnt/sys /install/stage2.sh \"$encryption_param\" \"$boot\" \"$root\" \"$swap\" \"$home\"" || artix-chroot /mnt/sys /install/stage2.sh "$encryption_param" "$boot" "$root" "$swap" "$home"
  237. fi