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.

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