agent start fix

This commit is contained in:
Frank Harris 2026-06-07 17:21:32 -05:00
parent 6a15b114e6
commit f2dbfe5e4e
10 changed files with 110 additions and 62 deletions

View file

@ -62,6 +62,15 @@ ensure_default_configs() {
normalize_bash_preferences
}
validate_required_config() {
if [ ! -f "$AGENT_DIR/Cfg/Config.pm" ]; then
fail "Missing $AGENT_DIR/Cfg/Config.pm. Run agent_conf.sh or copy Config.pm.default and set the Panel agent key."
fi
if grep -Eq "CHANGE_ME_PANEL_AGENT_KEY|key[[:space:]]*=>[[:space:]]*''" "$AGENT_DIR/Cfg/Config.pm"; then
fail "$AGENT_DIR/Cfg/Config.pm still contains placeholder values. Set key/listen settings to match the Panel remote server record."
fi
}
load_agent_preferences() {
agent_auto_update=0
agent_update_repo_url="$REPO_URL_DEFAULT"
@ -166,26 +175,31 @@ auto_update_windows_agent() {
return 0
fi
if ! validate_agent_file "$target_file"; then
if [ -f "$target_file" ] && ! validate_agent_file "$target_file"; then
warn "Current Windows agent does not validate. Auto-update can still replace it if backup succeeds."
fi
cp "$target_file" "$backup_file" 2>/dev/null || {
warn "Could not backup $target_file; skipping auto-update."
rm -rf "$tmp_dir"
return 0
}
if [ -f "$target_file" ]; then
cp "$target_file" "$backup_file" 2>/dev/null || {
warn "Could not backup $target_file; skipping auto-update."
rm -rf "$tmp_dir"
return 0
}
else
warn "$target_file is missing; installing validated agent without a local backup."
backup_file=""
fi
if ! cp "$candidate_file" "$target_file"; then
warn "Could not copy updated Windows agent; restoring backup."
cp "$backup_file" "$target_file" 2>/dev/null
[ -n "$backup_file" ] && cp "$backup_file" "$target_file" 2>/dev/null
rm -rf "$tmp_dir"
return 0
fi
if ! validate_agent_file "$target_file"; then
warn "Updated Windows agent failed validation after install; restoring backup."
cp "$backup_file" "$target_file" 2>/dev/null
[ -n "$backup_file" ] && cp "$backup_file" "$target_file" 2>/dev/null
rm -rf "$tmp_dir"
return 0
fi
@ -202,6 +216,7 @@ normalize_text_files "/Install"
ensure_default_configs
load_agent_preferences
auto_update_windows_agent
validate_required_config
echo "Validating $AGENT_DIR/ogp_agent.pl..."
validate_agent_file "$AGENT_DIR/ogp_agent.pl" || fail "Perl syntax/dependency validation failed. Install missing Cygwin Perl packages or restore a valid Windows agent file."