Initial commit.

This commit is contained in:
Moony 2024-05-08 14:40:21 -04:00
commit 29da9b9602
5 changed files with 292 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.bak
__pycache__
Session.vim

30
README.md Normal file
View File

@ -0,0 +1,30 @@
# AutoArtix
![](https://img.shields.io/badge/OS-Artix%20Linux-blue?logo=Artix+Linux)
A simple installer for Artix Linux. Supports OpenRC and dinit.
## Usage
1. Boot into the Artix live disk (the login and password are both `artix`).
2. Connect to the internet. Ethernet is setup automatically, and wifi is done with something like:
```shell
sudo rfkill unblock wifi
sudo ip link set wlan0 up
connmanctl
```
In Connman, use: `agent on`, `scan wifi`, `services`, `connect wifi_NAME`, `quit`
3. Acquire the install scripts:
```shell
git clone https://git.collectiveanalytics.net/moony/AutoArtix.git
```
4. Run `./install.sh`.
5. When everything finishes, `poweroff`, remove the installation media, and boot into Artix. Post-installation networking is done with Connman.
### Preinstallation
* ISO downloads can be found at [artixlinux.org](https://artixlinux.org/download.php)
* ISO files can be burned to drives with `dd` or something like Etcher.
* `sudo dd bs=4M if=/path/to/artix.iso of=/dev/sd[drive letter] status=progress`
* A better method these days is to use [Ventoy](https://www.ventoy.net/en/index.html).

105
install.sh Executable file
View File

@ -0,0 +1,105 @@
#!/bin/sh
# -*- coding: utf-8 -*-
# A simple installer for Artix Linux
confirm_password() {
stty -echo
until [ "$pass1" = "$pass2" ] && [ "$pass2" ]; do
printf "%s: " "$1" >&2 && read -r pass1 && printf "\n" >&2
printf "confirm %s: " "$1" >&2 && read -r pass2 && printf "\n" >&2
done
stty echo
echo "$pass2"
}
# Load keymap
sudo loadkeys us
# Check boot mode
[ ! -d /sys/firmware/efi ] && printf "Not booted in UEFI mode. Aborting..." && exit 1
# Choose MY_INIT
until [ "$MY_INIT" = "openrc" ] || [ "$MY_INIT" = "dinit" ]; do
printf "Init system (openrc/dinit): " && read -r MY_INIT
[ ! "$MY_INIT" ] && MY_INIT="openrc"
done
# Choose disk
while :; do
sudo fdisk -l
printf "\nDisk to install to (e.g. /dev/sda): " && read -r MY_DISK
[ -b "$MY_DISK" ] && break
done
PART1="$MY_DISK"1
PART2="$MY_DISK"2
PART3="$MY_DISK"3
case "$MY_DISK" in
*"nvme"*)
PART1="$MY_DISK"p1
PART2="$MY_DISK"p2
PART3="$MY_DISK"p3
;;
esac
# Swap size
until (echo "$SWAP_SIZE" | grep -Eq "^[0-9]+$") && [ "$SWAP_SIZE" -gt 0 ] && [ "$SWAP_SIZE" -lt 97 ]; do
printf "Size of swap partition in GiB (4): " && read -r SWAP_SIZE
[ ! "$SWAP_SIZE" ] && SWAP_SIZE=4
done
# Choose filesystem
until [ "$MY_FS" = "btrfs" ] || [ "$MY_FS" = "ext4" ]; do
printf "Filesystem (btrfs/ext4): " && read -r MY_FS
[ ! "$MY_FS" ] && MY_FS="btrfs"
done
ROOT_PART=$PART3
[ "$MY_FS" = "ext4" ] && ROOT_PART=$PART2
# Encrypt or not
printf "Encrypt? (y/N): " && read -r ENCRYPTED
[ ! "$ENCRYPTED" ] && ENCRYPTED="n"
MY_ROOT="/dev/mapper/root"
MY_SWAP="/dev/mapper/swap"
if [ "$ENCRYPTED" = "y" ]; then
CRYPTPASS=$(confirm_password "encryption password")
else
MY_ROOT=$PART3
MY_SWAP=$PART2
[ "$MY_FS" = "ext4" ] && MY_ROOT=$PART2
fi
[ "$MY_FS" = "ext4" ] && MY_SWAP="/dev/MyVolGrp/swap"
# Timezone
until [ -f /usr/share/zoneinfo/"$REGION_CITY" ]; do
printf "Region/City (e.g. 'America/Denver'): " && read -r REGION_CITY
[ ! "$REGION_CITY" ] && REGION_CITY="America/Denver"
done
# Host
while :; do
printf "Hostname: " && read -r MY_HOSTNAME
[ "$MY_HOSTNAME" ] && break
done
# Users
ROOT_PASSWORD=$(confirm_password "root password")
installvars() {
echo MY_INIT="$MY_INIT" MY_DISK="$MY_DISK" PART1="$PART1" PART2="$PART2" PART3="$PART3" \
SWAP_SIZE="$SWAP_SIZE" MY_FS="$MY_FS" ROOT_PART="$ROOT_PART" ENCRYPTED="$ENCRYPTED" MY_ROOT="$MY_ROOT" MY_SWAP="$MY_SWAP" \
REGION_CITY="$REGION_CITY" MY_HOSTNAME="$MY_HOSTNAME" \
CRYPTPASS="$CRYPTPASS" ROOT_PASSWORD="$ROOT_PASSWORD"
}
printf "\nDone with configuration. Installing...\n\n"
# Install
sudo "$(installvars)" sh src/installer.sh
# Chroot
sudo cp src/iamchroot.sh /mnt/root/ &&
sudo "$(installvars)" artix-chroot /mnt /bin/bash -c 'sh /root/iamchroot.sh; rm /root/iamchroot.sh; exit' &&
printf '\nYou may now poweroff.\n'

83
src/iamchroot.sh Executable file
View File

@ -0,0 +1,83 @@
#!/bin/sh
# -*- coding: utf-8 -*-
# A simple installer for Artix Linux
# Boring stuff you should probably do
ln -sf /usr/share/zoneinfo/"$REGION_CITY" /etc/localtime
hwclock --systohc
# Localization
printf "en_US.UTF-8 UTF-8\n" >>/etc/locale.gen
locale-gen
printf "LANG=en_US.UTF-8\n" >/etc/locale.conf
printf "KEYMAP=us\n" >/etc/vconsole.conf
# Host stuff
printf '%s\n' "$MY_HOSTNAME" >/etc/hostname
printf 'hostname="%s"\n' "$MY_HOSTNAME" >/etc/conf.d/hostname
printf "\n127.0.0.1\tlocalhost\n::1\t\tlocalhost\n127.0.1.1\t%s.localdomain\t%s\n" "$MY_HOSTNAME" "$MY_HOSTNAME" >/etc/hosts
# Install boot loader
ROOT_PART_uuid=$(blkid "$ROOT_PART" -o value -s UUID)
if [ "$ENCRYPTED" = "y" ]; then
my_params="cryptdevice=UUID=$ROOT_PART_uuid:root root=\/dev\/mapper\/root"
if [ "$MY_FS" = "ext4" ]; then
my_params="cryptdevice=UUID=$ROOT_PART_uuid:root root=\/dev\/MyVolGrp\/root"
fi
elif [ "$MY_FS" = "ext4" ]; then
my_params="root=\/dev\/MyVolGrp\/root"
fi
sed -i "s/^GRUB_CMDLINE_LINUX_DEFAULT.*$/GRUB_CMDLINE_LINUX_DEFAULT=\"$my_params\"/g" /etc/default/grub
[ "$ENCRYPTED" = "y" ] && sed -i '/GRUB_ENABLE_CRYPTODISK=y/s/^#//g' /etc/default/grub
grub-install --target=x86_64-efi --efi-directory=/boot --recheck
grub-install --target=x86_64-efi --efi-directory=/boot --removable --recheck
grub-mkconfig -o /boot/grub/grub.cfg
# Root user
yes "$ROOT_PASSWORD" | passwd
sed -i '/%wheel ALL=(ALL) ALL/s/^#//g' /etc/sudoers
# Other stuff you should do
if [ "$MY_INIT" = "openrc" ]; then
rc-update add connmand default
elif [ "$MY_INIT" = "dinit" ]; then
ln -s /etc/dinit.d/connmand /etc/dinit.d/boot.d/
fi
[ "$MY_FS" = "ext4" ] && [ "$MY_INIT" = "openrc" ] && rc-update add lvm boot
printf "\n%s\t\tswap\t\tswap\t\tsw\t0 0\n" "$MY_SWAP" >>/etc/fstab
if [ "$ENCRYPTED" = "y" ] && [ "$MY_FS" = "btrfs" ]; then
swap_uuid=$(blkid "$PART2" -o value -s UUID)
mkdir /root/.keyfiles
chmod 0400 /root/.keyfiles
dd if=/dev/urandom of=/root/.keyfiles/main bs=1024 count=4
yes "$CRYPTPASS" | cryptsetup luksAddKey "$PART2" /root/.keyfiles/main
printf "dmcrypt_key_timeout=1\ndmcrypt_retries=5\n\ntarget='swap'\nsource=UUID='%s'\nkey='/root/.keyfiles/main'\n#\n" "$swap_uuid" >/etc/conf.d/dmcrypt
[ "$MY_INIT" = "openrc" ] && rc-update add dmcrypt boot
fi
# Configure mkinitcpio
if [ "$MY_FS" = "ext4" ]; then
if [ "$ENCRYPTED" = "y" ]; then
sed -i 's/^HOOKS.*$/HOOKS=(base udev autodetect keyboard keymap modconf block encrypt lvm2 filesystems fsck)/g' /etc/mkinitcpio.conf
else
sed -i 's/^HOOKS.*$/HOOKS=(base udev autodetect keyboard keymap modconf block lvm2 filesystems fsck)/g' /etc/mkinitcpio.conf
fi
elif [ "$MY_FS" = "btrfs" ]; then
sed -i 's/BINARIES=()/BINARIES=(\/usr\/bin\/btrfs)/g' /etc/mkinitcpio.conf
if [ "$ENCRYPTED" = "y" ]; then
sed -i 's/^HOOKS.*$/HOOKS=(base udev autodetect keyboard keymap modconf block encrypt filesystems fsck)/g' /etc/mkinitcpio.conf
else
sed -i 's/^HOOKS.*$/HOOKS=(base udev autodetect keyboard keymap modconf block filesystems fsck)/g' /etc/mkinitcpio.conf
fi
fi
mkinitcpio -P

71
src/installer.sh Executable file
View File

@ -0,0 +1,71 @@
#!/bin/sh
# -*- coding: utf-8 -*-
# A simple installer for Artix Linux
# Partition disk
if [ "$MY_FS" = "ext4" ]; then
layout=",,V"
fs_pkgs="lvm2 lvm2-$MY_INIT"
elif [ "$MY_FS" = "btrfs" ]; then
layout=",${SWAP_SIZE}G,S\n,,"
fs_pkgs="btrfs-progs"
fi
[ "$ENCRYPTED" = "y" ] && fs_pkgs=$fs_pkgs+" cryptsetup cryptsetup-$MY_INIT"
printf "label: gpt\n,550M,U\n%s\n" "$layout" | sfdisk "$MY_DISK"
# Format and mount partitions
if [ "$ENCRYPTED" = "y" ]; then
yes "$CRYPTPASS" | cryptsetup -q luksFormat "$ROOT_PART"
yes "$CRYPTPASS" | cryptsetup open "$ROOT_PART" root
if [ "$MY_FS" = "btrfs" ]; then
yes "$CRYPTPASS" | cryptsetup -q luksFormat "$PART2"
yes "$CRYPTPASS" | cryptsetup open "$PART2" swap
fi
fi
mkfs.fat -F 32 "$PART1"
if [ "$MY_FS" = "ext4" ]; then
# Setup LVM
pvcreate "$MY_ROOT"
vgcreate MyVolGrp "$MY_ROOT"
lvcreate -L "$SWAP_SIZE"G MyVolGrp -n swap
lvcreate -l 100%FREE MyVolGrp -n root
mkfs.ext4 /dev/MyVolGrp/root
mount /dev/MyVolGrp/root /mnt
elif [ "$MY_FS" = "btrfs" ]; then
mkfs.btrfs "$MY_ROOT"
# Create subvolumes
mount "$MY_ROOT" /mnt
btrfs subvolume create /mnt/root
btrfs subvolume create /mnt/home
umount -R /mnt
# Mount subvolumes
mount -t btrfs -o compress=zstd,subvol=root "$MY_ROOT" /mnt
mkdir /mnt/home
mount -t btrfs -o compress=zstd,subvol=home "$MY_ROOT" /mnt/home
fi
mkswap "$MY_SWAP"
mkdir /mnt/boot
mount "$PART1" /mnt/boot
case $(grep vendor /proc/cpuinfo) in
*"Intel"*)
ucode="intel-ucode"
;;
*"Amd"*)
ucode="amd-ucode"
;;
esac
# Install base system and kernel
basestrap /mnt base base-devel "$MY_INIT" elogind-"$MY_INIT" "$fs_pkgs" efibootmgr grub "$ucode" dhcpcd wpa_supplicant connman-"$MY_INIT"
basestrap /mnt linux linux-firmware linux-headers mkinitcpio
fstabgen -U /mnt >/mnt/etc/fstab