2023-06-13 14:25:23 +02:00
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
2023-06-30 12:35:37 +02:00
|
|
|
|
LOGFILE=/tmp/void-usb-install-log
|
2023-07-02 20:52:21 +02:00
|
|
|
|
GIT_REPO_BASE="https://lostcave.ddnss.de/git/BodgeMaster/void-minecraft-usb/raw/branch/master"
|
2023-06-30 12:35:37 +02:00
|
|
|
|
|
2023-06-13 14:25:23 +02:00
|
|
|
|
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
|
2023-06-30 12:48:17 +02:00
|
|
|
|
echo ""
|
2023-06-13 14:25:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-30 12:48:17 +02:00
|
|
|
|
echo ""
|
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)
|
2023-07-14 20:58:05 +02:00
|
|
|
|
echo ""
|
2023-06-14 09:47:23 +02:00
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
n)
|
2023-07-14 20:58:05 +02:00
|
|
|
|
echo ""
|
2023-06-14 09:47:23 +02:00
|
|
|
|
return 1
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo " Please enter y for yes or n for no."
|
|
|
|
|
unset DISCARD_ME
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-20 13:16:00 +02:00
|
|
|
|
function run_in_target {
|
2023-06-28 19:55:09 +02:00
|
|
|
|
echo "$@" | chroot /mnt/target sh
|
2023-06-20 13:16:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-13 14:25:23 +02:00
|
|
|
|
clear
|
2023-06-30 12:35:37 +02:00
|
|
|
|
touch $LOGFILE
|
|
|
|
|
|
2023-07-03 14:08:11 +02:00
|
|
|
|
if [ ! "$(id -u)" -eq 0 ]; then
|
|
|
|
|
echo "Must be root to run this script!"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2023-07-14 20:50:12 +02:00
|
|
|
|
if ping -c2 repo-default.voidlinux.org >> $LOGFILE 2>&1; then
|
2023-07-03 14:08:11 +02:00
|
|
|
|
:
|
|
|
|
|
else
|
|
|
|
|
echo "An internet connection is required to run this script."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2023-06-30 12:35:37 +02:00
|
|
|
|
|
2023-06-13 14:25:23 +02:00
|
|
|
|
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-20 19:08:18 +02:00
|
|
|
|
Before we begin, the following packages need to be installed (if not installed already):
|
2023-06-13 14:25:23 +02:00
|
|
|
|
- xmirror
|
2023-06-20 19:08:18 +02:00
|
|
|
|
- wget
|
2023-06-30 12:35:37 +02:00
|
|
|
|
"
|
2023-06-13 14:25:23 +02:00
|
|
|
|
press_any_key
|
|
|
|
|
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo -n "Ensuring that XBPS is up-to-date... "
|
|
|
|
|
xbps-install --yes --sync --update xbps >> $LOGFILE 2>&1
|
|
|
|
|
echo "done"
|
|
|
|
|
echo -n "Installing xmirror, squashfs-tools, wget... "
|
2023-07-03 14:09:32 +02:00
|
|
|
|
xbps-install --yes xmirror wget >> $LOGFILE 2>&1
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo "done"
|
2023-06-13 14:25:23 +02:00
|
|
|
|
|
2023-06-30 12:35:37 +02:00
|
|
|
|
#TODO: If going down the path of extracting routines from void-installer, that should be done here
|
2023-06-13 14:25:23 +02:00
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
2023-06-30 13:22:20 +02:00
|
|
|
|
if grep "$TARGET_DISK" /proc/mounts >> $LOGFILE 2>&1; then
|
|
|
|
|
echo "The device seems to be mounted. Unmount?"
|
|
|
|
|
if yesno; then
|
|
|
|
|
echo -n "Attempting to unmount... "
|
|
|
|
|
readarray -t MOUNTPOINTS <<< "$(findmnt --raw --noheadings --output SOURCE,TARGET | grep "$TARGET_DISK" | sed 's/^[^ ]* //')"
|
|
|
|
|
for I in ${!MOUNTPOINTS[@]}; do
|
|
|
|
|
umount -R "${MOUNTPOINTS[$I]}" >> $LOGFILE 2>&1
|
|
|
|
|
done
|
|
|
|
|
if grep "$TARGET_DISK" /proc/mounts >> $LOGFILE 2>&1; then
|
|
|
|
|
echo "failed"
|
|
|
|
|
echo "It seems the device is still mounted. Installation cannot continue."
|
|
|
|
|
exit 1
|
|
|
|
|
else
|
|
|
|
|
echo "done"
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
echo "Aborting."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo -n "Wiping and partitioning storage... "
|
2023-06-13 14:25:23 +02:00
|
|
|
|
# new GPT
|
|
|
|
|
# 2M BIOS GRUB
|
2023-07-14 23:09:18 +02:00
|
|
|
|
# 66592 sectors ESP (first sector + 66591 sectors, the minimum to format FAT32 with default settings)
|
2023-06-13 14:25:23 +02:00
|
|
|
|
# everything else one big partition
|
|
|
|
|
echo "g
|
|
|
|
|
n
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+2M
|
|
|
|
|
n
|
|
|
|
|
|
|
|
|
|
|
2023-07-14 23:09:18 +02:00
|
|
|
|
+66591
|
2023-06-13 14:25:23 +02:00
|
|
|
|
n
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t
|
|
|
|
|
1
|
|
|
|
|
4
|
|
|
|
|
t
|
|
|
|
|
2
|
|
|
|
|
1
|
|
|
|
|
t
|
|
|
|
|
3
|
|
|
|
|
20
|
2023-06-30 12:35:37 +02:00
|
|
|
|
w" | fdisk --wipe always --wipe-partitions always "/dev/$TARGET_DISK" >> $LOGFILE 2>&1
|
2023-06-13 14:25:23 +02:00
|
|
|
|
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')"
|
2023-06-28 22:59:09 +02:00
|
|
|
|
TARGET_PART_BIG="$(lsblk --raw --noheadings --output PATH "/dev/$TARGET_DISK" | sed -n '4p')"
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo "done"
|
2023-06-13 14:25:23 +02:00
|
|
|
|
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo -n "Formatting partitions... "
|
|
|
|
|
mkfs.vfat -F32 -n "EFIBOOT" "$TARGET_PART_EFI" >> $LOGFILE 2>&1
|
|
|
|
|
mkfs.f2fs -f -l "container" "$TARGET_PART_BIG" >> $LOGFILE 2>&1
|
|
|
|
|
echo "done"
|
2023-06-13 14:25:23 +02:00
|
|
|
|
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo -n "Mounting partitions and virtual file systems... "
|
|
|
|
|
mkdir -p /mnt/target >> $LOGFILE 2>&1
|
|
|
|
|
mount -t tmpfs -o size=3g,mode=755 tmpfs /mnt/target >> $LOGFILE 2>&1
|
2023-06-28 19:55:09 +02:00
|
|
|
|
|
|
|
|
|
# used for chroot later
|
2023-06-30 12:35:37 +02:00
|
|
|
|
mkdir /mnt/target/run >> $LOGFILE 2>&1
|
|
|
|
|
mount --rbind /run /mnt/target/run >> $LOGFILE 2>&1
|
|
|
|
|
mkdir /mnt/target/proc >> $LOGFILE 2>&1
|
|
|
|
|
mount --rbind /proc /mnt/target/proc >> $LOGFILE 2>&1
|
|
|
|
|
mkdir /mnt/target/sys >> $LOGFILE 2>&1
|
|
|
|
|
mount --rbind /sys /mnt/target/sys >> $LOGFILE 2>&1
|
|
|
|
|
mkdir /mnt/target/dev >> $LOGFILE 2>&1
|
|
|
|
|
mount --rbind /dev /mnt/target/dev >> $LOGFILE 2>&1
|
2023-06-28 19:55:09 +02:00
|
|
|
|
|
|
|
|
|
# actual storage
|
2023-06-30 12:35:37 +02:00
|
|
|
|
mkdir -p /mnt/target/run/void-usb/container >> $LOGFILE 2>&1
|
|
|
|
|
mount "$TARGET_PART_BIG" /mnt/target/run/void-usb/container >> $LOGFILE 2>&1
|
|
|
|
|
mkdir /mnt/target/boot >> $LOGFILE 2>&1
|
|
|
|
|
mkdir /mnt/target/run/void-usb/container/boot >> $LOGFILE 2>&1
|
|
|
|
|
mount --bind /mnt/target/run/void-usb/container/boot /mnt/target/boot >> $LOGFILE 2>&1
|
|
|
|
|
mkdir /mnt/target/boot/efi >> $LOGFILE 2>&1
|
|
|
|
|
mount "$TARGET_PART_EFI" /mnt/target/boot/efi >> $LOGFILE 2>&1
|
|
|
|
|
mkdir /mnt/target/home >> $LOGFILE 2>&1
|
|
|
|
|
mkdir /mnt/target/run/void-usb/container/home >> $LOGFILE 2>&1
|
|
|
|
|
mount --bind /mnt/target/run/void-usb/container/home /mnt/target/home >> $LOGFILE 2>&1
|
|
|
|
|
echo "done"
|
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
|
2023-06-21 07:08:00 +02:00
|
|
|
|
#TODO: also remove CPU architecture
|
2023-06-13 14:25:23 +02:00
|
|
|
|
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
|
|
|
|
|
2023-06-21 07:08:00 +02:00
|
|
|
|
#TODO: also add CPU architecture
|
2023-06-13 14:25:23 +02:00
|
|
|
|
if grep "musl" <<< "$TARGET_TYPE"; then
|
|
|
|
|
TARGET_MIRROR="$TARGET_MIRROR/musl"
|
|
|
|
|
fi
|
|
|
|
|
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo -n "Copying repository keys... "
|
|
|
|
|
mkdir -p /mnt/target/var/db/xbps/keys >> $LOGFILE 2>&1
|
|
|
|
|
cp /var/db/xbps/keys/* /mnt/target/var/db/xbps/keys/ >> $LOGFILE 2>&1
|
|
|
|
|
echo "done"
|
2023-06-13 14:25:23 +02:00
|
|
|
|
|
2023-07-02 20:52:21 +02:00
|
|
|
|
clear
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo "The next step is installing packages for base system components.
|
|
|
|
|
Depending on your internet connection, your USB stick, and the phase of the moon, this may take a while.
|
|
|
|
|
The XBPS log will be displayed for this step.
|
|
|
|
|
"
|
|
|
|
|
press_any_key
|
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 \
|
2023-06-30 12:35:37 +02:00
|
|
|
|
squashfs-tools grub grub-i386-efi grub-x86_64-efi dracut xz 2>&1 | tee --append $LOGFILE
|
|
|
|
|
echo ""
|
2023-06-14 06:04:17 +02:00
|
|
|
|
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo "Adding mirror configuration."
|
2023-06-14 06:04:17 +02:00
|
|
|
|
echo "repository=$TARGET_MIRROR" > /mnt/target/etc/xbps.d/00-repository-main.conf
|
|
|
|
|
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo "Adding sudo configuration."
|
2023-07-14 20:50:12 +02:00
|
|
|
|
echo "%wheel ALL=(ALL:ALL) ALL" > /mnt/target/etc/sudoers.d/wheel_as_sudo_group
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo "Disabling root password."
|
|
|
|
|
run_in_target passwd --lock root
|
2023-06-14 06:04:17 +02:00
|
|
|
|
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo "Adding dracut configuration."
|
2023-06-28 07:46:48 +02:00
|
|
|
|
echo '# Void USB dracut configuration
|
|
|
|
|
|
|
|
|
|
hostonly="no"
|
|
|
|
|
compress="xz"
|
2023-06-28 13:02:25 +02:00
|
|
|
|
|
|
|
|
|
add_dracutmodules+=" void-usb "
|
2023-06-28 14:04:07 +02:00
|
|
|
|
omit_dracutmodules+=" nvdimm resume "' > /mnt/target/etc/dracut.conf.d/99-void-usb.conf
|
2023-06-28 07:46:48 +02:00
|
|
|
|
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo -n "Adding dracut module void-usb... "
|
|
|
|
|
mkdir -p /mnt/target/lib/dracut/modules.d/90void-usb >> $LOGFILE 2>&1
|
|
|
|
|
chmod 755 /mnt/target/lib/dracut/modules.d/90void-usb >> $LOGFILE 2>&1
|
2023-07-02 20:52:21 +02:00
|
|
|
|
wget --output-document=/mnt/target/lib/dracut/modules.d/90void-usb/module-setup.sh "$GIT_REPO_BASE/dracut-modules/90void-usb/module-setup.sh" >> $LOGFILE 2>&1
|
2023-06-30 12:35:37 +02:00
|
|
|
|
chmod 744 /mnt/target/lib/dracut/modules.d/90void-usb/module-setup.sh >> $LOGFILE 2>&1
|
2023-07-02 20:52:21 +02:00
|
|
|
|
wget --output-document=/mnt/target/lib/dracut/modules.d/90void-usb/create-loop0.sh "$GIT_REPO_BASE/dracut-modules/90void-usb/create-loop0.sh" >> $LOGFILE 2>&1
|
2023-06-30 12:35:37 +02:00
|
|
|
|
chmod 744 /mnt/target/lib/dracut/modules.d/90void-usb/create-loop0.sh >> $LOGFILE 2>&1
|
2023-07-02 20:52:21 +02:00
|
|
|
|
wget --output-document=/mnt/target/lib/dracut/modules.d/90void-usb/squashfs-img.sh "$GIT_REPO_BASE/dracut-modules/90void-usb/squashfs-img.sh" >> $LOGFILE 2>&1
|
2023-06-30 12:35:37 +02:00
|
|
|
|
chmod 744 /mnt/target/lib/dracut/modules.d/90void-usb/squashfs-img.sh >> $LOGFILE 2>&1
|
2023-07-02 20:52:21 +02:00
|
|
|
|
wget --output-document=/mnt/target/lib/dracut/modules.d/90void-usb/overlay.sh "$GIT_REPO_BASE/dracut-modules/90void-usb/overlay.sh" >> $LOGFILE 2>&1
|
2023-06-30 12:35:37 +02:00
|
|
|
|
chmod 744 /mnt/target/lib/dracut/modules.d/90void-usb/overlay.sh >> $LOGFILE 2>&1
|
|
|
|
|
echo "done"
|
|
|
|
|
|
2023-07-14 21:27:57 +02:00
|
|
|
|
echo -n "Adding system-image helper... "
|
2023-06-30 12:35:37 +02:00
|
|
|
|
mkdir -p /mnt/target/opt/void-usb >> $LOGFILE 2>&1
|
|
|
|
|
chmod 755 /mnt/target/opt/void-usb >> $LOGFILE 2>&1
|
2023-07-14 21:27:57 +02:00
|
|
|
|
wget --output-document=/mnt/target/opt/void-usb/system-image "$GIT_REPO_BASE/opt/system-image" >> $LOGFILE 2>&1
|
|
|
|
|
chmod 744 /mnt/target/opt/void-usb/system-image >> $LOGFILE 2>&1
|
2023-06-26 17:04:28 +02:00
|
|
|
|
echo "
|
2023-07-14 21:27:57 +02:00
|
|
|
|
/opt/void-usb/system-image" >> /mnt/target/etc/rc.shutdown
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo "done"
|
2023-06-26 17:04:28 +02:00
|
|
|
|
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo "Adding fstab."
|
2023-06-14 07:07:17 +02:00
|
|
|
|
echo "# See fstab(5).
|
|
|
|
|
# <device> <mount point> <fstype> <options> <dump> <pass>
|
|
|
|
|
|
2023-06-28 21:28:01 +02:00
|
|
|
|
# /run/void-usb/container, /run/void-usb/overlay, and / are mounted by scripts in initramfs
|
2023-06-14 07:07:17 +02:00
|
|
|
|
|
2023-06-28 22:59:09 +02:00
|
|
|
|
/run/void-usb/container/boot /boot none bind 0 0
|
2023-06-28 19:55:09 +02:00
|
|
|
|
/run/void-usb/container/home /home none bind 0 0
|
2023-06-29 00:44:32 +02:00
|
|
|
|
UUID=$(blkid --output value --match-tag UUID $TARGET_PART_EFI) /boot/efi vfat defaults,fmask=0077,dmask=0077 0 2
|
2023-06-14 07:07:17 +02:00
|
|
|
|
" > /mnt/target/etc/fstab
|
|
|
|
|
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo "Configuring keyboard layout."
|
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
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo "WARNING: Could not locate the keymap setting in rc.conf." | tee --append $LOGFILE
|
|
|
|
|
echo "The script will attempt to add one." | tee --append $LOGFILE
|
2023-06-14 09:47:23 +02:00
|
|
|
|
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
|
|
|
|
|
|
2023-06-30 12:35:37 +02:00
|
|
|
|
#TODO: Figure out how to configure keyboard for Xorg
|
|
|
|
|
|
2023-06-14 09:47:23 +02:00
|
|
|
|
#TODO timezone
|
|
|
|
|
|
|
|
|
|
clear
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo "Assume that the hardware clock is UTC?
|
2023-06-14 09:47:23 +02:00
|
|
|
|
|
2023-06-30 12:35:37 +02:00
|
|
|
|
Most Unix-like systems set the clock in your computer to UTC and add the time zone
|
|
|
|
|
on-the-fly. Windows on the other hand usually sets the hardware clock to local time.
|
|
|
|
|
|
|
|
|
|
If you want to use this stick on Windows computers, you will most likely want to answer no here.
|
2023-06-14 09:47:23 +02:00
|
|
|
|
"
|
|
|
|
|
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
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo "WARNING: Could not locate the hardwareclock setting in rc.conf." | tee --append $LOGFILE
|
|
|
|
|
echo "The script will attempt to add one." | tee --append $LOGFILE
|
2023-06-14 09:47:23 +02:00
|
|
|
|
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
|
2023-06-30 12:35:37 +02:00
|
|
|
|
echo "WARNING: Could not locate the hardwareclock setting in rc.conf." | tee --append $LOGFILE
|
|
|
|
|
echo "The script will attempt to add one." | tee --append $LOGFILE
|
2023-06-14 09:47:23 +02:00
|
|
|
|
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?
|
|
|
|
|
|
2023-06-30 12:35:37 +02:00
|
|
|
|
This is equivalent to giving a name to your computer - except it's a system on a USB drive.
|
2023-06-14 09:47:23 +02:00
|
|
|
|
|
|
|
|
|
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-30 12:35:37 +02:00
|
|
|
|
clear
|
|
|
|
|
echo -n "Installing bootloader... "
|
|
|
|
|
mkdir /mnt/target/boot/efi/LOADER >> $LOGFILE 2>&1
|
2023-06-20 13:16:39 +02:00
|
|
|
|
echo "GRUB has been deliberately installed to a non-standard location.
|
|
|
|
|
This avoids default kernel hooks breaking the custom config." > /mnt/target/boot/efi/LOADER/README.TXT
|
|
|
|
|
|
|
|
|
|
# no idea if any of these are even necessary/relevant but it can’t hurt...
|
2023-06-27 15:37:50 +02:00
|
|
|
|
TARGET_PRELOAD_GRUB_MODULES="usb usbms uhci ehci ohci part_gpt f2fs ahci ata pata"
|
2023-06-30 12:35:37 +02:00
|
|
|
|
run_in_target grub-install --target=i386-pc --boot-directory=/boot/efi/LOADER --disk-module=native --modules="'$TARGET_PRELOAD_GRUB_MODULES'" "'/dev/$TARGET_DISK'" >> $LOGFILE 2>&1
|
|
|
|
|
run_in_target grub-install --target=i386-efi --boot-directory=/boot/efi/LOADER --disk-module=native --efi-directory=/boot/efi --removable --no-nvram --modules="'$TARGET_PRELOAD_GRUB_MODULES'" "'/dev/$TARGET_DISK'" >> $LOGFILE 2>&1
|
|
|
|
|
run_in_target grub-install --target=x86_64-efi --boot-directory=/boot/efi/LOADER --disk-module=native --efi-directory=/boot/efi --removable --no-nvram --modules="'$TARGET_PRELOAD_GRUB_MODULES'" "'/dev/$TARGET_DISK'" >> $LOGFILE 2>&1
|
|
|
|
|
echo "done"
|
|
|
|
|
|
|
|
|
|
echo -n "Adding grub-config helper... "
|
2023-07-02 20:52:21 +02:00
|
|
|
|
wget --output-document=/mnt/target/opt/void-usb/grub-config "$GIT_REPO_BASE/opt/grub-config" >> $LOGFILE 2>&1
|
2023-06-30 12:35:37 +02:00
|
|
|
|
chmod 744 /mnt/target/opt/void-usb/grub-config >> $LOGFILE 2>&1
|
|
|
|
|
echo "done"
|
|
|
|
|
|
|
|
|
|
echo -n "Adding kernel hooks... "
|
2023-07-02 20:52:21 +02:00
|
|
|
|
wget --output-document=/mnt/target/etc/kernel.d/pre-install/99-void-usb "$GIT_REPO_BASE/kernel.d/pre-install/99-void-usb" >> $LOGFILE 2>&1
|
2023-06-30 12:35:37 +02:00
|
|
|
|
chmod 744 /mnt/target/etc/kernel.d/pre-install/99-void-usb >> $LOGFILE 2>&1
|
2023-07-02 20:52:21 +02:00
|
|
|
|
wget --output-document=/mnt/target/etc/kernel.d/post-install/99-void-usb "$GIT_REPO_BASE/kernel.d/post-install/99-void-usb" >> $LOGFILE 2>&1
|
2023-06-30 12:35:37 +02:00
|
|
|
|
chmod 744 /mnt/target/etc/kernel.d/post-install/99-void-usb >> $LOGFILE 2>&1
|
2023-07-02 20:52:21 +02:00
|
|
|
|
wget --output-document=/mnt/target/etc/kernel.d/post-remove/99-void-usb "$GIT_REPO_BASE/kernel.d/post-remove/99-void-usb" >> $LOGFILE 2>&1
|
2023-06-30 12:35:37 +02:00
|
|
|
|
chmod 744 /mnt/target/etc/kernel.d/post-remove/99-void-usb >> $LOGFILE 2>&1
|
|
|
|
|
echo "done"
|
|
|
|
|
|
|
|
|
|
echo -n "Reconfiguring all installed packages... "
|
|
|
|
|
run_in_target xbps-reconfigure -fa >> $LOGFILE 2>&1
|
|
|
|
|
echo "done"
|
|
|
|
|
|
2023-07-02 22:55:18 +02:00
|
|
|
|
echo -n "Configuring runit to start some services... "
|
|
|
|
|
run_in_target ln -s /etc/sv/acpid /etc/runit/runsvdir/default/
|
|
|
|
|
run_in_target ln -s /etc/sv/dbus /etc/runit/runsvdir/default/
|
|
|
|
|
run_in_target ln -s /etc/sv/NetworkManager /etc/runit/runsvdir/default/
|
|
|
|
|
echo "done"
|
|
|
|
|
|
2023-06-30 12:36:10 +02:00
|
|
|
|
echo -n "Adding stage 2 installer... "
|
2023-07-02 20:54:58 +02:00
|
|
|
|
|
|
|
|
|
STAGE2_DIR="/mnt/target/opt/void-usb/installer"
|
|
|
|
|
function get_stage2_file {
|
|
|
|
|
[ -d "$STAGE2_DIR/$(dirname $1)" ] || mkdir -p "$STAGE2_DIR/$(dirname $1)"
|
|
|
|
|
wget --output-document="$STAGE2_DIR/$1" "$GIT_REPO_BASE/$1" >> $LOGFILE 2>&1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get_stage2_file install-stage2.sh >> $LOGFILE 2>&1
|
|
|
|
|
chmod 744 "$STAGE2_DIR/install-stage2.sh" >> $LOGFILE 2>&1
|
|
|
|
|
|
|
|
|
|
get_stage2_file package_selections/sections.lst
|
|
|
|
|
readarray -t SECTIONS < "$STAGE2_DIR/package_selections/sections.lst"
|
|
|
|
|
for I in ${!SECTIONS[@]}; do
|
|
|
|
|
get_stage2_file "package_selections/${SECTIONS[$I]}/description.txt"
|
|
|
|
|
|
|
|
|
|
get_stage2_file "package_selections/${SECTIONS[$I]}/options.lst"
|
|
|
|
|
readarray -t OPTIONS < "$STAGE2_DIR/package_selections/${SECTIONS[$I]}/options.lst"
|
|
|
|
|
for J in ${!OPTIONS[@]}; do
|
|
|
|
|
get_stage2_file "package_selections/${SECTIONS[$I]}/${OPTIONS[$J]}"
|
|
|
|
|
done
|
|
|
|
|
done
|
|
|
|
|
|
2023-07-02 22:55:18 +02:00
|
|
|
|
mv /mnt/target/etc/sv/agetty-tty1/conf /mnt/target/etc/sv/agetty-tty1/conf.bak >> $LOGFILE 2>&1
|
|
|
|
|
echo 'if [ -x /sbin/agetty -o -x /bin/agetty ]; then
|
|
|
|
|
if [ "${tty}" = "tty1" ]; then
|
|
|
|
|
GETTY_ARGS="--noclear --autologin root"
|
|
|
|
|
fi
|
|
|
|
|
fi' > /mnt/target/etc/sv/agetty-tty1/conf
|
|
|
|
|
|
|
|
|
|
[ -f /mnt/target/root/.profile ] && mv /mnt/target/root/.profile /mnt/target/root/.profile.bak >> $LOGFILE 2>&1
|
2023-07-14 20:50:12 +02:00
|
|
|
|
echo "if ps aux | grep 'installer-stage2.sh' | grep -v 'grep' > /dev/null 2>&1; then
|
2023-07-02 22:55:18 +02:00
|
|
|
|
true
|
|
|
|
|
else
|
|
|
|
|
/opt/void-usb/installer/install-stage2.sh
|
|
|
|
|
exit
|
|
|
|
|
fi" > /mnt/target/root/.profile
|
|
|
|
|
|
2023-06-30 12:36:10 +02:00
|
|
|
|
echo "done"
|
|
|
|
|
|
2023-07-02 22:57:05 +02:00
|
|
|
|
# This is not technically necessary, but it should help to save some memory.
|
|
|
|
|
# TODO: Be smart about this, run install stage 2 in chroot if there is enough free RAM
|
2023-06-30 12:36:10 +02:00
|
|
|
|
clear
|
|
|
|
|
echo "Stage 1 installation is now complete.
|
|
|
|
|
|
|
|
|
|
The freshly installed system needs to be booted to continue with stage 2 of the installation process.
|
2023-07-02 22:57:05 +02:00
|
|
|
|
The installer will now create a system image and reboot the computer.
|
2023-06-30 12:36:10 +02:00
|
|
|
|
"
|
|
|
|
|
press_any_key
|
2023-07-02 22:57:05 +02:00
|
|
|
|
|
|
|
|
|
echo "Creating system image..."
|
|
|
|
|
#TODO: make this work without user interaction
|
2023-07-14 21:27:57 +02:00
|
|
|
|
run_in_target /opt/void-usb/system-image
|
2023-06-30 12:36:10 +02:00
|
|
|
|
reboot
|
2023-06-14 07:07:17 +02:00
|
|
|
|
#
|