2023-06-13 14:25:23 +02:00
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
function press_any_key {
|
2023-06-14 10:00:26 +02:00
|
|
|
|
echo "Press any key to continue or Ctrl+c to abort..."
|
2023-06-13 14:25:23 +02:00
|
|
|
|
read -n1 DISCARD_ME
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function are_you_really_really_sure {
|
|
|
|
|
echo "Enter the following to continue: $1"
|
2023-06-14 10:00:26 +02:00
|
|
|
|
read -p "> " DISCARD_ME
|
2023-06-13 14:25:23 +02:00
|
|
|
|
if [ "$1" = "$DISCARD_ME" ]; then
|
|
|
|
|
return 0
|
|
|
|
|
else
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-14 09:47:23 +02:00
|
|
|
|
function yesno {
|
|
|
|
|
unset DISCARD_ME
|
|
|
|
|
while [ -z "$DISCARD_ME" ]; do
|
2023-06-14 10:00:26 +02:00
|
|
|
|
read -p "[y/n] " -n1 DISCARD_ME
|
2023-06-14 09:47:23 +02:00
|
|
|
|
case "$DISCARD_ME" in
|
|
|
|
|
y)
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
n)
|
|
|
|
|
return 1
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo " Please enter y for yes or n for no."
|
|
|
|
|
unset DISCARD_ME
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-13 14:25:23 +02:00
|
|
|
|
clear
|
|
|
|
|
echo "
|
2023-06-14 09:47:23 +02:00
|
|
|
|
This script will now download and install Void Linux on your USB stick.
|
|
|
|
|
Any data that is currently on the stick will be lost and it won’t be
|
|
|
|
|
usable from Windows or MacOS.
|
2023-06-13 14:25:23 +02:00
|
|
|
|
|
2023-06-14 09:47:23 +02:00
|
|
|
|
Before we begin, the following tools need to be installed:
|
2023-06-13 14:25:23 +02:00
|
|
|
|
- xmirror
|
|
|
|
|
- squashfs-tools"
|
|
|
|
|
press_any_key
|
|
|
|
|
|
|
|
|
|
xbps-install --sync
|
|
|
|
|
xbps-install --yes --update xbps
|
|
|
|
|
xbps-install --yes xmirror squashfs-tools
|
|
|
|
|
|
|
|
|
|
#TODO: If going down the path of extracting routines from void-installer and
|
|
|
|
|
# xmirror, that should be done here.
|
|
|
|
|
|
|
|
|
|
#TODO: Select keyboard layout
|
2023-06-14 07:07:17 +02:00
|
|
|
|
KBD_LAYOUT="de-latin1"
|
2023-06-13 14:25:23 +02:00
|
|
|
|
|
|
|
|
|
clear
|
|
|
|
|
echo "Select the USB stick to install to (NAME column below)...
|
|
|
|
|
"
|
2023-06-14 09:47:23 +02:00
|
|
|
|
# exclude loop devices
|
|
|
|
|
lsblk --exclude 7 --nodeps --output NAME,SIZE,MODEL
|
2023-06-13 14:25:23 +02:00
|
|
|
|
echo ""
|
|
|
|
|
read -p "> " TARGET_DISK
|
|
|
|
|
|
|
|
|
|
while [ ! -b "/dev/$TARGET_DISK" ]; do
|
2023-06-14 09:47:23 +02:00
|
|
|
|
lsblk --exclude 7 --nodeps --output NAME,SIZE,MODEL
|
2023-06-13 14:25:23 +02:00
|
|
|
|
echo "$TARGET_DISK is not a valid device!"
|
|
|
|
|
read -p "> " TARGET_DISK
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
clear
|
|
|
|
|
echo "Selected device:"
|
|
|
|
|
lsblk --output NAME,SIZE,MODEL,LABEL,FSTYPE "/dev/$TARGET_DISK"
|
|
|
|
|
echo "
|
|
|
|
|
WARNING: The selected device will be wiped, partitioned, and formatted.
|
|
|
|
|
ALL DATA ON IT WILL BE LOST PERMANENTLY.
|
|
|
|
|
It will not be usable with Windows or MacOS while holding Void.
|
|
|
|
|
"
|
|
|
|
|
if are_you_really_really_sure "Yes, erase it."; then
|
|
|
|
|
true
|
|
|
|
|
else
|
|
|
|
|
echo "Aborting."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# new GPT
|
|
|
|
|
# 2M BIOS GRUB
|
|
|
|
|
# 268M ESP
|
|
|
|
|
# 1G boot
|
|
|
|
|
# everything else one big partition
|
|
|
|
|
echo "g
|
|
|
|
|
n
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+2M
|
|
|
|
|
n
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+268M
|
|
|
|
|
n
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+1G
|
|
|
|
|
n
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t
|
|
|
|
|
1
|
|
|
|
|
4
|
|
|
|
|
t
|
|
|
|
|
2
|
|
|
|
|
1
|
|
|
|
|
t
|
|
|
|
|
3
|
|
|
|
|
136
|
|
|
|
|
t
|
|
|
|
|
4
|
|
|
|
|
20
|
|
|
|
|
w" | fdisk --wipe always --wipe-partitions always "/dev/$TARGET_DISK"
|
|
|
|
|
TARGET_PART_BIOS="$(lsblk --raw --noheadings --output PATH "/dev/$TARGET_DISK" | sed -n '2p')"
|
|
|
|
|
TARGET_PART_EFI="$(lsblk --raw --noheadings --output PATH "/dev/$TARGET_DISK" | sed -n '3p')"
|
|
|
|
|
TARGET_PART_BOOT="$(lsblk --raw --noheadings --output PATH "/dev/$TARGET_DISK" | sed -n '4p')"
|
|
|
|
|
TARGET_PART_BIG="$(lsblk --raw --noheadings --output PATH "/dev/$TARGET_DISK" | sed -n '5p')"
|
|
|
|
|
|
2023-06-14 07:14:17 +02:00
|
|
|
|
mkfs.vfat -F32 -n "EFIBOOT" "$TARGET_PART_EFI"
|
|
|
|
|
mkfs.f2fs -f -l "boot" "$TARGET_PART_BOOT"
|
|
|
|
|
mkfs.f2fs -f -l "container" "$TARGET_PART_BIG"
|
2023-06-13 14:25:23 +02:00
|
|
|
|
|
|
|
|
|
mkdir -p /mnt/target
|
|
|
|
|
mount -t tmpfs -o size=3g tmpfs /mnt/target
|
|
|
|
|
#TODO don't use default permissions for tmpfs
|
|
|
|
|
mkdir /mnt/target/boot
|
|
|
|
|
mount "$TARGET_PART_BOOT" /mnt/target/boot
|
|
|
|
|
mkdir /mnt/target/boot/efi
|
|
|
|
|
mount "$TARGET_PART_EFI" /mnt/target/boot/efi
|
2023-06-14 07:14:17 +02:00
|
|
|
|
mkdir /mnt/target/container
|
|
|
|
|
mount "$TARGET_PART_BIG" /mnt/target/container
|
2023-06-13 14:25:23 +02:00
|
|
|
|
mkdir /mnt/target/home
|
2023-06-14 07:14:17 +02:00
|
|
|
|
mkdir /mnt/target/container/home
|
|
|
|
|
mount --bind /mnt/target/container/home /mnt/target/home
|
2023-06-13 14:25:23 +02:00
|
|
|
|
|
|
|
|
|
clear
|
|
|
|
|
echo "Storage is now prepared and ready for installation.
|
|
|
|
|
|
|
|
|
|
You need to select a download mirror for Void next.
|
2023-06-14 09:47:23 +02:00
|
|
|
|
The script will launch xmirror on the host/live system and determine
|
|
|
|
|
the chosen mirror from the config file it generates.
|
|
|
|
|
"
|
2023-06-13 14:25:23 +02:00
|
|
|
|
press_any_key
|
|
|
|
|
|
|
|
|
|
xmirror
|
|
|
|
|
TARGET_MIRROR="$(sed 's/repository=//;s|/musl$||' /etc/xbps.d/00-repository-main.conf)"
|
|
|
|
|
|
|
|
|
|
#TODO: select installation type
|
2023-06-14 10:16:11 +02:00
|
|
|
|
TARGET_TYPE="x86_64"
|
2023-06-13 14:25:23 +02:00
|
|
|
|
|
|
|
|
|
if grep "musl" <<< "$TARGET_TYPE"; then
|
|
|
|
|
TARGET_MIRROR="$TARGET_MIRROR/musl"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
mkdir -p /mnt/target/var/db/xbps/keys
|
|
|
|
|
cp /var/db/xbps/keys/* /mnt/target/var/db/xbps/keys/
|
|
|
|
|
|
2023-06-14 09:47:23 +02:00
|
|
|
|
XBPS_ARCH="$TARGET_TYPE" xbps-install --yes --sync --rootdir /mnt/target --repository "$TARGET_MIRROR" \
|
2023-06-13 14:25:23 +02:00
|
|
|
|
linux bash shadow f2fs-tools dosfstools dbus NetworkManager iana-etc \
|
|
|
|
|
iw wpa_supplicant util-linux which tar man-pages iproute2 iputils \
|
|
|
|
|
wifi-firmware traceroute grep gzip file sed gawk less coreutils findutils \
|
|
|
|
|
diffutils pciutils usbutils tzdata base-files ncurses mdocml procps-ng \
|
|
|
|
|
kbd xbps sudo ethtool kmod eudev runit-void removed-packages nano acpid \
|
|
|
|
|
squashfs-tools
|
2023-06-14 06:04:17 +02:00
|
|
|
|
|
|
|
|
|
echo "repository=$TARGET_MIRROR" > /mnt/target/etc/xbps.d/00-repository-main.conf
|
|
|
|
|
|
|
|
|
|
echo "%wheel ALL=(ALL:ALL) ALL" > /mnt/target/etc/sudoers.d/wheel_as_sudo_group.conf
|
|
|
|
|
|
2023-06-14 07:07:17 +02:00
|
|
|
|
# TODO: add overlayfs scripts (bootup and shutdown)
|
|
|
|
|
|
|
|
|
|
echo "# See fstab(5).
|
|
|
|
|
# <device> <mount point> <fstype> <options> <dump> <pass>
|
|
|
|
|
|
2023-06-14 07:14:17 +02:00
|
|
|
|
# / and /container are mounted by a script in initramfs
|
2023-06-14 07:07:17 +02:00
|
|
|
|
# TODO: add script path
|
|
|
|
|
|
|
|
|
|
UUID=$(blkid --output value --match-tag UUID $TARGET_PART_BOOT) /boot f2fs defaults,nodev,nosuid 0 2
|
|
|
|
|
UUID=$(blkid --output value --match-tag UUID $TARGET_PART_EFI) /boot/efi vfat defaults 0 2
|
2023-06-14 07:14:17 +02:00
|
|
|
|
/container/home /home none bind 0 0
|
2023-06-14 07:07:17 +02:00
|
|
|
|
" > /mnt/target/etc/fstab
|
|
|
|
|
|
2023-06-14 09:47:23 +02:00
|
|
|
|
if grep "#KEYMAP=" /mnt/target/etc/rc.conf; then
|
2023-06-14 10:00:26 +02:00
|
|
|
|
sed -i -e 's/#KEYMAP=.*/KEYMAP="'"$KBD_LAYOUT"'"/' /mnt/target/etc/rc.conf
|
2023-06-14 09:47:23 +02:00
|
|
|
|
else
|
|
|
|
|
clear
|
|
|
|
|
echo "WARNING: Could not locate the keymap setting in rc.conf."
|
|
|
|
|
echo "The script will attempt to add one."
|
|
|
|
|
echo ""
|
|
|
|
|
press_any_key
|
|
|
|
|
echo "" >> /mnt/target/etc/rc.conf
|
|
|
|
|
echo "# Install script could not find keymap setting, adding one here." >> /mnt/target/etc/rc.conf
|
|
|
|
|
echo "KEYMAP=\"$KBD_LAYOUT\"" >> /mnt/target/etc/rc.conf
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
#TODO timezone
|
|
|
|
|
|
|
|
|
|
clear
|
|
|
|
|
echo "Set hardware clock to UTC?
|
|
|
|
|
|
|
|
|
|
Most Unix/Linux systems set the clock in your computer to UTC and add
|
|
|
|
|
the time zone on-the-fly. If you use Windows, you will want to answer no here.
|
|
|
|
|
"
|
|
|
|
|
if yesno; then
|
|
|
|
|
if grep "#HARDWARECLOCK=" /mnt/target/etc/rc.conf; then
|
2023-06-14 10:00:26 +02:00
|
|
|
|
sed -i -e 's/#HARDWARECLOCK=.*/HARDWARECLOCK="UTC"/' /mnt/target/etc/rc.conf
|
2023-06-14 09:47:23 +02:00
|
|
|
|
else
|
|
|
|
|
clear
|
|
|
|
|
echo "WARNING: Could not locate the hardwareclock setting in rc.conf."
|
|
|
|
|
echo "The script will attempt to add one."
|
|
|
|
|
echo ""
|
|
|
|
|
press_any_key
|
|
|
|
|
echo "" >> /mnt/target/etc/rc.conf
|
|
|
|
|
echo "# Install script could not find hardwareclock setting, adding one here." >> /mnt/target/etc/rc.conf
|
|
|
|
|
echo 'HARDWARECLOCK="UTC"' >> /mnt/target/etc/rc.conf
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
if grep "#HARDWARECLOCK=" /mnt/target/etc/rc.conf; then
|
2023-06-14 10:00:26 +02:00
|
|
|
|
sed -i -e 's/#HARDWARECLOCK=.*/HARDWARECLOCK="localtime"/' /mnt/target/etc/rc.conf
|
2023-06-14 09:47:23 +02:00
|
|
|
|
else
|
|
|
|
|
clear
|
|
|
|
|
echo "WARNING: Could not locate the hardwareclock setting in rc.conf."
|
|
|
|
|
echo "The script will attempt to add one."
|
|
|
|
|
echo ""
|
|
|
|
|
press_any_key
|
|
|
|
|
echo "" >> /mnt/target/etc/rc.conf
|
|
|
|
|
echo "# Install script could not find hardwareclock setting, adding one here." >> /mnt/target/etc/rc.conf
|
|
|
|
|
echo 'HARDWARECLOCK="localtime"' >> /mnt/target/etc/rc.conf
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
clear
|
|
|
|
|
echo "Do you want to set a hostname?
|
|
|
|
|
|
|
|
|
|
This is equivalent to giving a name to your computer - except it's a system
|
|
|
|
|
on a USB drive.
|
|
|
|
|
|
|
|
|
|
If you leave this empty, it will be set to void-usb.
|
|
|
|
|
Allowed characters are a-zA-Z0-9 (and - in the middle).
|
|
|
|
|
"
|
|
|
|
|
while [ -z "$TARGET_HOSTNAME" ]; do
|
|
|
|
|
read -p "> " TARGET_HOSTNAME
|
|
|
|
|
if [ -z "$TARGET_HOSTNAME" ]; then
|
|
|
|
|
TARGET_HOSTNAME="void-usb"
|
|
|
|
|
else
|
|
|
|
|
if grep -e "^[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]$" -e "^[a-zA-Z0-9]*$" <<< "$TARGET_HOSTNAME" > /dev/null 2>&1; then
|
2023-06-14 10:16:11 +02:00
|
|
|
|
true
|
2023-06-14 09:47:23 +02:00
|
|
|
|
else
|
|
|
|
|
echo "Allowed characters are a-zA-Z0-9 (and - in the middle)."
|
|
|
|
|
unset TARGET_HOSTNAME
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
2023-06-14 10:16:11 +02:00
|
|
|
|
echo "$TARGET_HOSTNAME" > /mnt/target/etc/hostname
|
2023-06-14 09:47:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-14 07:07:17 +02:00
|
|
|
|
|
|
|
|
|
#
|