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.

287 lines
8.2 KiB

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