Fix install-host-agent.sh function order, remove duplicate, and improve dev serving
This commit is contained in:
parent
4bf9c42dbc
commit
6e404b24eb
3 changed files with 46 additions and 1234 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -2,6 +2,7 @@ package api
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
|
|
@ -3389,7 +3390,19 @@ func (r *Router) handleDownloadHostAgentInstallScript(w http.ResponseWriter, req
|
|||
w.Header().Set("Expires", "0")
|
||||
|
||||
scriptPath := "/opt/pulse/scripts/install-host-agent.sh"
|
||||
http.ServeFile(w, req, scriptPath)
|
||||
content, err := os.ReadFile(scriptPath)
|
||||
if err != nil {
|
||||
// Fallback to project root (dev environment)
|
||||
scriptPath = filepath.Join(r.projectRoot, "scripts", "install-host-agent.sh")
|
||||
content, err = os.ReadFile(scriptPath)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("path", scriptPath).Msg("Failed to read host agent installer script")
|
||||
http.Error(w, "Failed to read installer script", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
http.ServeContent(w, req, "install-host-agent.sh", time.Now(), bytes.NewReader(content))
|
||||
}
|
||||
|
||||
// handleDownloadHostAgentInstallScriptPS serves the PowerShell installation script for Windows
|
||||
|
|
|
|||
|
|
@ -60,6 +60,38 @@ print_footer() {
|
|||
echo ""
|
||||
}
|
||||
|
||||
validate_agent_binary_executable() {
|
||||
local path="$1"
|
||||
local mount_opts=""
|
||||
|
||||
if command -v findmnt >/dev/null 2>&1; then
|
||||
mount_opts=$(findmnt -no OPTIONS --target "$path" 2>/dev/null || true)
|
||||
if echo "$mount_opts" | grep -Eq '(^|,)noexec(,|$)'; then
|
||||
log_error "Install target $path is on a filesystem mounted noexec (options: $mount_opts)"
|
||||
echo ""
|
||||
log_info "Enable exec on that dataset or choose an exec-capable path, then rerun the installer."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if command -v file >/dev/null 2>&1; then
|
||||
local file_type=""
|
||||
file_type=$(file -b "$path" 2>/dev/null || true)
|
||||
if [[ -n "$file_type" ]] && ! echo "$file_type" | grep -qiE 'ELF|Mach-O|PE32'; then
|
||||
log_error "Downloaded file at $path is not a recognizable executable (detected: $file_type)"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! "$path" --version >/dev/null 2>&1; then
|
||||
log_error "Installed agent at $path failed to execute; check for noexec mounts or download issues."
|
||||
if [[ -n "$mount_opts" ]]; then
|
||||
log_info "Filesystem options: $mount_opts"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Parse arguments
|
||||
PULSE_URL=""
|
||||
PULSE_TOKEN=""
|
||||
|
|
@ -467,37 +499,7 @@ fi
|
|||
MANUAL_START_CMD="$AGENT_CMD"
|
||||
MANUAL_START_WRAPPED="nohup $MANUAL_START_CMD >$LINUX_LOG_FILE 2>&1 &"
|
||||
|
||||
validate_agent_binary_executable() {
|
||||
local path="$1"
|
||||
local mount_opts=""
|
||||
|
||||
if command -v findmnt >/dev/null 2>&1; then
|
||||
mount_opts=$(findmnt -no OPTIONS --target "$path" 2>/dev/null || true)
|
||||
if echo "$mount_opts" | grep -Eq '(^|,)noexec(,|$)'; then
|
||||
log_error "Install target $path is on a filesystem mounted noexec (options: $mount_opts)"
|
||||
echo ""
|
||||
log_info "Enable exec on that dataset or choose an exec-capable path, then rerun the installer."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if command -v file >/dev/null 2>&1; then
|
||||
local file_type=""
|
||||
file_type=$(file -b "$path" 2>/dev/null || true)
|
||||
if [[ -n "$file_type" ]] && ! echo "$file_type" | grep -qiE 'ELF|Mach-O|PE32'; then
|
||||
log_error "Downloaded file at $path is not a recognizable executable (detected: $file_type)"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! "$path" --version >/dev/null 2>&1; then
|
||||
log_error "Installed agent at $path failed to execute; check for noexec mounts or download issues."
|
||||
if [[ -n "$mount_opts" ]]; then
|
||||
log_info "Filesystem options: $mount_opts"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
write_truenas_env_file() {
|
||||
sudo install -d -m 0700 "$TRUENAS_STATE_DIR" "$TRUENAS_LOG_DIR"
|
||||
|
|
|
|||
Loading…
Reference in a new issue