Skip to content

Instantly share code, notes, and snippets.

@knuton
Last active July 8, 2020 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knuton/040665243300a50d42215ae2a5627569 to your computer and use it in GitHub Desktop.
Save knuton/040665243300a50d42215ae2a5627569 to your computer and use it in GitHub Desktop.
Install dividat driver as Windows service
# This script will download and install Dividat Driver as a Windows service.
## Configuration ##########################################
$releaseUrl = "https://dist.dividat.com/releases/driver2/"
$channel = "master"
$installDir = "C:\Program Files\dividat-driver"
###########################################################
$ErrorActionPreference = "Stop"
# Figure out the latest version
$latestTmpFile = Join-Path $env:TEMP "dividat-driver-latest.txt"
try {
(New-Object System.Net.WebClient).DownloadFile($releaseUrl + $channel + "/latest",$latestTmpFile)
}
catch {
$ex = $_
while ($ex -eq $null)
{
Write-Host $ex.Message
Write-Host $ex.ScriptStackTrace
$ex = $ex.InnerException
}
}
$latest = (Get-Content $latestTmpFile -Raw).trim()
Remove-Item -path $latestTmpFile
# Create install directory
if (![System.IO.Directory]::Exists($installDir)) {[void][System.IO.Directory]::CreateDirectory($installDir)}
# Download application
$downloadUrl = $releaseUrl + $channel + "/" + $latest + "/" + "dividat-driver-windows-amd64-" + $latest + ".exe"
$appPath = Join-Path $installDir "dividat-driver.exe"
try {
(New-Object System.Net.WebClient).DownloadFile($downloadUrl,$appPath)
}
catch {
$ex = $_
while ($ex -eq $null)
{
Write-Host $ex.Message
Write-Host $ex.ScriptStackTrace
$ex = $ex.InnerException
}
}
# Install as service
New-Service -Name "DividatDriver" -BinaryPathName $appPath -DisplayName "Dividat Driver" -StartupType Automatic
# Start the service
Start-Service DividatDriver
# This script will download and install Dividat Driver as a Windows service.
## Configuration ##########################################
$releaseUrl = "https://dist.dividat.com/releases/driver2/"
$channel = "master"
$installDir = "/home/emerij/dividat-driver"
###########################################################
$ErrorActionPreference = "Stop"
# Figure out the latest version
$latestTmpFile = Join-Path $env:TEMP "dividat-driver-latest.txt"
try {
(New-Object System.Net.WebClient).DownloadFile($releaseUrl + $channel + "/latest",$latestTmpFile)
}
catch {
$ex = $_
while ($ex -eq $null)
{
Write-Host $ex.Message
Write-Host $ex.ScriptStackTrace
$ex = $ex.InnerException
}
}
$latest = (Get-Content $latestTmpFile -Raw).trim()
Remove-Item -path $latestTmpFile
# Create install directory
if (![System.IO.Directory]::Exists($installDir)) {[void][System.IO.Directory]::CreateDirectory($installDir)}
# Download application
$downloadUrl = $releaseUrl + $channel + "/" + $latest + "/" + "dividat-driver-windows-amd64-" + $latest + ".exe"
$appPath = Join-Path $installDir "dividat-driver.exe"
try {
(New-Object System.Net.WebClient).DownloadFile($downloadUrl,$appPath)
}
catch {
$ex = $_
while ($ex -eq $null)
{
Write-Host $ex.Message
Write-Host $ex.ScriptStackTrace
$ex = $ex.InnerException
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment