agent start fix
This commit is contained in:
parent
6a15b114e6
commit
f2dbfe5e4e
10 changed files with 110 additions and 62 deletions
|
|
@ -7,33 +7,63 @@ if not "%errorLevel%" == "0" (
|
|||
echo Failure: current permissions are inadequate.
|
||||
echo.
|
||||
echo Run this script with "Run as administrator".
|
||||
pause
|
||||
call :pause_on_error
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
set "WD=%~dp0"
|
||||
pushd "%WD%" >nul 2>&1
|
||||
|
||||
set "CYGWIN_ROOT=%WD%"
|
||||
if not exist "%CYGWIN_ROOT%OGP\ogp_agent.pl" (
|
||||
if exist "%WD%..\OGP\ogp_agent.pl" (
|
||||
for %%I in ("%WD%..") do set "CYGWIN_ROOT=%%~fI\"
|
||||
)
|
||||
)
|
||||
|
||||
set "BASH_EXE="
|
||||
if exist "%CYGWIN_ROOT%bin\bash.exe" set "BASH_EXE=%CYGWIN_ROOT%bin\bash.exe"
|
||||
if not defined BASH_EXE if exist "C:\cygwin64\bin\bash.exe" set "BASH_EXE=C:\cygwin64\bin\bash.exe"
|
||||
if not defined BASH_EXE if exist "C:\cygwin\bin\bash.exe" set "BASH_EXE=C:\cygwin\bin\bash.exe"
|
||||
set "CYGWIN_ROOT="
|
||||
|
||||
if exist "%WD%bin\bash.exe" (
|
||||
set "BASH_EXE=%WD%bin\bash.exe"
|
||||
set "CYGWIN_ROOT=%WD%"
|
||||
)
|
||||
if not defined BASH_EXE if exist "%WD%..\bin\bash.exe" (
|
||||
set "BASH_EXE=%WD%..\bin\bash.exe"
|
||||
for %%I in ("%WD%..") do set "CYGWIN_ROOT=%%~fI\"
|
||||
)
|
||||
if not defined BASH_EXE if exist "%WD%..\..\bin\bash.exe" (
|
||||
set "BASH_EXE=%WD%..\..\bin\bash.exe"
|
||||
for %%I in ("%WD%..\..") do set "CYGWIN_ROOT=%%~fI\"
|
||||
)
|
||||
if not defined BASH_EXE if exist "C:\OGP64\bin\bash.exe" (
|
||||
set "BASH_EXE=C:\OGP64\bin\bash.exe"
|
||||
set "CYGWIN_ROOT=C:\OGP64\"
|
||||
)
|
||||
if not defined BASH_EXE if exist "C:\cygwin64\bin\bash.exe" (
|
||||
set "BASH_EXE=C:\cygwin64\bin\bash.exe"
|
||||
set "CYGWIN_ROOT=C:\cygwin64\"
|
||||
)
|
||||
if not defined BASH_EXE if exist "C:\cygwin\bin\bash.exe" (
|
||||
set "BASH_EXE=C:\cygwin\bin\bash.exe"
|
||||
set "CYGWIN_ROOT=C:\cygwin\"
|
||||
)
|
||||
|
||||
if not defined BASH_EXE (
|
||||
echo Failure: Cygwin bash.exe was not found.
|
||||
echo.
|
||||
echo Checked:
|
||||
echo %CYGWIN_ROOT%bin\bash.exe
|
||||
echo %WD%bin\bash.exe
|
||||
echo %WD%..\bin\bash.exe
|
||||
echo %WD%..\..\bin\bash.exe
|
||||
echo C:\OGP64\bin\bash.exe
|
||||
echo C:\cygwin64\bin\bash.exe
|
||||
echo C:\cygwin\bin\bash.exe
|
||||
pause
|
||||
call :pause_on_error
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
if not exist "%CYGWIN_ROOT%OGP\ogp_agent.pl" (
|
||||
echo Failure: OGP agent root was not found for detected Cygwin root.
|
||||
echo.
|
||||
echo Detected Cygwin root:
|
||||
echo %CYGWIN_ROOT%
|
||||
echo Expected agent file:
|
||||
echo %CYGWIN_ROOT%OGP\ogp_agent.pl
|
||||
call :pause_on_error
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
|
|
@ -49,7 +79,7 @@ if not exist "%CYGWIN_ROOT%Install\agent_start_cygwin.sh" if not exist "%CYGWIN_
|
|||
echo Expected one of:
|
||||
echo %CYGWIN_ROOT%Install\agent_start_cygwin.sh
|
||||
echo %CYGWIN_ROOT%OGP\Install\agent_start_cygwin.sh
|
||||
pause
|
||||
call :pause_on_error
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
|
|
@ -71,9 +101,13 @@ if not "%AGENT_EXIT%" == "0" (
|
|||
echo.
|
||||
echo GSP Windows Agent exited with error code %AGENT_EXIT%.
|
||||
echo Review the messages above. The window is staying open so the failure is visible.
|
||||
pause
|
||||
call :pause_on_error
|
||||
exit /b %AGENT_EXIT%
|
||||
)
|
||||
|
||||
popd >nul 2>&1
|
||||
exit /b 0
|
||||
|
||||
:pause_on_error
|
||||
if /I not "%GSP_AGENT_NO_PAUSE%"=="1" pause
|
||||
exit /b 0
|
||||
|
|
|
|||
|
|
@ -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."
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue