#!/usr/bin/env bash # VPS Installer bootstrap script # Usage: # curl -sSL https://your-host/bootstrap.sh | bash -s -- \ # --ip 0.0.0.0 --port 8443 --login admin --password S3cur3Pass set -euo pipefail # ─── Defaults ──────────────────────────────────────────────────────────────── INSTALLER_IP="" INSTALLER_PORT="" INSTALLER_LOGIN="" INSTALLER_PASSWORD="" NO_TLS="false" INSTALL_DIR="/opt/vps-installer" BASE_URL="${INSTALLER_BASE_URL:-https://vps.myidb.ru/files}" # ─── Argument parsing ──────────────────────────────────────────────────────── usage() { cat < VPS Installer Bootstrap" echo " Arch: $ARCH ($BINARY_ARCH)" echo " Listen: $INSTALLER_IP:$INSTALLER_PORT" echo " TLS: $([ "$NO_TLS" = "true" ] && echo 'disabled' || echo 'enabled (self-signed)')" echo "" mkdir -p "$INSTALL_DIR" BINARY_PATH="$INSTALL_DIR/vps-installer" echo "==> Downloading $BINARY_NAME ..." if command -v curl &>/dev/null; then curl -fsSL "$DOWNLOAD_URL" -o "$BINARY_PATH" elif command -v wget &>/dev/null; then wget -qO "$BINARY_PATH" "$DOWNLOAD_URL" else echo "ERROR: Neither curl nor wget is available." exit 1 fi chmod +x "$BINARY_PATH" echo " Saved to: $BINARY_PATH" # ─── Launch ────────────────────────────────────────────────────────────────── NOTLS_FLAG="" [ "$NO_TLS" = "true" ] && NOTLS_FLAG="--no-tls" # Detect public IP for display if binding to 0.0.0.0 DISPLAY_IP="$INSTALLER_IP" if [ "$INSTALLER_IP" = "0.0.0.0" ]; then DISPLAY_IP="$(ip -4 route get 8.8.8.8 2>/dev/null | grep -oP 'src \K\S+' || echo '')" fi PROTO="https" [ "$NO_TLS" = "true" ] && PROTO="http" echo "" echo "==> Starting VPS Installer..." echo "" echo " ┌─────────────────────────────────────────────────────┐" echo " │ Open in browser: │" echo " │ ${PROTO}://${DISPLAY_IP}:${INSTALLER_PORT}/ │" echo " │ │" if [ "$NO_TLS" = "false" ]; then echo " │ NOTE: Accept the self-signed TLS certificate │" echo " │ warning in your browser (one-time). │" echo " │ │" fi echo " │ Press Ctrl+C to stop the installer. │" echo " └─────────────────────────────────────────────────────┘" echo "" exec "$BINARY_PATH" \ --ip "$INSTALLER_IP" \ --port "$INSTALLER_PORT" \ --login "$INSTALLER_LOGIN" \ --password "$INSTALLER_PASSWORD" \ $NOTLS_FLAG