feat: command to uninstall all agent services (#30)

* feat: command to uninstall all agent services

* fix: file extension
This commit is contained in:
UUBulb 2024-12-05 17:07:05 +08:00 committed by GitHub
parent 3d31005c61
commit 7ed0dda9dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 3 deletions

View File

@ -1,5 +1,3 @@
#Get server and key
param($server, $key, $tls)
# Download latest release from github # Download latest release from github
if($PSVersionTable.PSVersion.Major -lt 5){ if($PSVersionTable.PSVersion.Major -lt 5){
Write-Host "Require PS >= 5,your PSVersion:"$PSVersionTable.PSVersion.Major -BackgroundColor DarkGreen -ForegroundColor White Write-Host "Require PS >= 5,your PSVersion:"$PSVersionTable.PSVersion.Major -BackgroundColor DarkGreen -ForegroundColor White
@ -82,6 +80,6 @@ Move-Item -Path "C:\temp\nezha-agent.exe" -Destination "C:\nezha\nezha-agent.exe
Remove-Item "C:\nezha.zip" Remove-Item "C:\nezha.zip"
Remove-Item "C:\temp" -Recurse Remove-Item "C:\temp" -Recurse
#安装部分 #安装部分
C:\nezha\nezha-agent.exe service install -s $server -p $key $tls C:\nezha\nezha-agent.exe service install
#enjoy #enjoy
Write-Host "Enjoy It!" -BackgroundColor DarkGreen -ForegroundColor Red Write-Host "Enjoy It!" -BackgroundColor DarkGreen -ForegroundColor Red

View File

@ -5,6 +5,7 @@ NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
red='\033[0;31m' red='\033[0;31m'
green='\033[0;32m' green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m' plain='\033[0m'
err() { err() {
@ -15,6 +16,10 @@ success() {
printf "${green}%s${plain}\n" "$*" printf "${green}%s${plain}\n" "$*"
} }
info() {
printf "${yellow}%s${plain}\n" "$*"
}
sudo() { sudo() {
myEUID=$(id -ru) myEUID=$(id -ru)
if [ "$myEUID" -ne 0 ]; then if [ "$myEUID" -ne 0 ]; then
@ -176,5 +181,18 @@ install() {
success "nezha-agent successfully installed" success "nezha-agent successfully installed"
} }
uninstall() {
find "$NZ_AGENT_PATH" -type f -name "*config*.yml" | while read -r file; do
sudo "$NZ_AGENT_PATH/nezha-agent" service -c "$file" uninstall
sudo rm "$file"
done
info "Uninstallation completed."
}
if [ "$1" = "uninstall" ]; then
uninstall
exit
fi
init init
install install