130 lines
4.8 KiB
Bash
Executable File
130 lines
4.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Artix Linux Minimal Encrypted Install Script.
|
|
# Coded by Moony
|
|
# 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=$1
|
|
[ -z "$targetDisk" ] && echo "No target disk specified." && exit
|
|
cryptPass=$2
|
|
[ -z "$cryptPass" ] && echo "No encryption password provided." && exit
|
|
rootPassword=$3
|
|
[ -z "$rootPassword" ] && echo "No root password provided." && exit
|
|
|
|
volGroup=lvmSystem
|
|
hostName=vicious
|
|
##################
|
|
|
|
echo "+-- Artix Installation Parameters --+"
|
|
echo "Target disk : \"$targetDisk\""
|
|
echo "Crypto pass : \"$cryptPass\""
|
|
echo "Cryptvol group: \"$volGroup\""
|
|
echo -n "Correct?" && read -r
|
|
|
|
# Reset/init.
|
|
pacman -Sy --noconfirm parted
|
|
# swapoff /dev/$volGroup/swap 2>/dev/null # for swap partition.
|
|
swapoff /mnt/swapfile # for 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
|
|
|
|
set -xe
|
|
# Partition the disk.
|
|
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%
|
|
|
|
# Set up LUKS encrypted container.
|
|
echo -ne "$cryptPass" | cryptsetup luksFormat "${targetDisk}2" -d -
|
|
echo -ne "$cryptPass" | cryptsetup open "${targetDisk}2" lvm-system -d -
|
|
|
|
# Create logical volumes.
|
|
pvcreate /dev/mapper/lvm-system
|
|
vgcreate $volGroup /dev/mapper/$volGroup
|
|
lvcreate -L 8G $volGroup -n SWAP # For swap partition
|
|
# lvcreate -L 50G $volGroup -n HOME # For set root partition if a separate home or var partition is desired.
|
|
lvcreate -l 100%FREE $volGroup -n ROOT
|
|
|
|
# Make filesystems.
|
|
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.
|
|
|
|
# Mount filesystems.
|
|
mount /dev/$volGroup/ROOT /mnt
|
|
# mkdir /mnt/home # Create a HOME folder if using partition.
|
|
# mount /dev/$volGroup/HOME /mnt/home # Mount HOME partition if in use.
|
|
mkdir /mnt/boot
|
|
mount "${targetDisk}1" /mnt/boot
|
|
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.
|
|
|
|
# Basestrap the system and install lvm hooks.
|
|
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 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 cleanups.
|
|
# swapoff /mnt/swapfile # When using SWAP file.
|
|
swapoff /mnt/$volGroup/SWAP
|
|
umount -R /mnt
|
|
vgchange -a n
|
|
cryptsetup close $volGroup
|
|
|
|
set +x
|
|
echo
|
|
echo "+-------------------------------------------------------------------------+"
|
|
echo "| Installation completed, you can log in with root password $rootPassword |"
|
|
echo "+-------------------------------------------------------------------------+"
|