Ward from fusion-voyager-3 f2f680e37b Add quiet mode
2024-12-17 20:30:41 +03:00

126 lines
4.0 KiB
Bash
Executable File

#! /bin/bash
set -e
# Mount the proc kernel temp mount
busybox mount -n -t proc proc /proc
# Check if bootloader wants the hook to be executed
BOOT_PARAM="$(busybox grep -o 'boot=[^ ]*' /proc/cmdline | busybox awk -F= '{print $2}')"
if [[ $BOOT_PARAM != "live" ]]
then
exit 0
fi
# Check if quiet is used
if [[ "$(busybox cat /proc/cmdline)" =~ (^|[[:space:]])quiet($|[[:space:]]) ]]; then
QUIET_MODE=true
else
QUIET_MODE=false
fi
VTOY_ISO_NAME_PARAM="$(busybox grep -o 'VTOY_ISO_NAME=[^ ]*' /proc/cmdline | busybox awk -F= '{print $2}')"
if [ "$QUIET_MODE" = false ]
then
busybox echo '[PikaOS Booster Live Hook]: boot=live detected in kernel cmdline, running LiveISO hooks...'
fi
### Create mounting dirs
if [ "$QUIET_MODE" = false ]
then
busybox echo '[PikaOS Booster Live Hook]: Creating mountpoints...'
fi
busybox mkdir -p /mnt/medium /mnt/filesystem /mnt/overlay /booster.root
# Try finding Appended partition among standard partition blocks.
if [ "$QUIET_MODE" = false ]
then
busybox echo '[PikaOS Booster Live Hook]: Searching for Live medium...'
fi
LIVE_MEDIA="$(busybox blkid | busybox grep "PikaOS 4" | busybox grep "iso9660" | busybox head -n1 | busybox awk -F: '{print $1}')"
if [ -z "$LIVE_MEDIA" ]
then
# Try getting appended partition from Ventoy ISO Partition
if [ "$QUIET_MODE" = false ]
then
busybox echo '[PikaOS Booster Live Hook]: Live medium could not be found among standard blocks.'
fi
if [ "$QUIET_MODE" = false ]
then
busybox echo '[PikaOS Booster Live Hook]: Attempting Ventoy mapping hook.'
fi
# Get Ventoy ISO Partition ID
VENTOY_DEVICE="$(busybox blkid | busybox grep "Ventoy" | busybox head -n1 | busybox awk -F: '{print $1}')"
# Keep retrying 10 times incase usb_storage has yet to pick up
while [ -z "$VENTOY_DEVICE" ]
do
if [ "$QUIET_MODE" = false ]
then
busybox echo '[PikaOS Booster Live Hook]: Ventoy Device not found retrying...'
fi
VENTOY_DEVICE="$(busybox blkid | busybox grep "Ventoy" | busybox head -n1 | busybox awk -F: '{print $1}')"
((c++)) && ((c==10)) && break
busybox sleep 5
done
# Get filesystem if iso was found
if [ ! -z "$VENTOY_DEVICE" ]
then
if [ "$QUIET_MODE" = false ]
then
busybox echo "[PikaOS Booster Live Hook]: Ventoy device found as $VENTOY_DEVICE !"
fi
busybox mkdir -p /mnt/ventoy
busybox mount -o ro "$VENTOY_DEVICE" /mnt/ventoy
### Mount live medium
if [ "$QUIET_MODE" = false ]
then
busybox echo '[PikaOS Booster Live Hook]: Mounting Live medium...'
fi
busybox mount -o ro,loop /mnt/ventoy/$VTOY_ISO_NAME_PARAM /mnt/medium
else
if [ "$QUIET_MODE" = false ]
then
busybox echo '[PikaOS Booster Live Hook]: Error: Live medium could not be found!'
fi
exit 32
fi
else
if [ "$QUIET_MODE" = false ]
then
busybox echo "[PikaOS Booster Live Hook]: Live medium found on $LIVE_MEDIA !"
fi
### Mount live medium
if [ "$QUIET_MODE" = false ]
then
busybox echo '[PikaOS Booster Live Hook]: Mounting Live medium...'
fi
busybox mount -o ro $LIVE_MEDIA /mnt/medium
fi
### Create loop from squashfs
if [ "$QUIET_MODE" = false ]
then
busybox echo '[PikaOS Booster Live Hook]: Mounting Live medium squashfs image...'
fi
busybox mount -o loop,ro /mnt/medium/live/filesystem.squashfs /mnt/filesystem
### Mount tmpfs on ram
if [ "$QUIET_MODE" = false ]
then
busybox echo '[PikaOS Booster Live Hook]: Creating Ramfs...'
fi
busybox mount -t tmpfs -o mode=1777 overlay_tmpfs /mnt/overlay
### Create overlay dirs
busybox mkdir -p /mnt/overlay/upper /mnt/overlay/work
### Create merged overlay
if [ "$QUIET_MODE" = false ]
then
busybox echo '[PikaOS Booster Live Hook]: Creating writable overlay Rootfs on ramfs...'
fi
busybox mount -t overlay overlay -o lowerdir=/mnt/filesystem:/mnt/medium,upperdir=/mnt/overlay/upper,workdir=/mnt/overlay/work /booster.root