Compare commits
30 Commits
Author | SHA1 | Date | |
---|---|---|---|
25ed1ecf9b | |||
530e59e3e1 | |||
a156ae0c08 | |||
531b39db5d | |||
33e1ef965b | |||
f3606631a0 | |||
84ed566c55 | |||
c4c5f2841c | |||
0ecaefeb10 | |||
43a65926fe | |||
24a6e7678e | |||
ae01d517d8 | |||
581e856e50 | |||
5e062cc429 | |||
0c93030488 | |||
7b871edada | |||
58fb7067eb | |||
2ae4d963ea | |||
09ce390537 | |||
edc1df0bbd | |||
9706917679 | |||
f3d3a8472e | |||
39c458f321 | |||
683095b6d7 | |||
281b3ce27d | |||
3b730c162b | |||
39069fe26d | |||
9e6ba0da51 | |||
f5808f4461 | |||
ab8abaee85 |
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/*.pdf
|
||||||
|
/*.zip
|
||||||
|
*.exe
|
141
README.md
141
README.md
@@ -1,21 +1,142 @@
|
|||||||
# Install Beszel Agent As Service Under Windows
|
# BeszelWin
|
||||||
|
|
||||||
The Windows *cmd* file `install-beszel-service.cmd` installs the [Beszel](https://beszel.dev) agent as a service under Microsoft Windows.
|
A collection of four scripts to build, install, update or uninstall the [Beszel](https://beszel.dev) agent under Microsoft Windows, inspired by [*Using Beszel to monitor Windows*](https://blog.ktz.me/using-beszel-to-monitor-windows/) and a [video](https://youtu.be/O_9wT-5LoHM) on the *Tailscale* channel by Alex Kretschmar.
|
||||||
|
|
||||||
## Usage
|
## (1) Building the executable
|
||||||
|
|
||||||
Open a `cmd.exe` shell with administrative rights.
|
### Prerequisites
|
||||||
|
|
||||||
|
- Microsoft Windows 10 or later **Client** OS (64 bit)
|
||||||
|
|
||||||
|
*Building under Windows Server OS should be working, but you have to install Go and Git manually as Winget is not available for Windows server operating systems.*
|
||||||
|
|
||||||
|
### Compiling
|
||||||
|
|
||||||
|
Download and extract [install-beszel-service.zip](https://gitea.elpatron.me/elpatron/Install-Beszel-Agent/releases/latest).
|
||||||
|
|
||||||
|
Open a `cmd.exe` shell, `cd` into the script directory (where you extracted the archive) and start the build-script:
|
||||||
|
|
||||||
|
```
|
||||||
|
.\build_agent.cmd
|
||||||
|
```
|
||||||
|
|
||||||
|
The script will install *Git* and *Go* (if not yet installed) with *Winget*, clone the *Beszel* repository and build a Windows 64 bit `agent.exe` binary.
|
||||||
|
|
||||||
|
```
|
||||||
|
C:\Users\User\Downloads\install-beszel-service>build_agent.cmd
|
||||||
|
This script downloads the Beszel repository and builds the Beszel agent for Windows (64 Bit only).
|
||||||
|
If not yet installed, Git and Go will be installed via Winget.
|
||||||
|
|
||||||
|
Winget executable found
|
||||||
|
Installing Go with Winget
|
||||||
|
Installing Git with Winget
|
||||||
|
Refreshing environment variables from registry for cmd.exe. Please wait...Finished..
|
||||||
|
Cloning Beszel repository
|
||||||
|
Building agent
|
||||||
|
Build successful
|
||||||
|
Beszel agent.exe was built and copied, you can proceed with 'install-beszel-service.cmd'.
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## (2) Installing the service
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
- Microsoft Windows 10 or later - *Server OS should work, too*
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
Open a `cmd.exe` shell with **administrative rights** and `cd` into the script directory (where you extracted the archive).
|
||||||
|
|
||||||
|
If you have built the agent by yourself: Copy your `agent.exe` binary to the directory where you extracted the scripts. Overwrite `agent.exe` from the archive.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```
|
||||||
|
copy /y .\beszel\beszel\cmd\agent\agent.exe .
|
||||||
|
```
|
||||||
|
|
||||||
|
Start the installation script provided with your Beszel Ssh key:
|
||||||
|
|
||||||
````
|
````
|
||||||
git clone https://gitea.elpatron.me/elpatron/Install-Beszel-Agent
|
|
||||||
cd Install-Beszel-Agent
|
|
||||||
.\install-beszel-service.cmd <your Beszel ssh key>
|
.\install-beszel-service.cmd <your Beszel ssh key>
|
||||||
````
|
````
|
||||||
|
|
||||||
## Explanation
|
The script copies `agent.exe` into the directory `%ProgramFiles%\BeszelAgent` and takes usage of *[NSSM - the Non-Sucking Service Manager](https://nssm.cc/)* to install the service. If *NSSM* is not yet installed on your system, it will be downloaded and installed to the Beszel agent directory.
|
||||||
|
|
||||||
The script copies `agent.exe` into the directory `%ProgramFiles%\BeszelAgent` and takes usage of *[NSSM - the Non-Sucking Service Manager](https://nssm.cc/)* to install the service. *NSSM* is being installed by *[Winget](https://github.com/microsoft/winget-cli)*.
|
The provided `agent.exe` was compiled on January, 17th 2025 by me and should be exchanged by a self compiled or official executable, see *(1) Building the executable*.
|
||||||
|
|
||||||
The provided `agent.exe` was compiled on January, 18th 2025 by me and should be exchanged by a self compiled or official executable.
|
|
||||||
|
|
||||||
For more details, see [*Using Beszel to monitor Windows*](https://blog.ktz.me/using-beszel-to-monitor-windows/) by Alex Kretschmar.
|
For more details, see [*Using Beszel to monitor Windows*](https://blog.ktz.me/using-beszel-to-monitor-windows/) by Alex Kretschmar.
|
||||||
|
|
||||||
|
```
|
||||||
|
C:\Users\User\Downloads\install-beszel-service>install-beszel-service.cmd ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJwRj3l7U9QUJM2K8p2mkH8KDJmhpMwejuPci4LtGxEz
|
||||||
|
This script installs the Beszel agent for Windows.
|
||||||
|
If not yet installed, NSSM will be installed via Winget.
|
||||||
|
|
||||||
|
Checking adminstrative rights
|
||||||
|
Administrative rights check OK
|
||||||
|
Creating directory C:\Program Files\BeszelAgent
|
||||||
|
Downloading NSSM
|
||||||
|
Extracting ZIP file
|
||||||
|
Copying nssm.exe to C:\Program Files\BeszelAgent
|
||||||
|
Deleting temporary files and directories
|
||||||
|
Copying agent.exe to C:\Program Files\BeszelAgent
|
||||||
|
Adding firewall rule
|
||||||
|
Installing service BeszelAgent
|
||||||
|
Setting environment for BeszelAgent
|
||||||
|
Starting BeszelAgent
|
||||||
|
BeszelAgent: START: The operation completed successfully.
|
||||||
|
Display service status
|
||||||
|
NSSM dump:
|
||||||
|
^"^\^"C:^\Program Files^\BeszelAgent^\nssm.exe^\^"^" install BeszelAgent "C:\Program Files\BeszelAgent\agent.exe"
|
||||||
|
^"^\^"C:^\Program Files^\BeszelAgent^\nssm.exe^\^"^" set BeszelAgent AppDirectory "C:\Program Files\BeszelAgent"
|
||||||
|
^"^\^"C:^\Program Files^\BeszelAgent^\nssm.exe^\^"^" set BeszelAgent AppExit Default Restart
|
||||||
|
^"^\^"C:^\Program Files^\BeszelAgent^\nssm.exe^\^"^" set BeszelAgent AppEnvironmentExtra ":KEY=ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJwRj3l7U9QUJM2K8p2mkH8KDJmhpMwejuPci4LtGxEz"
|
||||||
|
^"^\^"C:^\Program Files^\BeszelAgent^\nssm.exe^\^"^" set BeszelAgent DisplayName BeszelAgent
|
||||||
|
^"^\^"C:^\Program Files^\BeszelAgent^\nssm.exe^\^"^" set BeszelAgent ObjectName LocalSystem
|
||||||
|
^"^\^"C:^\Program Files^\BeszelAgent^\nssm.exe^\^"^" set BeszelAgent Start SERVICE_AUTO_START
|
||||||
|
^"^\^"C:^\Program Files^\BeszelAgent^\nssm.exe^\^"^" set BeszelAgent Type SERVICE_WIN32_OWN_PROCESS
|
||||||
|
Wait 5 seconds, check service status
|
||||||
|
SERVICE_RUNNING
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## (3) Updating the service
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
- To update the Beszel agent, it has to be installed using the install script.
|
||||||
|
|
||||||
|
### Updating
|
||||||
|
|
||||||
|
Open a `cmd.exe` shell with **administrative rights** and `cd` into the script directory (where you extracted the archive).
|
||||||
|
|
||||||
|
Start the update by launching
|
||||||
|
|
||||||
|
```
|
||||||
|
.\update_agent.cmd
|
||||||
|
```
|
||||||
|
|
||||||
|
The update will make a fresh clone of the Beszel GitHub repository, build the executable, stop the agent service, copy the new `agent.exe` to `%ProgramFiles%\BeszelAgent` and start the service.
|
||||||
|
|
||||||
|
## (4) Uninstall the service
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
- To uninstall the Beszel agent, it has to be installed using the install script.
|
||||||
|
|
||||||
|
### Uninstalling
|
||||||
|
|
||||||
|
Open a `cmd.exe` shell with **administrative rights**.
|
||||||
|
|
||||||
|
Start the update by launching
|
||||||
|
|
||||||
|
```
|
||||||
|
.\uninstall_agent.cmd
|
||||||
|
```
|
||||||
|
|
||||||
|
The script will stop and remove the Beszel service and delete the installation directory `%ProgramFiles%\BeszelAgent`.
|
67
build_agent.cmd
Normal file
67
build_agent.cmd
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
@echo off
|
||||||
|
cd /D "%~dp0"
|
||||||
|
echo This script downloads the Beszel repository and builds the Beszel agent for Windows (64 Bit only).
|
||||||
|
echo If not yet installed, Git and Go will be installed via Winget.
|
||||||
|
echo.
|
||||||
|
|
||||||
|
call env.cmd
|
||||||
|
set REFRESHENV=0
|
||||||
|
|
||||||
|
where winget.exe >nul 2>&1
|
||||||
|
if %errorlevel% NEQ 0 (
|
||||||
|
echo Winget not found, install Winget or use a compatible OS: Win 10 Client OS or later
|
||||||
|
goto end
|
||||||
|
) else (
|
||||||
|
echo Winget executable found
|
||||||
|
)
|
||||||
|
|
||||||
|
where go.exe >nul 2>&1
|
||||||
|
if %errorlevel% NEQ 0 (
|
||||||
|
echo Installing Go with Winget
|
||||||
|
winget install GoLang.Go --accept-source-agreements --accept-package-agreements >nul 2>&1
|
||||||
|
set REFRESHENV=1
|
||||||
|
) else (
|
||||||
|
echo Go executable found
|
||||||
|
)
|
||||||
|
|
||||||
|
where git.exe >nul 2>&1
|
||||||
|
if %errorlevel% NEQ 0 (
|
||||||
|
echo Installing Git with Winget
|
||||||
|
winget install Git.Git --accept-source-agreements --accept-package-agreements >nul 2>&1
|
||||||
|
set REFRESHENV=1
|
||||||
|
) else (
|
||||||
|
echo Git executable found
|
||||||
|
)
|
||||||
|
|
||||||
|
if %REFRESHENV% EQU 1 call .\RefreshEnv.cmd
|
||||||
|
|
||||||
|
echo Cloning Beszel repository
|
||||||
|
git clone https://github.com/henrygd/beszel.git >nul 2>&1
|
||||||
|
if %errorlevel% NEQ 0 (
|
||||||
|
echo Cloning the Beszel repository failed.
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
cd .\beszel\beszel\cmd\agent
|
||||||
|
|
||||||
|
echo Building agent
|
||||||
|
go build -ldflags "-w -s" . >nul 2>&1
|
||||||
|
if %errorlevel% NEQ 0 (
|
||||||
|
echo Something went wrong
|
||||||
|
) else (
|
||||||
|
echo Build was successful
|
||||||
|
cd /D "%~dp0"
|
||||||
|
copy /y .\beszel\beszel\cmd\agent\agent.exe . >nul 2>&1
|
||||||
|
echo Beszel agent.exe was built and copied, you can proceed with 'install-beszel-service.cmd'.
|
||||||
|
rd /s/q .\beszel >nul 2>&1
|
||||||
|
echo Cloned Beszel repository was deleted as we don´t need it anymore.
|
||||||
|
echo.
|
||||||
|
echo You can go ahead with .\install-beszel-service.cmd to install the service.
|
||||||
|
echo .
|
||||||
|
echo If Git ond/or Go was installed from this script and you don´t want to keep them, use
|
||||||
|
echo winget uninstall GoLang.Go
|
||||||
|
echo winget uninstall Git.Git
|
||||||
|
echo to remove the corresponding packages.
|
||||||
|
)
|
||||||
|
|
||||||
|
:end
|
8
env.cmd
Normal file
8
env.cmd
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
@echo off
|
||||||
|
set SERVICENAME=BeszelAgent
|
||||||
|
set DESTINATIONDIR=%ProgramFiles%\%SERVICENAME%
|
||||||
|
set AGENTEXE=%DESTINATIONDIR%\agent.exe
|
||||||
|
set NSSMEXE=nssm.exe
|
||||||
|
set GOOS=windows
|
||||||
|
set GOARCH=amd64
|
||||||
|
set CGO_ENABLED=0
|
@@ -1,57 +1,81 @@
|
|||||||
@echo off
|
@echo off
|
||||||
cd /D "%~dp0"
|
cd /D "%~dp0"
|
||||||
|
echo This script installs the Beszel agent for Windows.
|
||||||
|
echo If not yet installed, NSSM will be installed via Winget.
|
||||||
|
echo.
|
||||||
|
|
||||||
|
echo Checking adminstrative rights
|
||||||
|
rem from https://stackoverflow.com/questions/7985755/how-to-detect-if-cmd-is-running-as-administrator-has-elevated-privileges
|
||||||
|
net session >nul 2>&1
|
||||||
|
if %errorlevel% equ 0 (
|
||||||
|
echo Administrative rights check OK
|
||||||
|
) else (
|
||||||
|
echo You are NOT Administrator. Start the script from an administrative cmd.exe shell...
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
if !%1==! goto help
|
if !%1==! goto help
|
||||||
if !%2==! goto help
|
if !%2==! goto help
|
||||||
|
|
||||||
set BESZELKEYPREFIX=%1
|
set BESZELKEYPREFIX=%1
|
||||||
set BESZELKEY=%2
|
set BESZELKEY=%2
|
||||||
set SERVICENAME=BeszelAgent
|
call env.cmd
|
||||||
set DESTINATIONDIR=%ProgramFiles%\%SERVICENAME%
|
|
||||||
set AGENTEXE=%DESTINATIONDIR%\agent.exe
|
echo Creating directory %DESTINATIONDIR%
|
||||||
set NSSMEXE=nssm.exe
|
md "%DESTINATIONDIR%" >nul 2>&1
|
||||||
|
|
||||||
where nssm.exe >nul 2>&1
|
where nssm.exe >nul 2>&1
|
||||||
if %errorlevel%==1 goto installnssm
|
if %errorlevel% NEQ 0 goto installnssm
|
||||||
goto proceed
|
goto proceed
|
||||||
|
|
||||||
:installnssm
|
:installnssm
|
||||||
echo Downloading NSSM
|
echo Downloading NSSM
|
||||||
curl.exe --output "%TEMP%\nssm-2.24.zip" --url https://nssm.cc/release/nssm-2.24.zip >nul 2>&1
|
curl.exe --output "%TEMP%\nssm-2.24.zip" --url https://nssm.cc/ci/nssm-2.24-101-g897c7ad.zip >nul 2>&1
|
||||||
echo Extracting ZIP file
|
echo Extracting ZIP file
|
||||||
tar.exe -xf %TEMP%\nssm-2.24.zip
|
tar.exe -xf %TEMP%\nssm-2.24.zip >nul 2>&1
|
||||||
echo Copying nssm.exe to %DESTINATIONDIR%
|
echo Copying nssm.exe to %DESTINATIONDIR%
|
||||||
if %PROCESSOR_ARCHITECTURE%==AMD64 (
|
copy .\nssm-2.24-101-g897c7ad\win64\nssm.exe "%DESTINATIONDIR%\" >nul 2>&1
|
||||||
copy .\nssm-2.24\win64\nssm.exe "%DESTINATIONDIR%\" >nul 2>&1
|
|
||||||
) else (
|
|
||||||
copy .\nssm-2.24\win32\nssm.exe "%DESTINATIONDIR%\" >nul 2>&1
|
|
||||||
)
|
|
||||||
set NSSMEXE="%DESTINATIONDIR%\nssm.exe"
|
set NSSMEXE="%DESTINATIONDIR%\nssm.exe"
|
||||||
echo Deleting temporary files and directories
|
echo Deleting temporary files and directories
|
||||||
del "%TEMP%\nssm-2.24.zip" >nul 2>&1
|
del "%TEMP%\nssm-2.24.zip" >nul 2>&1
|
||||||
rd /s/q .\nssm-2.24 >nul 2>&1
|
rd /s/q .\nssm-2.24 >nul 2>&1
|
||||||
|
|
||||||
:proceed
|
:proceed
|
||||||
echo Creating deirectory %DESTINATIONDIR%
|
echo Copying agent.exe to %DESTINATIONDIR%
|
||||||
md "%DESTINATIONDIR%" >nul 2>&1
|
|
||||||
|
|
||||||
echo Copying agent.exe
|
|
||||||
copy .\agent.exe "%DESTINATIONDIR%\" >nul 2>&1
|
copy .\agent.exe "%DESTINATIONDIR%\" >nul 2>&1
|
||||||
|
|
||||||
echo Adding firewall rule
|
echo Adding firewall rule
|
||||||
netsh advfirewall firewall add rule name="%SERVICENAME%" dir=in action=allow program="%AGENTEXE%" enable=yes >nul 2>&1
|
netsh advfirewall firewall add rule name="%SERVICENAME%" dir=in action=allow program="%AGENTEXE%" enable=yes >nul 2>&1
|
||||||
|
|
||||||
echo Installing service
|
echo Installing service %SERVICENAME%
|
||||||
%NSSMEXE% install %SERVICENAME% "%AGENTEXE%" >nul 2>&1
|
%NSSMEXE% install %SERVICENAME% "%AGENTEXE%" >nul 2>&1
|
||||||
|
if %errorlevel% NEQ 0 (
|
||||||
|
echo Failed to install the service.
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Setting environment for %SERVICENAME%
|
||||||
%NSSMEXE% set %SERVICENAME% AppEnvironmentExtra "KEY=%BESZELKEYPREFIX% %BESZELKEY%" >nul 2>&1
|
%NSSMEXE% set %SERVICENAME% AppEnvironmentExtra "KEY=%BESZELKEYPREFIX% %BESZELKEY%" >nul 2>&1
|
||||||
|
if %errorlevel% NEQ 0 (
|
||||||
|
echo Failed to set the service environment.
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
echo Setting environment for service
|
echo Starting %SERVICENAME%
|
||||||
%NSSMEXE% start %SERVICENAME% >nul 2>&1
|
%NSSMEXE% start %SERVICENAME%
|
||||||
|
if %errorlevel% NEQ 0 (
|
||||||
|
echo Check output above.
|
||||||
|
)
|
||||||
|
|
||||||
echo Service installed, status:
|
echo NSSM dump:
|
||||||
%NSSMEXE% dump %SERVICENAME%
|
%NSSMEXE% dump %SERVICENAME%
|
||||||
|
echo Wait 5 seconds, then check service status
|
||||||
|
ping 127.0.0.1 -n 5 >nul 2>&1
|
||||||
|
%NSSMEXE% status %SERVICENAME%
|
||||||
goto end
|
goto end
|
||||||
|
|
||||||
:help
|
:help
|
||||||
echo You have to provide a Beszel ssh key, e.g. 'install-beszel-service.cmd ssh-ed25519 AAAAC3L3lIpn94iu2TIpdmneXsEC1TDvrg4HCNoM1aiC683WMZfGOVoatrJSkysaQB9K
|
echo You have to provide a Beszel ssh key, e.g. 'install-beszel-service.cmd ssh-ed25519 AAAAC3L3lIpn94iu2TIpdmneXsEC1TDvrg4HCNoM1aiC683WMZfGOVoatrJSkysaQB9K
|
||||||
echo The key must not be enclosed in "" or '', just copy and paste it as it is.
|
echo The key must not be enclosed in "" or '', just copy and paste it as it is.
|
||||||
|
|
||||||
:end
|
:end
|
29
uninstall_agent.cmd
Normal file
29
uninstall_agent.cmd
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
@echo off
|
||||||
|
setlocal
|
||||||
|
cd /D "%~dp0"
|
||||||
|
echo This script uninstalls the Beszel agent
|
||||||
|
echo.
|
||||||
|
|
||||||
|
call env.cmd
|
||||||
|
|
||||||
|
echo Checking adminstrative rights
|
||||||
|
rem from https://stackoverflow.com/questions/7985755/how-to-detect-if-cmd-is-running-as-administrator-has-elevated-privileges
|
||||||
|
net session >nul 2>&1
|
||||||
|
if %errorlevel% equ 0 (
|
||||||
|
echo Administrative rights check OK
|
||||||
|
) else (
|
||||||
|
echo You are NOT Administrator. Start the script from an administrative cmd.exe shell...
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Stopping Beszel agent service
|
||||||
|
%NSSMEXE% stop %SERVICENAME% >nul 2>&1
|
||||||
|
|
||||||
|
echo Removing Beszel agent service
|
||||||
|
%NSSMEXE% remove %SERVICENAME% >nul 2>&1
|
||||||
|
|
||||||
|
echo Deleting installation directory
|
||||||
|
rd /q/s %DESTINATIONDIR% >nul 2>&1
|
||||||
|
|
||||||
|
:end
|
||||||
|
ech Done.
|
97
update_agent.cmd
Normal file
97
update_agent.cmd
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
@echo off
|
||||||
|
setlocal
|
||||||
|
cd /D "%~dp0"
|
||||||
|
echo This script updates the Beszel agent to the latest version from the Github repository
|
||||||
|
echo.
|
||||||
|
|
||||||
|
echo Checking adminstrative rights
|
||||||
|
rem from https://stackoverflow.com/questions/7985755/how-to-detect-if-cmd-is-running-as-administrator-has-elevated-privileges
|
||||||
|
net session >nul 2>&1
|
||||||
|
if %errorlevel% equ 0 (
|
||||||
|
echo Administrative rights check OK
|
||||||
|
) else (
|
||||||
|
echo You are NOT Administrator. Start the script from an administrative cmd.exe shell...
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
call env.cmd
|
||||||
|
|
||||||
|
where winget.exe >nul 2>&1
|
||||||
|
if %errorlevel% NEQ 0 (
|
||||||
|
echo Winget not found, install Winget or use a compatible OS: Win 10 Client OS or later
|
||||||
|
goto end
|
||||||
|
) else (
|
||||||
|
echo Winget executable found
|
||||||
|
)
|
||||||
|
|
||||||
|
where go.exe >nul 2>&1
|
||||||
|
if %errorlevel% NEQ 0 (
|
||||||
|
echo Installing Go with Winget
|
||||||
|
winget install GoLang.Go
|
||||||
|
) else (
|
||||||
|
echo Go executable found
|
||||||
|
)
|
||||||
|
|
||||||
|
where git.exe >nul 2>&1
|
||||||
|
if %errorlevel% NEQ 0 (
|
||||||
|
echo Installing Git with Winget
|
||||||
|
winget install Git.Git
|
||||||
|
) else (
|
||||||
|
echo Git executable found
|
||||||
|
)
|
||||||
|
|
||||||
|
if exist .\beszel (
|
||||||
|
echo Subdirectory beszel already exists, it has to be deleted.
|
||||||
|
echo - Hit Crtl+c to exit if you don't want the directory to be deleted.
|
||||||
|
echo - Hit any other key to continue
|
||||||
|
pause >nul 2>&1
|
||||||
|
echo Deleting beszel subdirectory
|
||||||
|
rd /q/s .\beszel >nul 2>&1
|
||||||
|
)
|
||||||
|
|
||||||
|
:proceed
|
||||||
|
echo Cloning Beszel repository from Github
|
||||||
|
git clone https://github.com/henrygd/beszel.git >nul 2>&1
|
||||||
|
if %errorlevel% NEQ 0 (
|
||||||
|
echo Cloning repository failed.
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
cd .\beszel\beszel\cmd\agent
|
||||||
|
|
||||||
|
echo Building agent
|
||||||
|
set GOOS=windows
|
||||||
|
set GOARCH=amd64
|
||||||
|
set CGO_ENABLED=0
|
||||||
|
go build -ldflags "-w -s" . >nul 2>&1
|
||||||
|
if %errorlevel% NEQ 0 (
|
||||||
|
echo Something went wrong
|
||||||
|
goto end
|
||||||
|
) else (
|
||||||
|
echo Build successful
|
||||||
|
)
|
||||||
|
|
||||||
|
cd /D "%~dp0"
|
||||||
|
|
||||||
|
echo Stopping Beszel agent service
|
||||||
|
net stop %SERVICENAME% >nul 2>&1
|
||||||
|
if %errorlevel% NEQ 0 (
|
||||||
|
echo Failed to stop Beszel agent service
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Copying new agent
|
||||||
|
copy .\beszel\beszel\cmd\agent\agent.exe %AGENTEXE% >nul 2>&1
|
||||||
|
if %errorlevel% NEQ 0 (
|
||||||
|
echo Failed to copy agent.exe
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Starting Beszel agent service
|
||||||
|
net start %SERVICENAME% >nul 2>&1
|
||||||
|
if %errorlevel% NEQ 0 (
|
||||||
|
echo Failed to start Beszel agent service
|
||||||
|
goto end
|
||||||
|
)
|
||||||
|
|
||||||
|
:end
|
||||||
|
endlocal
|
Reference in New Issue
Block a user