artix_base_install/artix-luks-base-install.sh

148 lines
5.3 KiB
Bash
Raw Permalink Normal View History

2023-03-13 02:08:25 +00:00
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
2023-04-04 23:58:53 +00:00
### Artix Linux minimal LUKS encryption install script ###
### Developed by Moony ###
### From '9d5 until infinity ###
2023-03-13 02:08:25 +00:00
2023-04-04 23:58:53 +00:00
### PROPER USAGE CHECKS ###
2023-03-13 02:08:25 +00:00
[ -z "$1" ] && echo "Usage:
2023-03-13 02:11:33 +00:00
artix-luks-base-install /dev/sdX encrytption_pw root_pw" && exit
2023-03-13 02:08:25 +00:00
[ -z "$(ls /sys/firmware/efi/efivars)" ] && echo "EFI only installation; Please boot with EFI." && exit
[ "$(id -u)" != 0 ] && echo "Root privileges required." && exit
! "$(connmanctl state | grep -qe online -qe ready)" &&
echo "No network connection." && exit
# THe two lines above are more effective than the two below.
# [ -z "$(connmanctl state | grep -e online -e ready)" ] &&
# echo "No network connection." && exit
2023-04-04 23:58:53 +00:00
2023-03-13 02:08:25 +00:00
### PARAMETERS ###
2023-04-04 23:58:53 +00:00
targetDisk="/dev/sdX" # /dev/sdX
2023-03-13 02:08:25 +00:00
[ -z "$targetDisk" ] && echo "No target disk specified." && exit
2023-04-04 23:58:53 +00:00
cryptPass="P455w0rd" # Luks password
2023-03-13 02:08:25 +00:00
[ -z "$cryptPass" ] && echo "No encryption password provided." && exit
2023-04-04 23:58:53 +00:00
rootPassword="R00TP455W0RD" # Root user password
2023-03-13 02:08:25 +00:00
[ -z "$rootPassword" ] && echo "No root password provided." && exit
2023-04-04 23:58:53 +00:00
volGroup=lvmGroup # Lvm Volume Group Name
hostName=hostname # Computer hostname
2023-03-13 02:08:25 +00:00
echo "+-- Artix Installation Parameters --+"
2023-04-04 23:58:53 +00:00
echo "| Target disk path : \"$targetDisk\""
echo "| LUKS pass : \"$cryptPass\""
echo "| CryptVol Group : \"$volGroup\""
echo "+-----------------------------------+"
echo -n "Correct: y/n?" && read -r
2023-03-13 02:08:25 +00:00
2023-04-04 23:58:53 +00:00
### RESET / INITIALIZE ###
2023-03-13 02:08:25 +00:00
pacman -Sy --noconfirm parted
2023-04-04 23:58:53 +00:00
# swapoff /dev/$volGroup/swap 2>/dev/null # If using SWAP partition
swapoff /mnt/swapfile # If using SWAP file
2023-03-13 02:08:25 +00:00
umount -R /mnt 2>/dev/null
vgchange -a n 2>/dev/null
cryptsetup close lvm-system 2>/dev/null
killall -s 9 cryptsetup 2>/dev/null
2023-04-04 23:58:53 +00:00
### PARTITION THE DISKS ###
2023-03-13 02:08:25 +00:00
set -xe
parted -s -a optimal "$targetDisk" mklabel gpt
parted -s -a optimal "$targetDisk" mkpart "BOOT" fat32 0% 512MiB
parted -s -a optimal "$targetDisk" set 1 esp on
parted -s -a optimal "$targetDisk" mkpart "ROOT" ext4 512MiB 100%
2023-04-04 23:58:53 +00:00
### SETUP LUKS ENCRYPTED CONTAINER ###
2023-03-13 02:08:25 +00:00
echo -ne "$cryptPass" | cryptsetup luksFormat "${targetDisk}2" -d -
echo -ne "$cryptPass" | cryptsetup open "${targetDisk}2" lvm-system -d -
2023-04-04 23:58:53 +00:00
### CREATE LVM VOLUMES ###
2023-03-13 02:08:25 +00:00
pvcreate /dev/mapper/lvm-system
vgcreate $volGroup /dev/mapper/$volGroup
2023-04-04 23:58:53 +00:00
# lvcreate -L 8G $volGroup -n SWAP # For SWAP partition if a SWAP partition is desired
# lvcreate -L 50G $volGroup -n HOME # For HOME partition if a separate home or var partition is desired
2023-03-13 02:08:25 +00:00
lvcreate -l 100%FREE $volGroup -n ROOT
2023-04-04 23:58:53 +00:00
### CREATE FILE SYSTEMS ###
2023-03-13 02:08:25 +00:00
mkfs.fat -F32 "${targetDisk}1"
2023-04-04 23:58:53 +00:00
# mkswap -f /dev/$volGroup/SWAP # To create a swap partition
2023-03-13 02:08:25 +00:00
mkfs.ext4 -qF /dev/$volGroup/ROOT
2023-04-04 23:58:53 +00:00
# mkfs.ext4 -qF /dev/$volGroup/HOME # To create a HOME file system
### ROOT PARTITION ###
mount /dev/$volGroup/ROOT /mnt # Mount ROOT partition
### HOME PARTITION ###
# mkdir /mnt/home # Create a HOME folder if using HOME partition
# mount /dev/$volGroup/HOME /mnt/home # Mount HOME partition if created
mkdir /mnt/boot # Create BOOT path in ROOT directory
mount "${targetDisk}1" /mnt/boot # Mount BOOT partition
dd if=swap bs=1M of=/mnt/swapfile # Create a SWAP file instead of partition
swapon /mnt/swapfile # Turn on the SWAP file
# swapon /dev/$volGroup/SWAP # Turn on SWAP partition.
### INSTALL THE BASE SYSTEM ###
2023-03-13 02:08:25 +00:00
basestrap /mnt openrc elogind-openrc base base-devel connman-openrc connman-gtk neovim
basestrap /mnt linux linux-firmware intel-ucode
fstabgen -U /mnt >/mnt/etc/fstab
sed -s 's/^HOOKS=.*/HOOKS=(base udev autodetect modconf block encrypt keyboard keymap lvm2 resume filesystems fsck)/g' -i /mnt/etc/mkinitcpio.conf
basestrap /mnt cryptsetup lvm2 mkinitcpio grub efibootmgr
2023-04-04 23:58:53 +00:00
### INSTALL GRUB ###
2023-03-13 02:08:25 +00:00
cryptUUID=$(blkid -s UUID -o value "${targetDisk}2")
swapUUID=$(blkid -s UUID -o value /dev/$volGroup/swap) # For SWAP partition.
sed -s "s/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT=\"\
cryptdevice=UUID=$cryptUUID:lvm-system loglevel=3 quiet resume=UUID=$swapUUID net.ifnames=0\"/g" \
-i /mnt/etc/default/grub
sed -s 's/^#GRUB_ENABLE_CRYPTODISK=y/GRUB_ENABLE_CRYPTODISK=y/g' -i /mnt/etc/default/grub
artix-chroot /mnt sh -c 'grub-install --target=x86_64-efi --efi-directory=/boot \
--bootloader-id=grub && grub-mkconfig -o /boot/grub/grub.cfg'
2023-04-04 23:58:53 +00:00
### SET THE ROOT PASSWORD AND SUDOERS ###
2023-03-13 02:08:25 +00:00
artix-chroot /mnt sh -c 'echo root:password | chpasswd'
sed -s 's/# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL \
Defaults rootpw,pwfeedback/g' -i /mnt/etc/sudoers
2023-04-04 23:58:53 +00:00
### SET THE HOSTNAME ###
2023-03-13 02:08:25 +00:00
echo "$hostName" >/mnt/etc/hostname
echo "$hostName" >/mnt/etc/
echo "127.0.0.1 localhost
::1 localhost
127.0.1.1 $hostName.vicious.ly $hostName" >>/mnt/etc/hosts
artix-chroot /mnt
2023-04-04 23:58:53 +00:00
### SET LOCALE AND DEFAULT TIMEZONE ###
2023-03-13 02:08:25 +00:00
echo 'LANG="en_US.UTF-8"
LC_COLLATE="C"' >/mnt/etc/locale.conf
sed -s 's/#en_US/en_US/g' -i /mnt/etc/locale.gen
artix-chroot /mnt sh -c 'locale-gen'
artix-chroot /mnt sh -c 'ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime && hwclock -w'
2023-04-04 23:58:53 +00:00
### PERFORM CLEANUP ###
swapoff /mnt/swapfile # When using SWAP file.
# swapoff /mnt/$volGroup/SWAP # When using SWAP partitition.
2023-03-13 02:08:25 +00:00
umount -R /mnt
vgchange -a n
cryptsetup close $volGroup
2023-04-04 23:58:53 +00:00
### INSTALLATION COMPLETE ###
2023-03-13 02:08:25 +00:00
set +x
echo
echo "+-------------------------------------------------------------------------+"
2023-04-04 23:58:53 +00:00
echo "| Installation completed, Qyou can log in with root password $rootPassword |"
2023-03-13 02:08:25 +00:00
echo "+-------------------------------------------------------------------------+"