arch.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #!/bin/bash
  2. # This a lazy and DANGEROUS way to install Arch.
  3. # I do not recommend this to other people, ONLY
  4. # do this if you exactly understand EVERY SINGLE
  5. # LINE of this bash script. You'll thank me later.
  6. pacman -Sy --noconfirm dialog || {
  7. printf "Error at script start:\n\nAre you sure you're running this as the root user?\n\t(Tip: run 'whoami' to check)\n\nAre you sure you have an internet connection?\n\t(Tip: run 'ip a' to check)\n"
  8. exit
  9. }
  10. # Hardware AES Detection
  11. if grep -q "\baes\b" /proc/cpuinfo; then
  12. AES_NI="yes"
  13. else
  14. AES_NI="no"
  15. fi
  16. dialog --no-cancel --inputbox "Enter the hostname." 10 60 2>comp
  17. clear
  18. lsblk -d | sed 's/0 disk/0 disk\\n/;s/POINT/POINT\\n/'
  19. read -rp "Press any key to continue"
  20. dialog --no-cancel --inputbox "Enter the drive you want do install Arch on." 10 60 2>drive
  21. dialog --defaultno --title "Time Zone select" --yesno "Do you want use the default time zone(Europe/Zurich)?.\n\nPress no for select your own time zone" 10 60 && echo "Europe/Zurich" >tz.tmp || tzselect >tz.tmp
  22. dialog --no-cancel --inputbox "Enter swapsize in gb (only type in numbers)." 10 60 2>swapsize
  23. ls /sys/firmware/efi/efivars && EFI=yes
  24. SIZE=$(cat swapsize)
  25. DRIVE=$(cat drive)
  26. PVALUE=$(echo "${DRIVE}" | grep "^nvme" | sed 's/.*[0-9]/p/')
  27. timedatectl set-ntp true
  28. # Dynamic Partitioning
  29. if [ "$EFI" = "yes" ]; then
  30. if [ "$AES_NI" = "yes" ]; then
  31. UEFI_LETTER="1"
  32. SWAP_LETTER="2"
  33. ROOT_LETTER="3"
  34. cat <<EOF | fdisk -W always /dev/"${DRIVE}"
  35. g
  36. n
  37. +1024M
  38. t
  39. 1
  40. n
  41. +${SIZE}G
  42. t
  43. 2
  44. 19
  45. n
  46. w
  47. EOF
  48. else
  49. UEFI_LETTER="1"
  50. SWAP_LETTER="2"
  51. BOOT_LETTER="3"
  52. ROOT_LETTER="4"
  53. cat <<EOF | fdisk -W always /dev/"${DRIVE}"
  54. g
  55. n
  56. +1024M
  57. t
  58. 1
  59. n
  60. +${SIZE}G
  61. t
  62. 2
  63. 19
  64. n
  65. +1024M
  66. n
  67. w
  68. EOF
  69. fi
  70. else
  71. if [ "$AES_NI" = "yes" ]; then
  72. SWAP_LETTER="1"
  73. ROOT_LETTER="2"
  74. cat <<EOF | fdisk -W always /dev/"${DRIVE}"
  75. o
  76. n
  77. p
  78. +${SIZE}G
  79. t
  80. 82
  81. n
  82. p
  83. a
  84. 2
  85. w
  86. EOF
  87. else
  88. SWAP_LETTER="1"
  89. BOOT_LETTER="2"
  90. ROOT_LETTER="3"
  91. cat <<EOF | fdisk -W always /dev/"${DRIVE}"
  92. o
  93. n
  94. p
  95. +${SIZE}G
  96. t
  97. 82
  98. n
  99. p
  100. +1024M
  101. n
  102. p
  103. a
  104. 2
  105. w
  106. EOF
  107. fi
  108. fi
  109. partprobe
  110. # Dynamic LUKS Formatting
  111. while true; do
  112. if [ "$AES_NI" = "yes" ]; then
  113. cryptsetup luksFormat --type luks2 /dev/"${DRIVE}${PVALUE}${ROOT_LETTER}" && break
  114. else
  115. cryptsetup luksFormat --type luks2 --cipher xchacha12,aes-adiantum-plain64 --hash sha256 /dev/"${DRIVE}${PVALUE}${ROOT_LETTER}" && break
  116. fi
  117. done
  118. while true; do
  119. cryptsetup open /dev/"${DRIVE}${PVALUE}${ROOT_LETTER}" cryptroot && break
  120. done
  121. yes | mkfs.ext4 /dev/mapper/cryptroot
  122. mount /dev/mapper/cryptroot /mnt
  123. # Mount Unencrypted Boot (if Adiantum)
  124. if [ "$AES_NI" = "no" ]; then
  125. yes | mkfs.ext4 /dev/"${DRIVE}${PVALUE}${BOOT_LETTER}"
  126. mkdir -p /mnt/boot
  127. mount /dev/"${DRIVE}${PVALUE}${BOOT_LETTER}" /mnt/boot
  128. fi
  129. # Mount EFI
  130. if [ "$EFI" = "yes" ]; then
  131. mkfs.vfat -F32 /dev/"${DRIVE}${PVALUE}${UEFI_LETTER}"
  132. mkdir -p /mnt/boot/efi
  133. mount /dev/"${DRIVE}${PVALUE}${UEFI_LETTER}" /mnt/boot/efi
  134. fi
  135. pacman -Sy --noconfirm archlinux-keyring
  136. pacstrap /mnt base linux linux-firmware cryptsetup
  137. genfstab -U /mnt >>/mnt/etc/fstab
  138. # Pass variables to chroot
  139. cat tz.tmp >/mnt/tzfinal.tmp
  140. echo "$AES_NI" >/mnt/aes.tmp
  141. rm tz.tmp
  142. mv drive /mnt
  143. mv comp /mnt/etc/hostname
  144. curl -LO https://noahvogt.com/chroot.sh --output-dir /mnt && arch-chroot /mnt bash chroot.sh && rm /mnt/chroot.sh