#!/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 # --- CHANGED SECTION --- # Check and remove existing binary if it exists to force a fresh download if [ -f "$OUTPUT_BIN" ]; then echo "๐Ÿงน Found existing $OUTPUT_BIN, removing for a fresh download..." rm -f "$OUTPUT_BIN" fi # ----------------------- 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"