From 03bd9b6ad5335aff65d9cb6fb1d117b5cb4b7919 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Sat, 18 Jul 2026 14:55:21 +0530 Subject: refactor(scripts): split monolithic module into per-script submodules Extract shared `mkScript` and `mkScriptModule` helpers into `lib.nix` Split each script into `modules/scripts//` with its own `default.nix`, `script.sh`, and `assertions.nix` Remove `conditions` parameter from `mkScriptModule`; move condition assertions into per-script `assertions.nix` files with inline checks and error messages Simplify `mkScriptModule` to return `{ options, moduleConfig }` instead of a module function, taking `config` as a direct parameter Add `description` field to `mkScript` that inserts the description as a `# ` comment between the shebang and env vars Thread `description` through `mkScriptModule` to each `default.nix` Move top comment lines from each `script.sh` into the `description` field and remove from sources to avoid duplication Remove old flat `.sh` files from `modules/scripts/` root --- modules/scripts/vpn-connect.sh | 78 ------------------------------------------ 1 file changed, 78 deletions(-) delete mode 100644 modules/scripts/vpn-connect.sh (limited to 'modules/scripts/vpn-connect.sh') diff --git a/modules/scripts/vpn-connect.sh b/modules/scripts/vpn-connect.sh deleted file mode 100644 index 337fa2e..0000000 --- a/modules/scripts/vpn-connect.sh +++ /dev/null @@ -1,78 +0,0 @@ -# VPN-connect - OpenVPN connection script with credential caching and monitoring -CONF_DIR="$HOME/.config/openvpn" -CREDS_DIR="$CONF_DIR/credentials" -SERVERS_DIR="$CONF_DIR/servers" -CACHE_FILE="$HOME/.cache/openvpn/last_connection" -PID_FILE="$HOME/.cache/openvpn/vpn.pid" -LOG_FILE="$HOME/.cache/openvpn/vpn.log" - -mkdir -p "$CREDS_DIR" "$SERVERS_DIR" "$(dirname "$CACHE_FILE")" - -REFRESH=false -if [[ "$1" == "--refresh" || "$1" == "-r" ]]; then - REFRESH=true -fi - -# Load cache -if [[ "$REFRESH" == false && -f "$CACHE_FILE" ]]; then - source "$CACHE_FILE" - if [[ ! -f "$CRED" || ! -f "$SERVER" ]]; then - REFRESH=true - fi -else - REFRESH=true -fi - -# Select if needed -if [[ "$REFRESH" == true ]]; then - CRED=$(find "$CREDS_DIR" -type f | fzf --prompt="Select Credentials > ") - [ -z "$CRED" ] && exit 1 - - SERVER=$(find "$SERVERS_DIR" -type f \( -name "*.conf" -o -name "*.ovpn" \) | fzf --prompt="Select VPN Server > ") - [ -z "$SERVER" ] && exit 1 - - echo "CRED=\"$CRED\"" > "$CACHE_FILE" - echo "SERVER=\"$SERVER\"" >> "$CACHE_FILE" -fi - -echo "Connecting to $SERVER..." - -TMP_CONF=$(mktemp /tmp/vpn-config.XXXXXX) - -sed -e '/up \/etc\/openvpn\/update-resolv-conf/d' \ - -e '/down \/etc\/openvpn\/update-resolv-conf/d' "$SERVER" > "$TMP_CONF" - -# Run in background -sudo -v || exit 1 - -nohup sudo openvpn \ - --config "$TMP_CONF" \ - --auth-user-pass "$CRED" \ - --script-security 2 \ - --up "$SYSTEMD_RESOLVED_PATH" \ - --down "$SYSTEMD_RESOLVED_PATH" \ - --down-pre \ - > "$LOG_FILE" 2>&1 & - -VPN_PID=$! - -echo $VPN_PID > "$PID_FILE" -echo "VPN started in background (PID: $VPN_PID)" -echo "Logs: $LOG_FILE" - -# Wait until connected -echo -n "Waiting for VPN connection" -while true; do - if grep -q "Initialization Sequence Completed" "$LOG_FILE" 2>/dev/null; then - echo "" - echo "VPN connected successfully." - break - fi - if ! kill -0 "$VPN_PID" 2>/dev/null; then - echo "" - echo "VPN process died. Check logs: $LOG_FILE" - exit 1 - fi - sleep 1 - echo -n "." -done -- cgit v1.2.3