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.

281 lines
8.1 KiB

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