fix: skip installQuestions in non-interactive mode

- Extract IP detection into detect_server_ips() function
- Extract gateway calculations into prepare_network_config() function
- Only call installQuestions() in interactive mode
- Call detect_server_ips() and prepare_network_config() appropriately
- Rename AUTO_INSTALL to NON_INTERACTIVE_INSTALL for clarity

This fixes the CI failure where non-interactive installs were hanging
because installQuestions() was prompting for user input even when
configuration values were already set via CLI arguments.
This commit is contained in:
Stanislas Lange
2025-12-16 11:59:10 +01:00
parent de74685eb8
commit 4c6ae465b6

View File

@@ -96,8 +96,8 @@ log_debug() {
log_prompt() { log_prompt() {
# For user-facing prompts/questions (no prefix, just cyan) # For user-facing prompts/questions (no prefix, just cyan)
# Skip display in auto-install mode # Skip display in non-interactive mode
if [[ $AUTO_INSTALL != "y" ]]; then if [[ $NON_INTERACTIVE_INSTALL != "y" ]]; then
echo -e "${COLOR_CYAN}$*${COLOR_RESET}" echo -e "${COLOR_CYAN}$*${COLOR_RESET}"
fi fi
_log_to_file "[PROMPT] $*" _log_to_file "[PROMPT] $*"
@@ -105,8 +105,8 @@ log_prompt() {
log_header() { log_header() {
# For section headers # For section headers
# Skip display in auto-install mode # Skip display in non-interactive mode
if [[ $AUTO_INSTALL != "y" ]]; then if [[ $NON_INTERACTIVE_INSTALL != "y" ]]; then
echo "" echo ""
echo -e "${COLOR_BOLD}${COLOR_BLUE}=== $* ===${COLOR_RESET}" echo -e "${COLOR_BOLD}${COLOR_BLUE}=== $* ===${COLOR_RESET}"
echo "" echo ""
@@ -116,7 +116,7 @@ log_header() {
log_menu() { log_menu() {
# For menu options - only show in interactive mode # For menu options - only show in interactive mode
if [[ $AUTO_INSTALL != "y" ]]; then if [[ $NON_INTERACTIVE_INSTALL != "y" ]]; then
echo "$@" echo "$@"
fi fi
} }
@@ -1092,10 +1092,9 @@ cmd_install() {
if [[ $interactive == true ]]; then if [[ $interactive == true ]]; then
# Run interactive installer # Run interactive installer
installQuestions installQuestions
installOpenVPN
else else
# Non-interactive mode - set flags and defaults # Non-interactive mode - set flags and defaults
AUTO_INSTALL=y NON_INTERACTIVE_INSTALL=y
APPROVE_INSTALL=y APPROVE_INSTALL=y
APPROVE_IP=${APPROVE_IP:-y} APPROVE_IP=${APPROVE_IP:-y}
CONTINUE=y CONTINUE=y
@@ -1125,9 +1124,14 @@ cmd_install() {
# Validate configuration values (catches invalid env vars) # Validate configuration values (catches invalid env vars)
validate_configuration validate_configuration
installQuestions # Detect IPs and set up network config (interactive mode does this in installQuestions)
installOpenVPN detect_server_ips
fi fi
# Prepare derived network configuration (gateways, etc.)
prepare_network_config
installOpenVPN
} }
# Handle uninstall command # Handle uninstall command
@@ -2007,6 +2011,33 @@ function resolvePublicIP() {
fi fi
} }
# Detect server's IPv4 and IPv6 addresses
function detect_server_ips() {
IP_IPV4=$(ip -4 addr | sed -ne 's|^.* inet \([^/]*\)/.* scope global.*$|\1|p' | head -1)
IP_IPV6=$(ip -6 addr | sed -ne 's|^.* inet6 \([^/]*\)/.* scope global.*$|\1|p' | head -1)
# Set IP based on ENDPOINT_TYPE
if [[ $ENDPOINT_TYPE == "6" ]]; then
IP="$IP_IPV6"
else
IP="$IP_IPV4"
fi
}
# Calculate derived network configuration values
function prepare_network_config() {
# Calculate IPv4 gateway (always needed for leak prevention)
VPN_GATEWAY_IPV4="${VPN_SUBNET_IPV4%.*}.1"
# Calculate IPv6 gateway if IPv6 is enabled
if [[ $CLIENT_IPV6 == "y" ]]; then
VPN_GATEWAY_IPV6="${VPN_SUBNET_IPV6}1"
fi
# Set legacy variable for backward compatibility
IPV6_SUPPORT="$CLIENT_IPV6"
}
function installQuestions() { function installQuestions() {
log_header "OpenVPN Installer" log_header "OpenVPN Installer"
log_prompt "The git repository is available at: https://github.com/angristan/openvpn-install" log_prompt "The git repository is available at: https://github.com/angristan/openvpn-install"
@@ -2186,8 +2217,6 @@ function installQuestions() {
# IPv6-only mode: still need IPv4 subnet for leak prevention (redirect-gateway def1) # IPv6-only mode: still need IPv4 subnet for leak prevention (redirect-gateway def1)
VPN_SUBNET_IPV4="10.8.0.0" VPN_SUBNET_IPV4="10.8.0.0"
fi fi
# Calculate gateway (first usable IP in the subnet)
VPN_GATEWAY_IPV4="${VPN_SUBNET_IPV4%.*}.1"
# ========================================================================== # ==========================================================================
# Step 6: IPv6 subnet (if IPv6 enabled for clients) # Step 6: IPv6 subnet (if IPv6 enabled for clients)
@@ -2213,12 +2242,8 @@ function installQuestions() {
fi fi
;; ;;
esac esac
# Calculate gateway (first usable IP in the subnet)
VPN_GATEWAY_IPV6="${VPN_SUBNET_IPV6}1"
fi fi
# Set legacy IPV6_SUPPORT variable for backward compatibility
IPV6_SUPPORT="$CLIENT_IPV6"
log_menu "" log_menu ""
log_prompt "What port do you want OpenVPN to listen to?" log_prompt "What port do you want OpenVPN to listen to?"
log_menu " 1) Default: 1194" log_menu " 1) Default: 1194"
@@ -2502,15 +2527,15 @@ function installQuestions() {
} }
function installOpenVPN() { function installOpenVPN() {
if [[ $AUTO_INSTALL == "y" ]]; then if [[ $NON_INTERACTIVE_INSTALL == "y" ]]; then
# Resolve public IP if ENDPOINT not set # Resolve public IP if ENDPOINT not set
if [[ -z $ENDPOINT ]]; then if [[ -z $ENDPOINT ]]; then
ENDPOINT=$(resolvePublicIP) ENDPOINT=$(resolvePublicIP)
fi fi
# Log auto-install mode and parameters # Log non-interactive mode and parameters
log_info "=== OpenVPN Auto-Install ===" log_info "=== OpenVPN Non-Interactive Install ==="
log_info "Running in auto-install mode with the following settings:" log_info "Running in non-interactive mode with the following settings:"
log_info " ENDPOINT=$ENDPOINT" log_info " ENDPOINT=$ENDPOINT"
log_info " ENDPOINT_TYPE=$ENDPOINT_TYPE" log_info " ENDPOINT_TYPE=$ENDPOINT_TYPE"
log_info " CLIENT_IPV4=$CLIENT_IPV4" log_info " CLIENT_IPV4=$CLIENT_IPV4"