148 lines
5.3 KiB
Bash
Executable File
148 lines
5.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# -*- coding: utf-8 -*-
|
|
|
|
### Artix Linux minimal LUKS encryption install script ###
|
|
### Developed by Moony ###
|
|
### From '9d5 until infinity ###
|
|
|
|
|
|
### PROPER USAGE CHECKS ###
|
|
[ -z "$1" ] && echo "Usage:
|
|
artix-luks-base-install /dev/sdX encrytption_pw root_pw" && exit
|
|
[ -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
|
|
|
|
|
|
### PARAMETERS ###
|
|
targetDisk="/dev/sdX" # /dev/sdX
|
|
[ -z "$targetDisk" ] && echo "No target disk specified." && exit
|
|
|
|
cryptPass="P455w0rd" # Luks password
|
|
[ -z "$cryptPass" ] && echo "No encryption password provided." && exit
|
|
|
|
rootPassword="R00TP455W0RD" # Root user password
|
|
[ -z "$rootPassword" ] && echo "No root password provided." && exit
|
|
|
|
volGroup=lvmGroup # Lvm Volume Group Name
|
|
hostName=hostname # Computer hostname
|
|
|
|
echo "+-- Artix Installation Parameters --+"
|
|
echo "| Target disk path : \"$targetDisk\""
|
|
echo "| LUKS pass : \"$cryptPass\""
|
|
echo "| CryptVol Group : \"$volGroup\""
|
|
echo "+-----------------------------------+"
|
|
echo -n "Correct: y/n?" && read -r
|
|
|
|
|
|
### RESET / INITIALIZE ###
|
|
pacman -Sy --noconfirm parted
|
|
# swapoff /dev/$volGroup/swap 2>/dev/null # If using SWAP partition
|
|
swapoff /mnt/swapfile # If using SWAP file
|
|
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
|
|
|
|
|
|
### PARTITION THE DISKS ###
|
|
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%
|
|
|
|
|
|
### SETUP LUKS ENCRYPTED CONTAINER ###
|
|
echo -ne "$cryptPass" | cryptsetup luksFormat "${targetDisk}2" -d -
|
|
echo -ne "$cryptPass" | cryptsetup open "${targetDisk}2" lvm-system -d -
|
|
|
|
|
|
### CREATE LVM VOLUMES ###
|
|
pvcreate /dev/mapper/lvm-system
|
|
vgcreate $volGroup /dev/mapper/$volGroup
|
|
# 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
|
|
lvcreate -l 100%FREE $volGroup -n ROOT
|
|
|
|
|
|
### CREATE FILE SYSTEMS ###
|
|
mkfs.fat -F32 "${targetDisk}1"
|
|
# mkswap -f /dev/$volGroup/SWAP # To create a swap partition
|
|
mkfs.ext4 -qF /dev/$volGroup/ROOT
|
|
# 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 ###
|
|
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
|
|
|
|
|
|
### INSTALL GRUB ###
|
|
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'
|
|
|
|
|
|
### SET THE ROOT PASSWORD AND SUDOERS ###
|
|
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
|
|
|
|
### SET THE HOSTNAME ###
|
|
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
|
|
|
|
### SET LOCALE AND DEFAULT TIMEZONE ###
|
|
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'
|
|
|
|
### PERFORM CLEANUP ###
|
|
swapoff /mnt/swapfile # When using SWAP file.
|
|
# swapoff /mnt/$volGroup/SWAP # When using SWAP partitition.
|
|
umount -R /mnt
|
|
vgchange -a n
|
|
cryptsetup close $volGroup
|
|
|
|
### INSTALLATION COMPLETE ###
|
|
set +x
|
|
echo
|
|
echo "+-------------------------------------------------------------------------+"
|
|
echo "| Installation completed, Qyou can log in with root password $rootPassword |"
|
|
echo "+-------------------------------------------------------------------------+"
|