mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-04-05 18:13:50 +00:00
APT Proxy: Support full URLs (http/https with custom ports) (#13474)
* APT Proxy: Support full URLs (http/https with custom ports) * APT Proxy: Add URL validation and update default.vars examples
This commit is contained in:
committed by
GitHub
parent
bff20d3b61
commit
730176268e
@@ -986,13 +986,23 @@ base_settings() {
|
|||||||
|
|
||||||
# Runtime check: Verify APT cacher is reachable if configured
|
# Runtime check: Verify APT cacher is reachable if configured
|
||||||
if [[ -n "$APT_CACHER_IP" && "$APT_CACHER" == "yes" ]]; then
|
if [[ -n "$APT_CACHER_IP" && "$APT_CACHER" == "yes" ]]; then
|
||||||
if ! curl -s --connect-timeout 2 "http://${APT_CACHER_IP}:3142" >/dev/null 2>&1; then
|
local _check_host _check_port _check_url
|
||||||
msg_warn "APT Cacher configured but not reachable at ${APT_CACHER_IP}:3142"
|
_check_host=$(echo "$APT_CACHER_IP" | sed -e 's|https\?://||' -e 's|/.*||' | cut -d: -f1)
|
||||||
|
_check_port=$(echo "$APT_CACHER_IP" | sed -e 's|https\?://||' -e 's|/.*||' | cut -s -d: -f2)
|
||||||
|
if [[ "$APT_CACHER_IP" =~ ^https?:// ]]; then
|
||||||
|
_check_url="$APT_CACHER_IP"
|
||||||
|
_check_port="${_check_port:-80}"
|
||||||
|
else
|
||||||
|
_check_port="${_check_port:-3142}"
|
||||||
|
_check_url="http://${APT_CACHER_IP}:${_check_port}"
|
||||||
|
fi
|
||||||
|
if ! curl -s --connect-timeout 2 "${_check_url}" >/dev/null 2>&1; then
|
||||||
|
msg_warn "APT Cacher configured but not reachable at ${_check_url}"
|
||||||
msg_custom "⚠️" "${YW}" "Disabling APT Cacher for this installation"
|
msg_custom "⚠️" "${YW}" "Disabling APT Cacher for this installation"
|
||||||
APT_CACHER=""
|
APT_CACHER=""
|
||||||
APT_CACHER_IP=""
|
APT_CACHER_IP=""
|
||||||
else
|
else
|
||||||
msg_ok "APT Cacher verified at ${APT_CACHER_IP}:3142"
|
msg_ok "APT Cacher verified at ${_check_url}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -1199,6 +1209,13 @@ load_vars_file() {
|
|||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
var_apt_cacher_ip)
|
||||||
|
# Allow: plain IP/hostname, http://host, https://host:port
|
||||||
|
if [[ -n "$var_val" ]] && ! [[ "$var_val" =~ ^(https?://)?[a-zA-Z0-9._-]+(:[0-9]+)?(/.*)?$ ]]; then
|
||||||
|
msg_warn "Invalid APT Cacher address '$var_val' in $file, ignoring"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
;;
|
||||||
var_container_storage | var_template_storage)
|
var_container_storage | var_template_storage)
|
||||||
# Validate that the storage exists and is active on the current node
|
# Validate that the storage exists and is active on the current node
|
||||||
local _storage_status
|
local _storage_status
|
||||||
@@ -1311,9 +1328,11 @@ var_ipv6_method=none
|
|||||||
var_ssh=no
|
var_ssh=no
|
||||||
# var_ssh_authorized_key=
|
# var_ssh_authorized_key=
|
||||||
|
|
||||||
# APT cacher (optional - with example)
|
# APT cacher (optional - IP or URL)
|
||||||
# var_apt_cacher=yes
|
# var_apt_cacher=yes
|
||||||
# var_apt_cacher_ip=192.168.1.10
|
# var_apt_cacher_ip=192.168.1.10
|
||||||
|
# var_apt_cacher_ip=http://proxy.local
|
||||||
|
# var_apt_cacher_ip=https://proxy.local:443
|
||||||
|
|
||||||
# Features/Tags/verbosity
|
# Features/Tags/verbosity
|
||||||
var_fuse=no
|
var_fuse=no
|
||||||
@@ -2526,7 +2545,7 @@ advanced_settings() {
|
|||||||
# Ask for IP if enabled
|
# Ask for IP if enabled
|
||||||
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
|
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
|
||||||
--title "APT CACHER IP" \
|
--title "APT CACHER IP" \
|
||||||
--inputbox "\nEnter APT Cacher-NG server IP address:" 10 58 "$_apt_cacher_ip" \
|
--inputbox "\nEnter APT Cacher-NG IP or URL:\n(e.g. 192.168.1.10, http://host, https://host:443)" 12 62 "$_apt_cacher_ip" \
|
||||||
3>&1 1>&2 2>&3); then
|
3>&1 1>&2 2>&3); then
|
||||||
_apt_cacher_ip="$result"
|
_apt_cacher_ip="$result"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -390,10 +390,24 @@ update_os() {
|
|||||||
msg_info "Updating Container OS"
|
msg_info "Updating Container OS"
|
||||||
if [[ "$CACHER" == "yes" ]]; then
|
if [[ "$CACHER" == "yes" ]]; then
|
||||||
echo 'Acquire::http::Proxy-Auto-Detect "/usr/local/bin/apt-proxy-detect.sh";' >/etc/apt/apt.conf.d/00aptproxy
|
echo 'Acquire::http::Proxy-Auto-Detect "/usr/local/bin/apt-proxy-detect.sh";' >/etc/apt/apt.conf.d/00aptproxy
|
||||||
|
local _proxy_raw="${CACHER_IP}"
|
||||||
|
local _proxy_host _proxy_port _proxy_url
|
||||||
|
# Parse host and port from URL or plain IP/hostname
|
||||||
|
_proxy_host=$(echo "$_proxy_raw" | sed -e 's|https\?://||' -e 's|/.*||' | cut -d: -f1)
|
||||||
|
_proxy_port=$(echo "$_proxy_raw" | sed -e 's|https\?://||' -e 's|/.*||' | cut -s -d: -f2)
|
||||||
|
if [[ "$_proxy_raw" =~ ^https?:// ]]; then
|
||||||
|
# Full URL provided — use as-is for proxy output, extract port for nc check
|
||||||
|
_proxy_url="$_proxy_raw"
|
||||||
|
_proxy_port="${_proxy_port:-80}"
|
||||||
|
else
|
||||||
|
# Legacy: plain IP or hostname — default to http + port 3142
|
||||||
|
_proxy_port="${_proxy_port:-3142}"
|
||||||
|
_proxy_url="http://${_proxy_raw}:${_proxy_port}"
|
||||||
|
fi
|
||||||
cat <<EOF >/usr/local/bin/apt-proxy-detect.sh
|
cat <<EOF >/usr/local/bin/apt-proxy-detect.sh
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
if nc -w1 -z "${CACHER_IP}" 3142; then
|
if nc -w1 -z "${_proxy_host}" ${_proxy_port}; then
|
||||||
echo -n "http://${CACHER_IP}:3142"
|
echo -n "${_proxy_url}"
|
||||||
else
|
else
|
||||||
echo -n "DIRECT"
|
echo -n "DIRECT"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user