#!/usr/bin/env bash LOGFILE=/tmp/void-usb-install-log STAGE2_DIR="/opt/void-usb/installer/" function press_any_key { echo "Press any key to continue or Ctrl+c to abort..." read -n1 DISCARD_ME echo "" } function yesno { unset DISCARD_ME while [ -z "$DISCARD_ME" ]; do read -p "[y/n] " -n1 DISCARD_ME case "$DISCARD_ME" in y) echo "" return 0 ;; n) echo "" return 1 ;; *) echo " Please enter y for yes or n for no." unset DISCARD_ME ;; esac done } [ -z "$TERM" ] && export TERM=linux echo -n "Checking for internet connection..." INTERNET="down" WAITING=0 while [ "$INTERNET" = "down" -a "$WAITING" -lt 15 ]; do sleep 1 if ping -c2 repo-default.voidlinux.org >> $LOGFILE 2>&1; then INTERNET="up" fi WAITING=$((WAITING+1)) echo -n "." done echo " $INTERNET" if [ "$INTERNET" = "down" ]; then clear echo "Connect to WiFi? Any network settings from before the reboot have not been saved and need to be entered again. Use 'Activate a connection' in the dialog to select your network. Alternatively, you can continue without internet but the system will be left in a barebones state. " if yesno; then nmtui clear echo -n "Checking for internet connection..." WAITING=0 while [ "$INTERNET" = "down" -a "$WAITING" -lt 15 ]; do sleep 1 if ping -c2 repo-default.voidlinux.org >> $LOGFILE 2>&1; then INTERNET="up" fi WAITING=$((WAITING+1)) echo -n "." done echo " $INTERNET" # TODO: allow to connect again if still no internet fi fi if [ "$INTERNET" = "up" ]; then echo -n "Retrieving package lists... " xbps-install --sync >>$LOGFILE 2>&1 echo "done" fi CONFIG_DIR="$STAGE2_DIR/custom-scripts" SCRIPTS=() NAMES=() DESCRIPTIONS=() echo "Scanning for configuration scripts in $CONFIG_DIR..." for script in "$CONFIG_DIR"/*.sh; do [ -f "$script" ] || continue # Skip if no .sh files found SCRIPTS+=("$script") SCRIPT_NAME=$(grep '^# NAME:' "$script" | sed 's/^# NAME:[[:space:]]*//') [ -z "$SCRIPT_NAME" ] && SCRIPT_NAME="$(basename "$script")" SCRIPT_DESC=$(grep '^# DESC:' "$script" | sed 's/^# DESC:[[:space:]]*//') [ -z "$SCRIPT_DESC" ] && SCRIPT_DESC="No description available." NAMES+=("$SCRIPT_NAME") DESCRIPTIONS+=("$SCRIPT_DESC") done # Check if no scripts were found if [ ${#SCRIPTS[@]} -eq 0 ]; then echo "No configuration scripts found in $CONFIG_DIR." exit 1 fi echo "Available configurations:" for i in "${!SCRIPTS[@]}"; do echo "$((i+1)): ${NAMES[i]} - ${DESCRIPTIONS[i]}" done echo "$(( ${#SCRIPTS[@]} + 1 )): Exit" CHOICE=0 while ! (( CHOICE >= 1 && CHOICE <= ${#SCRIPTS[@]} )); do read -p "Select an option [1-$((${#SCRIPTS[@]}+1))]: " CHOICE if (( CHOICE >= 1 && CHOICE <= ${#SCRIPTS[@]} )); then echo "Running: ${NAMES[CHOICE-1]}" bash "${SCRIPTS[CHOICE-1]}" elif (( CHOICE == ${#SCRIPTS[@]} + 1 )); then echo "Exiting..." break else echo "Invalid choice." fi done echo "Setting up user..." read -p "Enter username: " NEW_USER #TODO: let the user choose additional groups (suggest sane defaults for different use cases) # cdrom? optical? storage? what they do? # scanner # network (check if this even still does anything) # kvm # audio, video # dialout # users (dows this even do anything) useradd -m -s /bin/bash -G wheel "$NEW_USER" passwd "$NEW_USER" echo "Cleaning up installation files..." mv /mnt/target/etc/sv/agetty-tty1/conf.bak /mnt/target/etc/sv/agetty-tty1/conf >> $LOGFILE 2>&1 if [ -f /root/.profile.bak ]; then mv /root/.profile.bak /root/.profile else rm /root/.profile fi rm -rf "$STAGE2_DIR" clear echo "To save the changes made to the system, a new system image needs to be created. The system will reboot now. While shutting down, you will be asked about creating a system image. Choose yes." reboot