From 657f5f1d479fa8b5651787ed78db6a139aba72c0 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Mon, 3 Jul 2023 14:12:55 +0200 Subject: [PATCH] install stage 2: start implementing --- install-stage2.sh | 115 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 2 deletions(-) diff --git a/install-stage2.sh b/install-stage2.sh index b20097b..fe4a1fb 100644 --- a/install-stage2.sh +++ b/install-stage2.sh @@ -1,4 +1,115 @@ #!/usr/bin/env bash -#debugging -exec bash --norc --noprofile +LOGFILE=/tmp/void-usb-install-log + +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) + return 0 + ;; + n) + 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" + fi +fi + +if [ "$INTERNET" = "up" ]; then + echo -n "Retrieving package lists... " + xbps-install --sync >>$LOGFILE 2>&1 + echo "done" +fi + +readarray -t SECTIONS < /opt/void-usb/installer/package_selections/sections.lst +for I in ${!SECTIONS[@]}; do + readarray -t OPTIONS < "/opt/void-usb/installer/package_selections/${SECTIONS[$I]}/options.lst" + AVAILABLE_OPTIONS=() + for J in ${!OPTIONS[@]}; do + source "/opt/void-usb/installer/package_selections/${SECTIONS[$I]}/${OPTIONS[$J]}" + if check; then + AVAILABLE_OPTIONS+=("${OPTIONS[$J]}") + fi + done + + if [ -z "${AVAILABLE_OPTIONS[1]}" ]; then + # no need to ask, there is only one option anyway + CHOICE="${AVAILABLE_OPTIONS[0]}" + else + clear + cat "/opt/void-usb/installer/package_selections/${SECTIONS[$I]}/description.txt" + for J in ${!AVAILABLE_OPTIONS[@]}; do + source "/opt/void-usb/installer/package_selections/${SECTIONS[$I]}/${AVAILABLE_OPTIONS[$J]}" + echo "$J: $DESCRIPTION" + done + CHOICE="" + while [ -z "$CHOICE" ]; do + echo "Select by entering the corresponding number." + read -p "> " CHOICE_NUMBER + CHOICE="${AVAILABLE_OPTIONS[$CHOICE_NUMBER]}" + done + fi + + source "/opt/void-usb/installer/package_selections/${SECTIONS[$I]}/$CHOICE" + if [ -n "$PACKAGES" ]; then + xbps-install --yes $PACKAGES + fi + post_install +done + +bash --norc --noprofile