arch.sh 3.4 KB

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