From 517ac34e3d554bf98eee4130e27fc5a9fc78ca6e Mon Sep 17 00:00:00 2001 From: Jocadbz Date: Tue, 18 Feb 2025 04:08:57 +0100 Subject: [PATCH] custom-scripts: add customization scripts infrastructure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit has been created from multiple commits on Joca’s branch and additional edits Co-authored-by: BodgeMaster <> --- custom-scripts/README.md | 19 ++++++++++++++ custom-scripts/i3wm.sh | 12 +++++++++ custom-scripts/scripts.lst | 1 + install-stage1.sh | 8 +++++- install-stage2.sh | 54 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 custom-scripts/README.md create mode 100644 custom-scripts/i3wm.sh create mode 100644 custom-scripts/scripts.lst diff --git a/custom-scripts/README.md b/custom-scripts/README.md new file mode 100644 index 0000000..0cf751e --- /dev/null +++ b/custom-scripts/README.md @@ -0,0 +1,19 @@ + +### Configuration Scripts + +Use this to Deploy rices/set up services/etc. + +Each configuration script should follow this structure: + +```bash +#!/usr/bin/env bash +# NAME: Your Script Name +# DESC: A brief description of what the script does. + +# Your script logic here +``` + +If `# NAME:` is not found, install stage 2 will fall back to displaying the script's filename. +If `# DESC:` is not found, "No description available." will be displayed instead. + +Place the scripts under this folder, add the filename to `scripts.lst` (separate by newline) and they will show up in the installer. diff --git a/custom-scripts/i3wm.sh b/custom-scripts/i3wm.sh new file mode 100644 index 0000000..77a21bf --- /dev/null +++ b/custom-scripts/i3wm.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# NAME: Install i3wm +# DESC: This script installs i3wm and basic utilities. + + echo "Updating Void" + xbps-install -Suv + xbps-install -S + + +echo -e "Installing i3wm" + +xbps-install -S xinit xorg base-devel i3 i3status i3-gaps termite diff --git a/custom-scripts/scripts.lst b/custom-scripts/scripts.lst new file mode 100644 index 0000000..89f71a6 --- /dev/null +++ b/custom-scripts/scripts.lst @@ -0,0 +1 @@ +i3wm.sh diff --git a/install-stage1.sh b/install-stage1.sh index 73f37cc..48c9c1c 100644 --- a/install-stage1.sh +++ b/install-stage1.sh @@ -411,9 +411,15 @@ function get_stage2_file { wget --output-document="$STAGE2_DIR/$1" "$GIT_REPO_BASE/$1" >> $LOGFILE 2>&1 } -get_stage2_file install-stage2.sh >> $LOGFILE 2>&1 +get_stage2_file "install-stage2.sh" >> $LOGFILE 2>&1 chmod 744 "$STAGE2_DIR/install-stage2.sh" >> $LOGFILE 2>&1 +# Stage 2 prefab environment/rice install scripts +get_stage2_file "custom-scripts/scripts.lst" +while read -r NEXT_SCRIPT; do + [ -n "$NEXT_SCRIPT" ] && get_stage2_file "custom-scripts/$NEXT_SCRIPT" +done < "$STAGE2_DIR/custom-scripts/scripts.lst" + 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 diff --git a/install-stage2.sh b/install-stage2.sh index e52d2c2..ce933e0 100644 --- a/install-stage2.sh +++ b/install-stage2.sh @@ -78,4 +78,58 @@ if [ "$INTERNET" = "up" ]; then echo "done" fi + +STAGE2_DIR="/opt/void-usb/installer/" # Change this to your desired directory +CONFIG_DIR="$STAGE2_DIR/custom-scripts" +SCRIPT_LIST="$CONFIG_DIR/scripts.lst" +SCRIPTS=() +NAMES=() +DESCRIPTIONS=() + +# Find all scripts and extract their 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") + + # Extract name from "# NAME:" (first occurrence) + SCRIPT_NAME=$(grep -m1 '^# NAME:' "$script" | sed 's/^# NAME:[[:space:]]*//') + [ -z "$SCRIPT_NAME" ] && SCRIPT_NAME="$(basename "$script")" + + # Extract description from "# DESC:" (first occurrence) + SCRIPT_DESC=$(grep -m1 '^# 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 + +# Display menu dynamically +echo "Available configurations:" +for i in "${!SCRIPTS[@]}"; do + echo "$((i+1))) ${NAMES[i]} - ${DESCRIPTIONS[i]}" +done +echo "$(( ${#SCRIPTS[@]} + 1 ))) Exit" + +# Get user input +read -p "Select an option [1-$((${#SCRIPTS[@]}+1))]: " CHOICE + +# Run selected script +if (( CHOICE >= 1 && CHOICE <= ${#SCRIPTS[@]} )); then + echo "Running: ${NAMES[CHOICE-1]}" + bash "${SCRIPTS[CHOICE-1]}" +elif (( CHOICE == ${#SCRIPTS[@]} + 1 )); then + echo "Exiting..." + exit 0 +else + echo "Invalid choice." + exit 1 +fi + bash --norc --noprofile