-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.ps1
118 lines (96 loc) · 4.33 KB
/
setup.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
$nl = [Environment]::NewLine
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Write-Host "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"
Write-Host $nl"Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Break
}
# Set black background
$Host.UI.RawUI.BackgroundColor = "Black"
Clear-Host
# define some variables
$temp="c:\TempGMIL\TempGMILSetup-yFH4gu"
$npm="npm-1.4.12.zip"
$config="c:\Program Files\Qlik\Sense\ServiceDispatcher"
$target="$config\Node\GlobalMasterItems-Server"
# check if module is installed
if(!(Test-Path -Path "$target\node_modules")) {
$confirm = Read-Host "This script will install GlobalMasterItems-Server for GlobalMasterItems-Library Qlik Sense Extension, do you want to proceed? [Y/n]"
if ($confirm -eq 'n') {
Break
}
# check if npm has been downloaded already
if(!(Test-Path -Path "$temp\$npm")) {
New-Item -Path "$temp" -Type directory -force | Out-Null
Invoke-WebRequest "http://nodejs.org/dist/npm/$npm" -OutFile "$temp\$npm"
}
# check if module has been downloaded
if(!(Test-Path -Path "$target\routes")) {
New-Item -Path "$target\routes" -Type directory | Out-Null
Invoke-WebRequest "http://raw.githubusercontent.com/iviasensio/GlobalMasterItems-Server/master/index.js" -OutFile "$target\index.js"
Invoke-WebRequest "http://raw.githubusercontent.com/iviasensio/GlobalMasterItems-Server/master/db.js" -OutFile "$target\db.js"
Invoke-WebRequest "http://raw.githubusercontent.com/iviasensio/GlobalMasterItems-Server/master/routes/index.js" -OutFile "$target\routes\index.js"
Invoke-WebRequest "http://raw.githubusercontent.com/iviasensio/GlobalMasterItems-Server/master/package.json" -OutFile "$target\package.json"
}
# check if npm has been unzipped already
if(!(Test-Path -Path "$temp\node_modules")) {
Write-Host "Extracting files..."
Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::ExtractToDirectory("$temp\$npm", "$temp")
}
# install module with dependencies
Write-Host "Installing modules..."
Push-Location "$target"
$env:Path=$env:Path + ";$config\Node"
&$temp\npm.cmd config set spin=false
&$temp\npm.cmd --prefix "$target" install
Pop-Location
# cleanup temporary data
Write-Host $nl"Removing temporary files..."
Remove-Item $temp -recurse
}
function Read-Default($text, $defaultValue) { $prompt = Read-Host "$($text) [$($defaultValue)]"; return ($defaultValue,$prompt)[[bool]$prompt]; }
# check if config has been added already
if (!(Select-String -path "$config\services.conf" -pattern "Identity=aor-globalmasteritems-server" -quiet)) {
$settings = @"
[globalmasteritems-server]
Identity=aor-globalmasteritems-server
Enabled=true
DisplayName=GlobalMasterItems Server
ExecType=nodejs
ExePath=Node\node.exe
Script=Node\globalmasteritems-server\index.js
[globalmasteritems-server.parameters]
auth_port=
globalmasteritems_port_unsecure=
"@
Add-Content "$config\services.conf" $settings
}
# configure module
Write-Host $nl"CONFIGURE MODULE"
Write-Host $nl"To make changes to the configuration in the future just re-run this script."
$auth_port=Read-Default $nl"Enter HTTPS port" "8200"
$globalmasteritems_port_unsecure=Read-Default $nl"Enter HTTP port" "8202"
function Set-Config( $file, $key, $value )
{
$regreplace = $("(?<=$key).*?=.*")
$regvalue = $("=" + $value)
if (([regex]::Match((Get-Content $file),$regreplace)).success) {
(Get-Content $file) `
|Foreach-Object { [regex]::Replace($_,$regreplace,$regvalue)
} | Set-Content $file
}
}
# write changes to configuration file
Write-Host $nl"Updating configuration..."
Set-Config -file "$config\services.conf" -key "auth_port" -value $auth_port
Set-Config -file "$config\services.conf" -key "globalmasteritems_port_unsecure" -value $globalmasteritems_port_unsecure
# Restart ServiceDipatcher
Write-Host $nl"Restarting ServiceDispatcher.."
net stop QlikSenseServiceDispatcher
start-sleep 5
net start QlikSenseServiceDispatcher
Write-Host $nl"'Qlik Sense Service Dispatcher' restarted."$nl
Write-Host $nl"Done! GlobalMasterItems write-back module installed."$nl