diff --git a/cockpit/cockpit-installer.sh b/cockpit/cockpit-installer.sh index 5c2fcc9..77b5d9b 100644 --- a/cockpit/cockpit-installer.sh +++ b/cockpit/cockpit-installer.sh @@ -26,7 +26,6 @@ show_help() { echo "Usage: $0 [options]" echo "" echo "Options:" - echo " --port Cockpit port (default: 12345)" echo " --user User to create (default: user)" echo " --password Password for the user (default: auto-generated)" echo " --timezone System timezone (default: UTC, e.g. Europe/Moscow)" @@ -34,25 +33,20 @@ show_help() { echo "" echo "Examples:" echo " $0" - echo " $0 --port 8443" - echo " $0 --port 8443 --user admin" - echo " $0 --port 8443 --user admin --password MySecret123!" - echo " $0 --port 8443 --timezone Europe/Moscow" + echo " $0 --user admin" + echo " $0 --user admin --password MySecret123!" + echo " $0 --timezone Europe/Moscow" echo "" } # ─── Parse arguments ────────────────────────────────────────────────────────── -COCKPIT_PORT=12345 +readonly COCKPIT_PORT=12345 NEW_USER="user" USER_PASSWORD="" TIMEZONE="UTC" while [[ $# -gt 0 ]]; do case "$1" in - --port) - COCKPIT_PORT="$2" - shift 2 - ;; --user) NEW_USER="$2" shift 2 @@ -90,43 +84,12 @@ if ! command -v apt &>/dev/null; then fi log_ok "OS check passed" -# ─── Validate port ──────────────────────────────────────────────────────────── -validate_port() { - local port="$1" - if ! [[ "$port" =~ ^[0-9]+$ ]] || \ - [ "$port" -lt 1 ] || \ - [ "$port" -gt 65535 ]; then - return 1 - fi - return 0 -} - -if ! validate_port "$COCKPIT_PORT"; then - log_err "Invalid port: '$COCKPIT_PORT'. Must be a number between 1 and 65535" - exit 1 -fi -log_ok "Port validation passed: $COCKPIT_PORT" - # ─── Check port is not in use ───────────────────────────────────────────────── if ss -tlnp | grep -q ":${COCKPIT_PORT} "; then - log_warn "Port $COCKPIT_PORT is already in use" - while true; do - # Print prompt directly to terminal, not to log - printf "${YELLOW}[~]${NC} Enter a new port: " > /dev/tty - read -r NEW_PORT < /dev/tty - if ! validate_port "$NEW_PORT"; then - log_err "Invalid port: '$NEW_PORT'. Must be a number between 1 and 65535" - continue - fi - if ss -tlnp | grep -q ":${NEW_PORT} "; then - log_err "Port $NEW_PORT is also in use. Try another" - continue - fi - COCKPIT_PORT="$NEW_PORT" - log_ok "Using port $COCKPIT_PORT" - break - done + log_err "Port $COCKPIT_PORT is already in use. The script uses a fixed Cockpit port and cannot continue" + exit 1 fi +log_ok "Cockpit will use fixed port $COCKPIT_PORT" # ─── Validate timezone ──────────────────────────────────────────────────────── if ! timedatectl list-timezones | grep -qx "$TIMEZONE"; then