mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-04-28 13:20:40 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| df75b12c60 | |||
| beb29c00ea |
+12
-3
@@ -1054,7 +1054,7 @@ load_vars_file() {
|
|||||||
|
|
||||||
# Allowed var_* keys
|
# Allowed var_* keys
|
||||||
local VAR_WHITELIST=(
|
local VAR_WHITELIST=(
|
||||||
var_apt_cacher var_apt_cacher_ip var_brg var_cpu var_disk var_fuse var_gpu var_keyctl
|
var_apt_cacher var_apt_cacher_ip var_brg var_cpu var_disk var_fuse var_github_token var_gpu var_keyctl
|
||||||
var_gateway var_hostname var_ipv6_method var_mac var_mknod var_mount_fs var_mtu
|
var_gateway var_hostname var_ipv6_method var_mac var_mknod var_mount_fs var_mtu
|
||||||
var_net var_nesting var_ns var_os var_protection var_pw var_ram var_tags var_timezone var_tun var_unprivileged
|
var_net var_nesting var_ns var_os var_protection var_pw var_ram var_tags var_timezone var_tun var_unprivileged
|
||||||
var_verbose var_version var_vlan var_ssh var_ssh_authorized_key var_container_storage var_template_storage var_searchdomain
|
var_verbose var_version var_vlan var_ssh var_ssh_authorized_key var_container_storage var_template_storage var_searchdomain
|
||||||
@@ -1255,7 +1255,7 @@ default_var_settings() {
|
|||||||
# Allowed var_* keys (alphabetically sorted)
|
# Allowed var_* keys (alphabetically sorted)
|
||||||
# Note: Removed var_ctid (can only exist once), var_ipv6_static (static IPs are unique)
|
# Note: Removed var_ctid (can only exist once), var_ipv6_static (static IPs are unique)
|
||||||
local VAR_WHITELIST=(
|
local VAR_WHITELIST=(
|
||||||
var_apt_cacher var_apt_cacher_ip var_brg var_cpu var_disk var_fuse var_gpu var_keyctl
|
var_apt_cacher var_apt_cacher_ip var_brg var_cpu var_disk var_fuse var_github_token var_gpu var_keyctl
|
||||||
var_gateway var_hostname var_ipv6_method var_mac var_mknod var_mount_fs var_mtu
|
var_gateway var_hostname var_ipv6_method var_mac var_mknod var_mount_fs var_mtu
|
||||||
var_net var_nesting var_ns var_os var_protection var_pw var_ram var_tags var_timezone var_tun var_unprivileged
|
var_net var_nesting var_ns var_os var_protection var_pw var_ram var_tags var_timezone var_tun var_unprivileged
|
||||||
var_verbose var_version var_vlan var_ssh var_ssh_authorized_key var_container_storage var_template_storage
|
var_verbose var_version var_vlan var_ssh var_ssh_authorized_key var_container_storage var_template_storage
|
||||||
@@ -1350,6 +1350,10 @@ var_verbose=no
|
|||||||
|
|
||||||
# Security (root PW) – empty => autologin
|
# Security (root PW) – empty => autologin
|
||||||
# var_pw=
|
# var_pw=
|
||||||
|
|
||||||
|
# GitHub Personal Access Token (optional – avoids API rate limits during installs)
|
||||||
|
# Create at https://github.com/settings/tokens – read-only public access is sufficient
|
||||||
|
# var_github_token=ghp_your_token_here
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Now choose storages (always prompt unless just one exists)
|
# Now choose storages (always prompt unless just one exists)
|
||||||
@@ -1387,6 +1391,11 @@ EOF
|
|||||||
VERBOSE="no"
|
VERBOSE="no"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 4) Map var_github_token → GITHUB_TOKEN (only if not already set in environment)
|
||||||
|
if [[ -z "${GITHUB_TOKEN:-}" && -n "${var_github_token:-}" ]]; then
|
||||||
|
export GITHUB_TOKEN="${var_github_token}"
|
||||||
|
fi
|
||||||
|
|
||||||
# 4) Apply base settings and show summary
|
# 4) Apply base settings and show summary
|
||||||
METHOD="mydefaults-global"
|
METHOD="mydefaults-global"
|
||||||
base_settings "$VERBOSE"
|
base_settings "$VERBOSE"
|
||||||
@@ -1419,7 +1428,7 @@ get_app_defaults_path() {
|
|||||||
if ! declare -p VAR_WHITELIST >/dev/null 2>&1; then
|
if ! declare -p VAR_WHITELIST >/dev/null 2>&1; then
|
||||||
# Note: Removed var_ctid (can only exist once), var_ipv6_static (static IPs are unique)
|
# Note: Removed var_ctid (can only exist once), var_ipv6_static (static IPs are unique)
|
||||||
declare -ag VAR_WHITELIST=(
|
declare -ag VAR_WHITELIST=(
|
||||||
var_apt_cacher var_apt_cacher_ip var_brg var_cpu var_disk var_fuse var_gpu
|
var_apt_cacher var_apt_cacher_ip var_brg var_cpu var_disk var_fuse var_github_token var_gpu
|
||||||
var_gateway var_hostname var_ipv6_method var_mac var_mtu
|
var_gateway var_hostname var_ipv6_method var_mac var_mtu
|
||||||
var_net var_ns var_os var_pw var_ram var_tags var_tun var_unprivileged
|
var_net var_ns var_os var_pw var_ram var_tags var_tun var_unprivileged
|
||||||
var_verbose var_version var_vlan var_ssh var_ssh_authorized_key var_container_storage var_template_storage
|
var_verbose var_version var_vlan var_ssh var_ssh_authorized_key var_container_storage var_template_storage
|
||||||
|
|||||||
+82
-3
@@ -1117,15 +1117,87 @@ is_package_installed() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# validate_github_token()
|
||||||
|
# Checks a GitHub token via the /user endpoint.
|
||||||
|
# Prints a status message and returns:
|
||||||
|
# 0 - token is valid
|
||||||
|
# 1 - token is invalid / expired (HTTP 401)
|
||||||
|
# 2 - token has no public repo scope (HTTP 200 but missing scope)
|
||||||
|
# 3 - network/API error
|
||||||
|
# Also reports expiry date if the token carries an x-oauth-expiry header.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
validate_github_token() {
|
||||||
|
local token="${1:-${GITHUB_TOKEN:-}}"
|
||||||
|
[[ -z "$token" ]] && return 3
|
||||||
|
|
||||||
|
local response headers http_code expiry_date scopes
|
||||||
|
headers=$(mktemp)
|
||||||
|
response=$(curl -sSL -w "%{http_code}" \
|
||||||
|
-D "$headers" \
|
||||||
|
-o /dev/null \
|
||||||
|
-H "Authorization: Bearer $token" \
|
||||||
|
-H "Accept: application/vnd.github+json" \
|
||||||
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
|
"https://api.github.com/user" 2>/dev/null) || { rm -f "$headers"; return 3; }
|
||||||
|
http_code="$response"
|
||||||
|
|
||||||
|
# Read expiry header (fine-grained PATs carry this)
|
||||||
|
expiry_date=$(grep -i '^github-authentication-token-expiration:' "$headers" \
|
||||||
|
| sed 's/.*: *//' | tr -d '\r\n' || true)
|
||||||
|
# Read token scopes (classic PATs)
|
||||||
|
scopes=$(grep -i '^x-oauth-scopes:' "$headers" \
|
||||||
|
| sed 's/.*: *//' | tr -d '\r\n' || true)
|
||||||
|
rm -f "$headers"
|
||||||
|
|
||||||
|
case "$http_code" in
|
||||||
|
200)
|
||||||
|
if [[ -n "$expiry_date" ]]; then
|
||||||
|
msg_ok "GitHub token is valid (expires: $expiry_date)."
|
||||||
|
else
|
||||||
|
msg_ok "GitHub token is valid (no expiry / fine-grained PAT)."
|
||||||
|
fi
|
||||||
|
# Warn if classic PAT has no public_repo scope
|
||||||
|
if [[ -n "$scopes" && "$scopes" != *"public_repo"* && "$scopes" != *"repo"* ]]; then
|
||||||
|
msg_warn "Token has no 'public_repo' scope - private repos and some release APIs may fail."
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
401)
|
||||||
|
msg_error "GitHub token is invalid or expired (HTTP 401)."
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
msg_warn "GitHub token validation returned HTTP $http_code - treating as valid."
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Prompt user to enter a GitHub Personal Access Token (PAT) interactively
|
# Prompt user to enter a GitHub Personal Access Token (PAT) interactively
|
||||||
# Returns 0 if a valid token was provided, 1 otherwise
|
# Returns 0 if a valid token was provided, 1 otherwise
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
prompt_for_github_token() {
|
prompt_for_github_token() {
|
||||||
if [[ ! -t 0 ]]; then
|
if [[ ! -t 0 ]]; then
|
||||||
|
# Non-interactive: pick up var_github_token if set (from default.vars / app.vars / env)
|
||||||
|
if [[ -z "${GITHUB_TOKEN:-}" && -n "${var_github_token:-}" ]]; then
|
||||||
|
export GITHUB_TOKEN="${var_github_token}"
|
||||||
|
msg_ok "GitHub token loaded from var_github_token."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Prefer var_github_token when already set and no interactive override needed
|
||||||
|
if [[ -z "${GITHUB_TOKEN:-}" && -n "${var_github_token:-}" ]]; then
|
||||||
|
export GITHUB_TOKEN="${var_github_token}"
|
||||||
|
msg_ok "GitHub token loaded from var_github_token."
|
||||||
|
validate_github_token || true
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
local reply
|
local reply
|
||||||
read -rp "${TAB}Would you like to enter a GitHub Personal Access Token (PAT)? [y/N]: " reply
|
read -rp "${TAB}Would you like to enter a GitHub Personal Access Token (PAT)? [y/N]: " reply
|
||||||
reply="${reply:-n}"
|
reply="${reply:-n}"
|
||||||
@@ -1147,10 +1219,16 @@ prompt_for_github_token() {
|
|||||||
msg_warn "Token must not contain spaces. Please try again."
|
msg_warn "Token must not contain spaces. Please try again."
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
# Validate before accepting
|
||||||
|
export GITHUB_TOKEN="$token"
|
||||||
|
if validate_github_token "$token"; then
|
||||||
break
|
break
|
||||||
|
else
|
||||||
|
msg_warn "Please enter a valid token, or press Ctrl+C to abort."
|
||||||
|
unset GITHUB_TOKEN
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
export GITHUB_TOKEN="$token"
|
|
||||||
msg_ok "GitHub token has been set."
|
msg_ok "GitHub token has been set."
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -2860,7 +2938,7 @@ function fetch_and_deploy_codeberg_release() {
|
|||||||
|
|
||||||
while ((attempt < ${#api_timeouts[@]})); do
|
while ((attempt < ${#api_timeouts[@]})); do
|
||||||
resp=$(curl --connect-timeout 10 --max-time "${api_timeouts[$attempt]}" -fsSL -w "%{http_code}" -o /tmp/codeberg_rel.json "$api_url") && success=true && break
|
resp=$(curl --connect-timeout 10 --max-time "${api_timeouts[$attempt]}" -fsSL -w "%{http_code}" -o /tmp/codeberg_rel.json "$api_url") && success=true && break
|
||||||
((attempt++))
|
attempt=$((attempt + 1))
|
||||||
if ((attempt < ${#api_timeouts[@]})); then
|
if ((attempt < ${#api_timeouts[@]})); then
|
||||||
msg_warn "API request timed out after ${api_timeouts[$((attempt - 1))]}s, retrying... (attempt $((attempt + 1))/${#api_timeouts[@]})"
|
msg_warn "API request timed out after ${api_timeouts[$((attempt - 1))]}s, retrying... (attempt $((attempt + 1))/${#api_timeouts[@]})"
|
||||||
fi
|
fi
|
||||||
@@ -3370,7 +3448,8 @@ function fetch_and_deploy_gh_release() {
|
|||||||
if prompt_for_github_token; then
|
if prompt_for_github_token; then
|
||||||
header=(-H "Authorization: token $GITHUB_TOKEN")
|
header=(-H "Authorization: token $GITHUB_TOKEN")
|
||||||
retry_delay=2
|
retry_delay=2
|
||||||
attempt=0
|
attempt=1
|
||||||
|
continue
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user