artix-install.sh (3308B)
1 #!/bin/sh 2 ###! FOR UEFI SYSTEMS ONLY !### 3 #TODO: implement other mountpoints/partitions 4 ### FUNCTIONS ### 5 test_drive () { 6 [ -z $(test -e $1) ] && echo "Incorrect drive input" && exit 1 7 } 8 9 get_var () { 10 echo $1 11 read $2 12 } 13 14 # set time zone 15 set_time () { 16 ln -sf /usr/share/zoneinfo/$country/$timezone /etc/localtime 17 } 18 19 # $1 options: 20 # urandom: secure but long 21 # null: quick and less secure 22 # $2 should be the drive to be wiped 23 wipe_drive () { 24 dd bs=4096 if=/dev/$1 iflag=nocache of=$2 oflag=direct status=progress && sync 25 } 26 27 ### SETTING VARIABLES ### 28 get_var "Which Drive should be the root:" root_drive 29 30 # testing if root drive exists 31 # TODO: write if statement or while loop to ask for correct drive if it doesnt exist 32 test_drive root_drive 33 34 get_var "Which filesystem type should the root partition be:" root_format 35 36 get_var "(Optional) mkfs args (leave blank to skip):" root_mkfs_args 37 38 get_var "Which Drive should be the /boot partition:" boot_drive 39 40 get_var "Which init system (options: dinit, s6, runit, openrc):" init 41 42 43 44 ### FORMATTING DRIVES ### 45 # clear drive 46 echo "Wiping $root_drive ..." 47 wipe_drive urandom $root_drive && sync 48 49 # encrypt drive 50 echo "Encrypting $root_drive ..." 51 cryptsetup luksFormat $root_drive && sync 52 53 # formatting boot drive 54 echo "Wiping $boot_drive ..." 55 wipe_drive urandom $boot_drive # clear drive 56 57 echo "Formatting and Labelling $boot_drive ..." 58 mkfs.fat -F 32 $boot_drive && sync # format drive 59 fatlabel $boot_drive ESP && sync # label drive 60 61 ### MOUNTING DRIVES ### 62 cryptname=cryptlvm # for further customizabity(?) 63 crypto=/dev/mapper/$cryptname # decrypted drive name 64 65 cryptsetup open $root_drive $cryptname 66 67 rtmnt=/mnt # mountpoint of root drive 68 69 mount $crypto $rtmnt # mount decrypted root drive 70 mount $boot_drive $rtmnt/boot # mount unencrypted boot drive in /boot of installation 71 72 73 ### INSTALLING MAIN SYSTEM ### 74 get_var "Which kernel would you like to install:" kernel 75 76 # strap main system w packages 77 # this package list is for desktop systems that connect wirelessly, edit package list or make alternate if you wish 78 basestrap /mnt base base-devel $kernel $kernel-headers iwd-$init dhcpcd-$init 79 80 # generate fstab 81 fstabgen -U $rtmnt >> $rtmnt/etc/fstab 82 83 # set timezome 84 ln -sf $rtmnt/usr/share/zoneinfo/$country/$timezone $rtmnt/etc/localtime 85 86 ### GRUB ### 87 grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=Artix 88 89 # TODO: set up configuration of /etc/default/grub 90 # Mostly done :D 91 root_basename=$(echo $root_drive | awk -F '/' '{print $2}') 92 root_uuid=$(lsblk -f | grep root_basename) 93 grubcmdline="GRUB_CMDLINE_LINUX=\"cryptdevice=UUID=$root_uuid:$cryptname rootfstype=ext4\"" 94 sed -i "1s/$grubcmdline^/GRUB_/" $rtmnt/etc/default/grub 95 96 # build config 97 grub-mkconfig -o /boot/grub/grub.cfg 98 99 ## FIXME ### 100 # Possible solution: `artix-chroot $rtmnt ./chroot_script.sh` 101 artix-chroot $rtmnt # FIX THIS PLEASE FIXME TODO BIG TIME 102 103 # build & compress initramfs 104 initramfs_checker () { 105 which $1 && initramfsgen=$1 106 } 107 108 initramfs_checker mkinitcpio || initramfs_checker dracut 109 110 [ initramfsgen == dracut ] && dracut --regenerate-all --force 111 [ initramfsgen == mkinitcpio ] && mkinitcpio -P 112 113 echo "You have to enable services if they weren't already enabled by pacman hooks. Default service packages installed via this script are iwd and dhcpcd."