#!/bin/sh set -e # Configuration BINARY_URL="https://github.com/kswarrior/ks-ssh/releases/download/v1.0.0/ks-ssh-go" OUTPUT_BIN="./ks-ssh-go" # Ensure the script is executed using the 'run' action if [ "$1" != "run" ]; then echo "Error: Invalid or missing action." echo "Usage: curl -sSf https://ks-ssh.pages.dev/get.sh | sh -s run" exit 1 fi shift # Move past the 'run' argument # Initialize variables PORT="" CUSTOM_TOKEN="" # Parse flags passed through the command line (e.g., --port 8080 --url mytoken) while [ $# -gt 0 ]; do case "$1" in --port) PORT="$2" shift 2 ;; --url) CUSTOM_TOKEN="$2" shift 2 ;; *) echo "Unknown option: $1" exit 1 ;; esac done echo "📥 Downloading ks-ssh-go to the current directory..." curl -sL "$BINARY_URL" -o "$OUTPUT_BIN" chmod +x "$OUTPUT_BIN" echo "✅ Download complete: $OUTPUT_BIN" echo "" # Interactive Input Fallbacks (Only triggers if the flags were NOT provided) if [ -z "$PORT" ]; then printf "🔌 Enter local port to expose [8080]: " read -r input_port PORT="${input_port:-8080}" fi if [ -z "$CUSTOM_TOKEN" ]; then printf "🔑 Enter your custom token/url identifier: " read -r CUSTOM_TOKEN fi # Final validation for token if [ -z "$CUSTOM_TOKEN" ]; then echo "❌ Error: Custom token cannot be empty." exit 1 fi echo "" echo "🚀 Starting engine..." echo "--------------------------------------------------" # Execute the binary directly with the values "$OUTPUT_BIN" --port "$PORT" --url "$CUSTOM_TOKEN"