2021-05-14 14:06:20 -04:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
|
2021-08-09 10:44:29 -04:00
|
|
|
ask_root() {
|
|
|
|
if [ "$(whoami)" != "root" ]; then
|
|
|
|
echo "Please run as root."
|
|
|
|
exit 1
|
2021-05-14 14:06:20 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-08-09 10:44:29 -04:00
|
|
|
quiet() {
|
|
|
|
local DUMMY
|
|
|
|
set +e
|
|
|
|
DUMMY=$($@ 2>&1 > /dev/null)
|
|
|
|
set -e
|
2021-05-14 14:06:20 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 10:44:29 -04:00
|
|
|
#ask_root
|
2021-05-14 14:06:20 -04:00
|
|
|
|
2021-08-09 10:44:29 -04:00
|
|
|
DISTRO=$(lsb_release -is)
|
|
|
|
INIT_SYS=$(basename $(readlink /bin/init))
|
2021-05-14 14:06:20 -04:00
|
|
|
|
2021-08-09 10:44:29 -04:00
|
|
|
quiet ls /sys/firmware/efi/efivars
|
|
|
|
[ $? -eq 0 ] && UEFI=1 || UEFI=0
|
2021-05-15 17:55:45 -04:00
|
|
|
|
2021-08-09 10:44:29 -04:00
|
|
|
AVAILABLE_PLATFORMS='Artix (OpenRC)\n'
|
|
|
|
readonly AVAILABLE_PLATFORMS
|
2021-05-15 17:55:45 -04:00
|
|
|
|
|
|
|
install() {
|
|
|
|
echo -n "Installing $1..."
|
|
|
|
pacman -Sq --needed --noconfirm $1 2>&1 > /dev/null
|
|
|
|
echo "done"
|
|
|
|
}
|
|
|
|
|
|
|
|
prompt() {
|
2021-08-09 10:44:29 -04:00
|
|
|
echo -n "$1 [Y/n] "
|
|
|
|
[ $NO_CONFIRM ] && echo "y" && return 1
|
2021-05-15 17:55:45 -04:00
|
|
|
read ans
|
|
|
|
case $ans in
|
2021-08-09 10:44:29 -04:00
|
|
|
n|N) return 0 ;;
|
|
|
|
*) return 1 ;;
|
2021-05-15 17:55:45 -04:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2021-08-09 10:44:29 -04:00
|
|
|
prompt_drive() {
|
|
|
|
local DRIVES="$(lsblk -pno NAME,TYPE,MODEL | awk 'BEGIN {count=1} $1 ~ /^\// {
|
|
|
|
if ($2 == "disk") {printf("%i'")"' %s \"", count, $1); for(i=3;i<NF;i++) printf("%s ", $i); printf("%s\"\n", $NF); count++ } }')"
|
|
|
|
echo "Available drives:"
|
|
|
|
printf " %-12s %s\n" "DISK" "IDENTIFIER"
|
|
|
|
echo -e "$DRIVES"
|
|
|
|
echo -n "Choose drive to install $DISTRO into (WARNING: it will be repartitioned and wiped out) (default=1): "
|
|
|
|
local drive
|
|
|
|
read drive
|
|
|
|
|
|
|
|
[ -z "$drive" ] && drive=1
|
|
|
|
DRIVE_TARGET=$(echo -e "$DRIVES" | awk '$1 ~ /^'$drive'\)$/ { print $2 }')
|
|
|
|
if [ -z "$DRIVE_TARGET" ]; then
|
|
|
|
echo "Invalid target"
|
|
|
|
exit 1
|
2021-05-15 19:25:56 -04:00
|
|
|
fi
|
2021-08-05 21:29:58 -04:00
|
|
|
|
2021-08-09 10:44:29 -04:00
|
|
|
set +e
|
|
|
|
prompt "Installing for $DRIVE_TARGET. Confirm?"
|
|
|
|
[ $? -eq 0 ] && exit 0
|
2021-08-05 21:29:58 -04:00
|
|
|
set -e
|
|
|
|
}
|
|
|
|
|
2021-08-09 10:44:29 -04:00
|
|
|
partition() {
|
|
|
|
prompt_drive
|
2021-08-05 21:29:58 -04:00
|
|
|
|
2021-08-09 10:44:29 -04:00
|
|
|
echo -n "Partitioning drive..."
|
|
|
|
parted --script "$DRIVE_TARGET" \
|
|
|
|
mklabel gpt \
|
|
|
|
mkpart swap ext4 0MiB 4GiB \
|
|
|
|
mkpart boot ext4 4GiB 5Gib \
|
|
|
|
mkpart root ext4 5GiB 100%
|
2021-08-05 21:29:58 -04:00
|
|
|
echo "done"
|
|
|
|
|
2021-08-09 10:44:29 -04:00
|
|
|
echo -n "Configuring SWAP partition..."
|
|
|
|
quiet mkswap -L SWAP "$DRIVE_TARGET"1
|
|
|
|
quiet swapon "$DRIVE_TARGET"1
|
2021-05-15 19:25:56 -04:00
|
|
|
echo "done"
|
|
|
|
|
2021-08-09 10:44:29 -04:00
|
|
|
echo -n "Configuring ROOT partition..."
|
|
|
|
quiet mkfs.ext4 -L ROOT "$DRIVE_TARGET"3
|
|
|
|
quiet mount "$DRIVE_TARGET"3 /mnt
|
2021-05-15 19:25:56 -04:00
|
|
|
echo "done"
|
|
|
|
|
2021-08-09 10:44:29 -04:00
|
|
|
echo -n "Configuring BOOT partition..."
|
|
|
|
if [ $UEFI -eq 1 ]; then
|
|
|
|
quiet mkfs.fat32 "$DRIVE_TARGET"2
|
|
|
|
fatlabel "$DRIVE_TARGET"2 BOOT
|
|
|
|
else
|
|
|
|
quiet mkfs.ext4 -L BOOT "$DRIVE_TARGET"2
|
|
|
|
fi
|
|
|
|
mkdir /mnt/boot
|
|
|
|
mount "$DRIVE_TARGET"2 /mnt/boot
|
2021-05-15 17:55:45 -04:00
|
|
|
echo "done"
|
2021-05-14 14:06:20 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 10:44:29 -04:00
|
|
|
main() {
|
|
|
|
prompt_drive
|
|
|
|
echo "$DRIVE_TARGET"
|
|
|
|
}
|
2021-05-15 17:55:45 -04:00
|
|
|
|
2021-08-09 10:44:29 -04:00
|
|
|
main
|