Skip to content

Commit

Permalink
added windows service installation and uninstallation scripts, update…
Browse files Browse the repository at this point in the history
…d readme
  • Loading branch information
carlo.maiorano committed Nov 13, 2017
1 parent 53e54ef commit 9125d3c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ script:
- GOOS="linux" GOARCH=arm go build -v -o bin/arm/sleeponlan main.go

before_deploy:
- cp script/win-service-install.ps1 bin/win/win-service-install.ps1
- cp script/win-service-uninstall.ps1 bin/win/win-service-uninstall.ps1
- zip -r bin/sleeponlan-x86.zip bin/x86/
- zip -r bin/sleeponlan-win.zip bin/win/
- zip -r bin/sleeponlan-arm.zip bin/arm/
Expand Down
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,25 @@ curl -X POST http://your-pc-ip:7740/poweroff #This will shutdown your pc
```
## Installation

You can download binaries from [release](https://github.com/charliemaiors/sleep-on-lan/releases) or run:
You can download binaries from [release](https://github.com/charliemaiors/sleep-on-lan/releases), unzip it and run from a powershell or run:

```bash
go get github.com/charliemaiors/sleep-on-lan/
```

and run:
```bash
sudo $GOPATH/bin/sleeponlan
```
```
## Service

Sleep on lan could be installed also as a service in your os using this syntax:

```bash
./sleeponlan install [--port <custom-port>]
```
on linux, currently on windows the service is installed but it will not start so there is a script inside the script folder (if you get the executable using ```go get```) or inside the windows binary archive from [releases](https://github.com/charliemaiors/sleep-on-lan/releases) page in order to install and run it.
In order to uninstall it you could run
```bash
./sleeponlan uninstall
```
on linux systems, there is also a temporary (hopefully) uninstall script in windows binary archive or script folder.
36 changes: 36 additions & 0 deletions script/win-service-install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Write-Host "Checking if Chocolatey is installed"

if ((Get-Command "choco" -ErrorAction SilentlyContinue) -eq $null)
{
Write-Host "Unable to find Chocolatey (choco) in your PATH, please install it from https://chocolatey.org/"
exit
}

Write-Host "Checking current priviledges"
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"
exit
}

Write-Host "Check if nssm is installed"

if ((Get-Command "nssm" -ErrorAction SilentlyContinue) -eq $null)
{
choco install -y nssm
}

if (Test-Path "$env:GOPATH\bin\sleeponlan.exe")
{
$path="$env:GOPATH\bin\sleeponlan.exe"
} else {
$path = Read-Host 'Please insert the full path where sleeponlan.exe is installed'
}

$port = Read-Host 'Please insert the port number where you want to map your service'
nssm install sleeponlan "$path"
nssm set sleeponlan AppParameters "--port $port"
nssm set sleeponlan DisplayName "Sleep on Lan service"
nssm set sleeponlan Description "Simple Sleep on Lan service"
nssm start sleeponlan
2 changes: 2 additions & 0 deletions script/win-service-uninstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nssm stop sleeponlan
nssm remove sleeponlan

0 comments on commit 9125d3c

Please # to comment.