Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/verify-split-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ on:
- "tests/mongodb-upgrade.sh"
- "tests/uv-required-version.sh"
- "tests/docker-lxcfs.sh"
- "tests/external-installer.sh"
- ".github/workflows/verify-split-files.yml"
push:
branches: [main]
Expand All @@ -47,6 +48,7 @@ on:
- "tests/mongodb-upgrade.sh"
- "tests/uv-required-version.sh"
- "tests/docker-lxcfs.sh"
- "tests/external-installer.sh"
- ".github/workflows/verify-split-files.yml"
workflow_dispatch:

Expand Down Expand Up @@ -86,6 +88,9 @@ jobs:
- name: Docker lxcfs visibility regression tests
run: bash tests/docker-lxcfs.sh

- name: External installer confirmation tests
run: bash tests/external-installer.sh

- name: Prefetch lists cover every engine file
run: |
set -euo pipefail
Expand Down
28 changes: 28 additions & 0 deletions core/core.func
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,34 @@ prompt_confirm() {
fi
}

# ------------------------------------------------------------------------------
# confirm_external_installer()
#
# confirm_external_installer <source> <installer>
#
# - Warns that a third-party installer is about to run and asks to continue
# - var_external_installer answers it, so unattended runs can say yes or no.
# prompt_confirm is no use here: it takes its default without asking in
# every non-advanced mode, and the default has to be no
# - Exits 10 when declined
# ------------------------------------------------------------------------------
confirm_external_installer() {
local source="$1" installer="$2" answer="${var_external_installer:-}"
msg_warn "WARNING: This script will run an external installer from a third-party source (${source})."
msg_warn "The following code is NOT maintained or audited by our repository."
msg_warn "If you have any doubts or concerns, please review the installer code before proceeding:"
msg_custom "${TAB3}${GATEWAY}${BGN}${CL}" "\e[1;34m" "→ ${installer}"
echo
if [[ -z "$answer" ]] && ! read -r -p "${TAB3}Do you want to continue? [y/N]: " answer; then
msg_error "No terminal to confirm on. Set var_external_installer=yes to run it unattended."
exit 10
fi
if [[ ! "${answer,,}" =~ ^(y|yes|true)$ ]]; then
msg_error "Aborted by user. No changes have been made."
exit 10
fi
}

# ------------------------------------------------------------------------------
# prompt_input()
#
Expand Down
48 changes: 48 additions & 0 deletions tests/external-installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
set -euo pipefail

CORE_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
eval "$(awk '/^confirm_external_installer\(\) \{/,/^}/' "$CORE_DIR/core/core.func")"

msg_warn() { :; }
msg_custom() { :; }
msg_error() { echo "$*" >&2; }
# shellcheck disable=SC2034 # read by the eval'd helper
TAB3="" GATEWAY="" BGN="" CL=""
passed=0 failed=0

check() {
if [[ "$3" == "$2" ]]; then
echo "PASS $1"
passed=$((passed + 1))
else
echo "FAIL $1: expected <$2>, got <$3>" >&2
failed=$((failed + 1))
fi
}
# exit code of one call; $1 is var_external_installer, $2 what the user types
run() {
local rc=0
(var_external_installer="$1" confirm_external_installer src url) <<<"$2" >/dev/null 2>&1 || rc=$?
echo "$rc"
}
# no stdin at all, as in an unattended run without the variable
run_eof() {
local rc=0
(var_external_installer="" confirm_external_installer src url) </dev/null >/dev/null 2>&1 || rc=$?
echo "$rc"
}

check "var yes" 0 "$(run yes "")"
check "var YES" 0 "$(run YES "")"
check "var true" 0 "$(run true "")"
check "var no" 10 "$(run no "y")"
check "var wins over input" 10 "$(run no "yes")"
check "typed y" 0 "$(run "" y)"
check "typed Yes" 0 "$(run "" Yes)"
check "typed n" 10 "$(run "" n)"
check "just enter" 10 "$(run "" "")"
check "no stdin" 10 "$(run_eof)"

printf '%s passed, %s failed\n' "$passed" "$failed"
((failed == 0))
1 change: 1 addition & 0 deletions ui/API.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ color
color_spinner
configure_http_proxy
configure_ssh_settings
confirm_external_installer
confirm_not_pve_host
cs_testing_state
default_var_settings
Expand Down
Loading