-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# helper script to install the AutoTx service on a computer | ||
|
||
# set our requirements: | ||
#Requires -version 5.1 | ||
#Requires -RunAsAdministrator | ||
|
||
[CmdletBinding()] | ||
Param( | ||
[Parameter(Mandatory = $False)][switch] $StartService | ||
) | ||
|
||
function Start-MyService { | ||
Write-Host -NoNewLine "Starting service $($ServiceName): " | ||
try { | ||
Start-Service $ServiceName | ||
Write-Host "[OK]" -Fore Green | ||
} catch { | ||
$ex = $_.Exception | ||
Write-Host "[FAILED]" -Fore Red | ||
Write-Host $ex.Message | ||
Write-Host "Please check if your configuration is valid!" | ||
Write-Host "Showing last 20 lines of service log file:" | ||
Write-Host "==========================================" | ||
Get-Content $ServiceLog -Tail 20 | ||
} | ||
} | ||
|
||
|
||
function Copy-ServiceFiles { | ||
if (Test-Path -Type Container $ServiceDir) { | ||
Write-Host "Target directory [$($ServiceDir)] exists, stopping!" | ||
Exit 1 | ||
} | ||
|
||
Write-Host -NoNewLine "Updating / installing service files: " | ||
$TargetDir = New-Item -ItemType Container -Force -Path $ServiceDir | ||
try { | ||
Copy-Item -Recurse -Force -Path "$ServiceName\*" -Destination $ServiceDir | ||
Copy-Item -Recurse -Force -Path "conf-example" -Destination $ServiceDir | ||
# create a dummy log file, so admins can already start watching it: | ||
Out-File -FilePath $ServiceLog -InputObject "$($ServiceName) installed" -Encoding utf8 | ||
Write-Host "[OK]" -Fore Green | ||
} catch { | ||
$ex = $_.Exception | ||
Write-Host "[FAILED]" -Fore Red | ||
Write-Host $ex.Message | ||
Exit | ||
} | ||
} | ||
|
||
|
||
function Install-Service { | ||
Write-Host "Installing service $($ServiceName)... " | ||
Write-Host "========================================================================" | ||
$InstallUtil = "C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" | ||
$ServiceExe = $ServiceDir + "\" + $ServiceName + ".exe" | ||
$ArgList = ("/username=$ServiceUser", "/password=$ServicePasswd", "/unattended", "$ServiceExe") | ||
$InstallProcess = Start-Process -FilePath "$InstallUtil" -ArgumentList $ArgList -Wait -NoNewWindow -PassThru | ||
Write-Host "========================================================================" | ||
Write-Host "InstallUtil exit code: $($InstallProcess.ExitCode)" | ||
Write-Host "========================================================================" | ||
} | ||
|
||
|
||
function Add-PerfMonGroupMember { | ||
$GroupName = "Performance Monitor Users" | ||
try { | ||
Add-LocalGroupMember -Group $GroupName -Member $ServiceUser | ||
Write-Host $("Successfully added user [$($ServiceUser)] to the local" | ||
"group [$($GroupName)].") | ||
} catch [Microsoft.PowerShell.Commands.MemberExistsException] { | ||
Write-Host $("User [$($ServiceUser)] is already a member of the local" | ||
"group [$($GroupName)], no action required.") | ||
} catch { | ||
Write-Host $("Adding user [$($ServiceUser)] to the local group" | ||
"[$($GroupName)] failed: $($_.Exception.Message)") | ||
} | ||
} | ||
|
||
|
||
$ErrorActionPreference = "Stop" | ||
|
||
|
||
$LocalConfiguration = ".\ScriptsConfig.ps1" | ||
if (Test-Path $LocalConfiguration) { | ||
. $LocalConfiguration | ||
} else { | ||
Write-Host "Can't find configuration '$LocalConfiguration'!" -Fore Red | ||
Exit | ||
} | ||
|
||
$ServiceLog = "$($ServiceDir)\var\$($env:COMPUTERNAME).$($ServiceName).log" | ||
|
||
|
||
$Service = Get-Service $ServiceName -ErrorAction SilentlyContinue | ||
if ($Service) { | ||
Write-Host "Service $($ServiceName) already installed! Please use the" ` | ||
"Updater to do service updates. Stopping." | ||
Exit 1 | ||
} | ||
|
||
Copy-ServiceFiles | ||
Install-Service | ||
Add-PerfMonGroupMember | ||
|
||
Write-Host "`nWatching the service log file can be done like this:`n" ` | ||
"`n> Get-Content -Wait -Tail 50 $($ServiceLog)`n" | ||
|
||
if ($StartService) { | ||
Start-MyService | ||
} else { | ||
Write-Host "Service installation has completed.`n" ` | ||
"`nNOTE: the service has not been started. Create and/or check`n" ` | ||
"the configuration files and start the service manually using:`n" ` | ||
"`n> Start-Service $($ServiceName)`n" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Configuration script to set variable that are used during the installation | ||
# process. | ||
|
||
$ServiceDir = "C:\Tools\AutoTx" | ||
$ServiceName = "AutoTx" | ||
|
||
$IncomingDir = "D:\AUTOTRANSFER" | ||
$ManagedDir = "D:\ProgramData\AUTOTRANSFER" | ||
|
||
$ServiceUser = "<SERVICE_USER>" | ||
$ServicePasswd = "<SERVICE_USER_PASSWORD>" |