diff --git a/Makefile b/Makefile index 342ae49..e7fe911 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,12 @@ VERSION = 0.1.0 all: build run +# Default build build: @if not exist $(BIN_DIR) mkdir $(BIN_DIR) - go build -ldflags "-s -w -X main.version=$(VERSION)" -o $(BIN_DIR)\$(APP_NAME).exe . + set CGO_ENABLED=0 && \ + set GOOS=windows && set GOARCH=amd64 && \ + go build -ldflags="-s -w -trimpath -X main.version=$(VERSION)" -o $(BIN_DIR)\$(APP_NAME).exe . run: go run . @@ -14,9 +17,12 @@ run: clean: @if exist $(BIN_DIR) rmdir /s /q $(BIN_DIR) +# Windows-specific optimized build windows: @if not exist $(BIN_DIR) mkdir $(BIN_DIR) - set GOOS=windows&& set GOARCH=amd64&& go build -o $(BIN_DIR)\$(APP_NAME).exe . + set CGO_ENABLED=0 && \ + set GOOS=windows && set GOARCH=amd64 && \ + go build -ldflags="-s -w -trimpath -X main.version=$(VERSION)" -o $(BIN_DIR)\$(APP_NAME).exe . tidy: go mod tidy diff --git a/bin/config.json b/bin/config.json new file mode 100644 index 0000000..d1c7a8d --- /dev/null +++ b/bin/config.json @@ -0,0 +1,5 @@ +{ + "update_url": "https://triztech.pro/cpanelwebcall/TOKEN", + "check_interval_seconds": 30, + "ip_check_url": "https://api.ipify.org" +} diff --git a/bin/install_ddnsupdater_service.bat b/bin/install_ddnsupdater_service.bat index 44b6c9f..f208821 100644 --- a/bin/install_ddnsupdater_service.bat +++ b/bin/install_ddnsupdater_service.bat @@ -1,23 +1,41 @@ @echo off +REM =============================== +REM DDNS Updater Install using NSSM +REM =============================== + REM Get the folder where this bat is located SET SCRIPT_DIR=%~dp0 -REM Define the service exe path (same folder as bat) +REM Define program and NSSM paths SET EXE_NAME=DDNSUpdater.exe SET EXE_PATH=%SCRIPT_DIR%%EXE_NAME% +SET NSSM_PATH=%SCRIPT_DIR%nssm.exe -REM Check if the exe exists +REM Check if files exist IF NOT EXIST "%EXE_PATH%" ( echo ERROR: %EXE_NAME% not found in the same folder as this script. pause exit /b 1 ) -REM Create the service (auto-start) -sc create DDNSUpdaterService binPath= "%EXE_PATH%" start= auto +IF NOT EXIST "%NSSM_PATH%" ( + echo ERROR: nssm.exe not found in the same folder as this script. + pause + exit /b 1 +) + +REM Remove existing service if present +"%NSSM_PATH%" remove DDNSUpdaterService confirm + +REM Install service +"%NSSM_PATH%" install DDNSUpdaterService "%EXE_PATH%" + +REM Optional: auto-start at boot +"%NSSM_PATH%" set DDNSUpdaterService Start SERVICE_AUTO_START REM Start the service -sc start DDNSUpdaterService +"%NSSM_PATH%" start DDNSUpdaterService -echo Service DDNSUpdaterService installed and started. +echo. +echo DDNSUpdaterService installed and started successfully! pause diff --git a/bin/nssm.exe b/bin/nssm.exe new file mode 100644 index 0000000..6ccfe3c Binary files /dev/null and b/bin/nssm.exe differ diff --git a/bin/uninstall_ddnsupdater_service.bat b/bin/uninstall_ddnsupdater_service.bat index 4e633f7..c119920 100644 --- a/bin/uninstall_ddnsupdater_service.bat +++ b/bin/uninstall_ddnsupdater_service.bat @@ -1,5 +1,21 @@ @echo off -sc stop DDNSUpdaterService -sc delete DDNSUpdaterService -echo Service DDNSUpdaterService stopped and deleted. +REM =============================== +REM DDNS Updater Uninstall using NSSM +REM =============================== + +SET SCRIPT_DIR=%~dp0 +SET NSSM_PATH=%SCRIPT_DIR%nssm.exe + +IF NOT EXIST "%NSSM_PATH%" ( + echo ERROR: nssm.exe not found in the same folder as this script. + pause + exit /b 1 +) + +REM Stop and remove the service +"%NSSM_PATH%" stop DDNSUpdaterService +"%NSSM_PATH%" remove DDNSUpdaterService confirm + +echo. +echo DDNSUpdaterService uninstalled successfully! pause