feat: add user confirmation prompt for pulse-sensor-proxy installation

Adds explicit user consent before installing pulse-sensor-proxy on the
Proxmox host, with support for noninteractive/scripted installations.

Changes:
- Add --proxy flag with yes/no/auto modes
- Add prompt_proxy_installation() function that explains what will be
  installed and asks for user confirmation
- Detect Docker in container and preselect 'yes' as default when found
- Support noninteractive mode via --proxy flag for automated installs
- Skip proxy installation if user declines or --proxy=no specified
- Auto-detect mode (--proxy=auto) installs only if Docker is present

Behavior:
- Default (no flag): Prompt user with explanation of what will be installed
- --proxy=yes: Install without prompting (for turnkey workflows)
- --proxy=no: Skip proxy installation entirely
- --proxy=auto: Install only if Docker is detected in container
- Docker detected: Default prompt answer changes to [Y/n] instead of [y/N]

When user declines, clear message explains temperature monitoring will
be unavailable and provides command to enable later.

This provides transparency about host-level changes while preserving
the turnkey workflow for automated/Docker installations.
This commit is contained in:
rcourtman 2025-10-19 16:13:46 +00:00
parent 171723a7d3
commit ee6d9d4877

View file

@ -25,6 +25,7 @@ ENABLE_AUTO_UPDATES=false
FORCE_VERSION="" FORCE_VERSION=""
FORCE_CHANNEL="" FORCE_CHANNEL=""
SOURCE_BRANCH="main" SOURCE_BRANCH="main"
PROXY_MODE="" # Can be: yes, no, auto, or empty (will prompt)
DEBIAN_TEMPLATE_FALLBACK="debian-12-standard_12.12-1_amd64.tar.zst" DEBIAN_TEMPLATE_FALLBACK="debian-12-standard_12.12-1_amd64.tar.zst"
DEBIAN_TEMPLATE="" DEBIAN_TEMPLATE=""
@ -145,6 +146,67 @@ print_warn() {
echo -e "${YELLOW}[WARN] $1${NC}" echo -e "${YELLOW}[WARN] $1${NC}"
} }
# Prompt user about proxy installation
# Returns 0 if user wants proxy, 1 if not
prompt_proxy_installation() {
local docker_detected="$1"
local default_choice="n"
# If Docker is detected, preselect yes
if [[ "$docker_detected" == "true" ]]; then
default_choice="y"
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " Temperature Monitoring Setup"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "Pulse can install a secure proxy service on the host to enable"
echo "temperature monitoring from within the container."
echo ""
echo "This will:"
echo " • Install pulse-sensor-proxy service on the Proxmox host"
echo " • Create bind mount for container communication"
echo " • Distribute SSH keys to cluster nodes"
echo " • Restart the container to activate"
echo ""
if [[ "$docker_detected" == "true" ]]; then
echo "${YELLOW}Docker detected - proxy is recommended for temperature monitoring${NC}"
echo ""
fi
# Determine prompt text based on default
if [[ "$default_choice" == "y" ]]; then
echo -n "Enable temperature monitoring? [Y/n]: "
else
echo -n "Enable temperature monitoring? [y/N]: "
fi
read -r response
# Handle empty response (use default)
if [[ -z "$response" ]]; then
response="$default_choice"
fi
# Normalize to lowercase
response=$(echo "$response" | tr '[:upper:]' '[:lower:]')
if [[ "$response" =~ ^(y|yes)$ ]]; then
echo ""
print_info "Temperature proxy will be installed"
return 0
else
echo ""
print_info "Skipping proxy installation"
print_info "Temperature monitoring from container will be unavailable"
print_info "To enable later, run: curl -fsSL https://raw.githubusercontent.com/rcourtman/Pulse/main/scripts/install-sensor-proxy.sh | bash -s -- --ctid <CTID>"
return 1
fi
}
ensure_debian_template() { ensure_debian_template() {
if [[ -n "$DEBIAN_TEMPLATE" ]]; then if [[ -n "$DEBIAN_TEMPLATE" ]]; then
return return
@ -1086,59 +1148,96 @@ create_lxc_container() {
# Get container IP # Get container IP
local IP=$(pct exec $CTID -- hostname -I | awk '{print $1}') local IP=$(pct exec $CTID -- hostname -I | awk '{print $1}')
# Install temperature proxy on host for secure monitoring # Determine if we should install temperature proxy
echo local install_proxy=false
print_info "Installing temperature monitoring proxy on host..." local docker_in_container=false
local proxy_script="/tmp/install-sensor-proxy-$$.sh"
# Download proxy installer # Check if Docker is installed in the container
if command -v timeout >/dev/null 2>&1; then if pct exec $CTID -- command -v docker >/dev/null 2>&1; then
if ! timeout 15 curl -fsSL --connect-timeout 5 --max-time 15 \ docker_in_container=true
"https://raw.githubusercontent.com/rcourtman/Pulse/main/scripts/install-sensor-proxy.sh" \
> "$proxy_script" 2>/dev/null; then
print_warn "Failed to download proxy installer - temperature monitoring unavailable"
print_info "Run manually later: curl -fsSL https://raw.githubusercontent.com/rcourtman/Pulse/main/scripts/install-sensor-proxy.sh | bash -s -- --ctid $CTID"
fi
else
if ! curl -fsSL --connect-timeout 5 --max-time 15 \
"https://raw.githubusercontent.com/rcourtman/Pulse/main/scripts/install-sensor-proxy.sh" \
> "$proxy_script" 2>/dev/null; then
print_warn "Failed to download proxy installer - temperature monitoring unavailable"
print_info "Run manually later: curl -fsSL https://raw.githubusercontent.com/rcourtman/Pulse/main/scripts/install-sensor-proxy.sh | bash -s -- --ctid $CTID"
fi
fi fi
# Run proxy installer if downloaded # Decide based on PROXY_MODE
if [[ -f "$proxy_script" ]]; then case "$PROXY_MODE" in
chmod +x "$proxy_script" yes)
install_proxy=true
# If building from source, copy the binary from the LXC instead of downloading ;;
local proxy_install_args="--ctid $CTID" no)
if [[ "$BUILD_FROM_SOURCE" == "true" ]]; then install_proxy=false
local local_proxy_binary="/tmp/pulse-sensor-proxy-$CTID" ;;
print_info "Copying locally-built pulse-sensor-proxy binary from container..." auto)
if pct pull $CTID /opt/pulse/bin/pulse-sensor-proxy "$local_proxy_binary" 2>/dev/null; then # Auto-detect: install if Docker is present
proxy_install_args="--ctid $CTID --local-binary $local_proxy_binary" if [[ "$docker_in_container" == "true" ]]; then
print_info "Using locally-built binary from container" install_proxy=true
else else
print_warn "Failed to copy binary from container, will try fallback download" install_proxy=false
export PULSE_SENSOR_PROXY_FALLBACK_URL="http://${IP}:${frontend_port}/api/install/pulse-sensor-proxy" fi
;;
*)
# Empty/unset - prompt the user
if prompt_proxy_installation "$docker_in_container"; then
install_proxy=true
else
install_proxy=false
fi
;;
esac
# Install temperature proxy on host for secure monitoring (if enabled)
if [[ "$install_proxy" == "true" ]]; then
echo
print_info "Installing temperature monitoring proxy on host..."
local proxy_script="/tmp/install-sensor-proxy-$$.sh"
# Download proxy installer
if command -v timeout >/dev/null 2>&1; then
if ! timeout 15 curl -fsSL --connect-timeout 5 --max-time 15 \
"https://raw.githubusercontent.com/rcourtman/Pulse/main/scripts/install-sensor-proxy.sh" \
> "$proxy_script" 2>/dev/null; then
print_warn "Failed to download proxy installer - temperature monitoring unavailable"
print_info "Run manually later: curl -fsSL https://raw.githubusercontent.com/rcourtman/Pulse/main/scripts/install-sensor-proxy.sh | bash -s -- --ctid $CTID"
fi fi
else else
# For release installs, set fallback URL to download from Pulse server inside the LXC if ! curl -fsSL --connect-timeout 5 --max-time 15 \
export PULSE_SENSOR_PROXY_FALLBACK_URL="http://${IP}:${frontend_port}/api/install/pulse-sensor-proxy" "https://raw.githubusercontent.com/rcourtman/Pulse/main/scripts/install-sensor-proxy.sh" \
> "$proxy_script" 2>/dev/null; then
print_warn "Failed to download proxy installer - temperature monitoring unavailable"
print_info "Run manually later: curl -fsSL https://raw.githubusercontent.com/rcourtman/Pulse/main/scripts/install-sensor-proxy.sh | bash -s -- --ctid $CTID"
fi
fi fi
if bash "$proxy_script" $proxy_install_args 2>&1 | tee /tmp/proxy-install-${CTID}.log; then # Run proxy installer if downloaded
print_info "Temperature proxy installed successfully" if [[ -f "$proxy_script" ]]; then
# Clean up temporary binary if it was copied chmod +x "$proxy_script"
[[ -f "$local_proxy_binary" ]] && rm -f "$local_proxy_binary"
else # If building from source, copy the binary from the LXC instead of downloading
print_warn "Proxy installation failed - temperature monitoring will use fallback method" local proxy_install_args="--ctid $CTID"
print_info "Check logs: /tmp/proxy-install-${CTID}.log" if [[ "$BUILD_FROM_SOURCE" == "true" ]]; then
print_info "Or run manually: curl -fsSL https://raw.githubusercontent.com/rcourtman/Pulse/main/scripts/install-sensor-proxy.sh | bash -s -- --ctid $CTID" local local_proxy_binary="/tmp/pulse-sensor-proxy-$CTID"
print_info "Copying locally-built pulse-sensor-proxy binary from container..."
if pct pull $CTID /opt/pulse/bin/pulse-sensor-proxy "$local_proxy_binary" 2>/dev/null; then
proxy_install_args="--ctid $CTID --local-binary $local_proxy_binary"
print_info "Using locally-built binary from container"
else
print_warn "Failed to copy binary from container, will try fallback download"
export PULSE_SENSOR_PROXY_FALLBACK_URL="http://${IP}:${frontend_port}/api/install/pulse-sensor-proxy"
fi
else
# For release installs, set fallback URL to download from Pulse server inside the LXC
export PULSE_SENSOR_PROXY_FALLBACK_URL="http://${IP}:${frontend_port}/api/install/pulse-sensor-proxy"
fi
if bash "$proxy_script" $proxy_install_args 2>&1 | tee /tmp/proxy-install-${CTID}.log; then
print_info "Temperature proxy installed successfully"
# Clean up temporary binary if it was copied
[[ -f "$local_proxy_binary" ]] && rm -f "$local_proxy_binary"
else
print_warn "Proxy installation failed - temperature monitoring will use fallback method"
print_info "Check logs: /tmp/proxy-install-${CTID}.log"
print_info "Or run manually: curl -fsSL https://raw.githubusercontent.com/rcourtman/Pulse/main/scripts/install-sensor-proxy.sh | bash -s -- --ctid $CTID"
fi
rm -f "$proxy_script"
fi fi
rm -f "$proxy_script"
fi fi
# Clean final output # Clean final output
@ -2863,6 +2962,14 @@ while [[ $# -gt 0 ]]; do
ENABLE_AUTO_UPDATES=true ENABLE_AUTO_UPDATES=true
shift shift
;; ;;
--proxy)
PROXY_MODE="$2"
if [[ ! "$PROXY_MODE" =~ ^(yes|no|auto)$ ]]; then
print_error "Invalid --proxy value: $PROXY_MODE (must be yes, no, or auto)"
exit 1
fi
shift 2
;;
--main|--source|--from-source|--branch) --main|--source|--from-source|--branch)
BUILD_FROM_SOURCE=true BUILD_FROM_SOURCE=true
# Optional: specify branch # Optional: specify branch
@ -2884,6 +2991,11 @@ while [[ $# -gt 0 ]]; do
echo " --main Build and install from main branch source" echo " --main Build and install from main branch source"
echo " --source [BRANCH] Build and install from source (default: main)" echo " --source [BRANCH] Build and install from source (default: main)"
echo " --enable-auto-updates Enable automatic stable updates (via systemd timer)" echo " --enable-auto-updates Enable automatic stable updates (via systemd timer)"
echo " --proxy MODE Control temperature proxy installation (yes/no/auto)"
echo " yes: Install without prompting"
echo " no: Skip proxy installation"
echo " auto: Auto-detect (install if Docker present)"
echo " (default: prompt user for LXC installations)"
echo "" echo ""
echo "Management options:" echo "Management options:"
echo " --reset Reset Pulse to fresh configuration" echo " --reset Reset Pulse to fresh configuration"