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.

284 lines
8.1 KiB

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