2
!include "WordFunc.nsh"
1
################################################################################
3
## Copyleft OCS Inventory NG Team
4
## Web : http://www.ocsinventory-ng.org
6
## This code is open source and may be copied and modified as long as the source
7
## code is always made freely available.
8
## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
9
################################################################################
12
; This is the code of installer which will setup agent, plugins and certificate
13
; It requires Aministrator privileges
14
; It is launched by All-One-Installer 1runas.nsi
16
; - agent setup files is OcsSetup.exe, and is in the same folder
17
; - subfolder OcsData contains files to copy to Agent data folder
18
; - subfolder OcsPlugins contains files to copy to Agent plugins folder
19
; - file ocsdat.ini contains various parameters for this tool. This file is created by All-In-One installer
23
!insertmacro MUI_LANGUAGE "English"
4
24
!include "FileFunc.nsh"
5
25
!include "TextFunc.nsh"
6
26
!insertmacro GetTime
7
27
!insertmacro FileJoin
8
!define appname "instocs.exe"
9
!define AgentLogFileName "OCS-NG-Windows-Agent-Setup.log"
29
!define PRODUCT_NAME "OCS Inventory NG Packager (Privilegied Installer)"
30
!define PRODUCT_VERSION "2.1.0.1"
31
!define AGENT_LOG_FILENAME "OCS-NG-Windows-Agent-Setup.log"
32
!define AGENT_PLUGINS_DIR "Plugins"
34
Name "${PRODUCT_NAME}"
35
Icon "OCSInventory.ico"
41
var /GLOBAL SETUP_LOG_FILE ; Setup log file to populate
42
var /GLOBAL logBuffer ; Variable to write log
44
;Request application privileges for Windows Vista or higher ('user' or 'admin')
45
RequestExecutionLevel admin
47
################################################################################
49
################################################################################
50
VIProductVersion "${PRODUCT_VERSION}"
51
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "${PRODUCT_NAME}"
52
VIAddVersionKey /LANG=${LANG_ENGLISH} "Comments" "Script for installing Agent, Certificate and Plugins from privilegied account"
53
VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" "OCS Inventory NG Team"
54
VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalTrademarks" "OCS Inventory NG Team"
55
VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "OCS Inventory NG Team"
56
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "instOCS.exe"
57
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${PRODUCT_VERSION}"
59
#####################################################################
62
# output, top of stack (replaces, with e.g. whatever)
63
# modifies no other variables.
64
#####################################################################
65
Function GetParameters
72
;Check for quote or space
73
StrCpy $R0 $CMDLINE $R2
80
StrCpy $R0 $CMDLINE 1 $R2
86
StrCpy $R0 $CMDLINE 1 $R2
88
StrCpy $R0 $CMDLINE "" $R2
95
#####################################################################
96
# This function write content of logBuffer variable in log file in
97
# a log file OcsAgentSetup.log located in install directory
98
#####################################################################
103
; Is there something to write ?
104
StrCmp $logBuffer "" WriteLog_end
106
FileOpen $R0 $SETUP_LOG_FILE a
109
IfErrors WriteLog_end
111
FileWrite $R0 "$logBuffer"
116
; Restore used register
121
#####################################################################
123
#####################################################################
17
; Prevent Multiple Instances
18
System::Call 'kernel32::CreateMutexA(i 0, i 0, t "instOCSNG") i .r1 ?e'
20
StrCmp $R0 0 not_running
127
; Read log file to populate from config
128
readINIStr $SETUP_LOG_FILE "$exedir\ocsdat.ini" "Config" "LogFile"
129
StrCpy $logBuffer "${PRODUCT_NAME} : ********************************************************$\r$\n"
131
${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
132
StrCpy $logBuffer "${PRODUCT_NAME} : Starting ${PRODUCT_NAME} ${PRODUCT_VERSION} on $0/$1/$2 at $4:$5:$6$\r$\n"
134
; Prevent Multiple Instances
135
System::Call 'kernel32::CreateMutexA(i 0, i 0, t "instOCSNG") i .r1 ?e'
137
StrCmp $R0 0 not_running
138
StrCpy $logBuffer "${PRODUCT_NAME} : ABORT because setup already running !$\r$\n"
29
readINIStr $2 "$exedir\ocsdat.ini" cnf a
30
readINIStr $3 "$exedir\ocsdat.ini" cnf z
31
readINIStr $4 "$exedir\ocsdat.ini" cnf e
32
readINIStr $5 "$exedir\ocsdat.ini" cnf r
33
readINIStr $6 "$exedir\ocsdat.ini" cnf t
34
; readINIStr $7 "$exedir\ocsdat.ini" cnf y
35
; readINIStr $8 "$exedir\ocsdat.ini" cnf u
36
readINIStr $9 "$exedir\ocsdat.ini" cnf v
37
readINIStr $FILE_COLLECTION "$exedir\ocsdat.ini" cnf W
38
readINIStr $SETUP_LOG_FILE "$exedir\ocsdat.ini" cnf x
40
; strcpy $FILE_COLLECTION "aaa|bbb"
41
; messagebox mb_ok "COLLEC $FILE_COLLECTION"
43
SetShellVarContext all
45
StrCpy $OcsLogon_v '${appname}_:_Attempt to create "$4" dir...$\r$\n'
47
; execwait '"$exedir\OcsSetup.exe" $2'
48
; messagebox mb_ok "dir cr�� :$4 "
49
; messagebox mb_ok 'copy "$exedir\$5" "$4\$5"'
51
strcmp $5 "othern.filen" no_cert 0
52
copyfiles "$exedir\$5" "$4\$5"
53
StrCpy $OcsLogon_v '${appname}_:_Copying certificate:$5 to "$4\"...$\r$\n'
56
;messagebox mb_ok '"copy2 "$7" "$8"'
58
; copyfiles "$exedir\$7" "$4\$8"
59
; StrCpy $OcsLogon_v 'Copying "$exedir\$7" to "$4\$8"...$\r$\n'
63
fileopen $0 "$4\label" w
66
StrCpy $OcsLogon_v '${appname}_:_Writing label $9 to "$4\label"$\r$\n'
70
strcmp $FILE_COLLECTION "" endloopfiles
72
; messagebox mb_ok "collect= $FILE_COLLECTION"
73
;********************************************
74
; TRAITEMENT DE LA COLLECTION DE FICHIERS
75
;********************************************
76
${WordFind} $FILE_COLLECTION "|" "*" $R0
79
intcmp $R0 $1 0 endloopfiles
81
; retrieve current indexed_file
82
${WordFind} $FILE_COLLECTION "|" "+$1" $R1
83
strcmp $R1 "" endloopfiles
85
copyfiles "$exedir\$R1" "$4\$R1"
86
StrCpy $OcsLogon_v '${appname}_:_Copying "$exedir\$R1" to "$4\$R1"...$\r$\n'
90
;fin de traitement de la collection
92
execwait '"$exedir\OcsSetup.exe" $2'
93
StrCpy $OcsLogon_v '${appname}_:_Lauching OcsSetup.exe (see Contents)...$\r$\n'
95
;ins�rer log de ocsagentsetup
96
StrCpy $OcsLogon_v '${appname}_:_============== Start of OcsSetup.exe log =============$\r$\n'
98
${FileJoin} $SETUP_LOG_FILE '$exedir\${AgentLogFileName}' $SETUP_LOG_FILE
99
StrCpy $OcsLogon_v '${appname}_:_============== End of OcsSetup.exe log =============$\r$\n'
103
function .onInstSuccess
104
${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
105
StrCpy $OcsLogon_v "${appname}_:_End of ${appname} on $0/$1/$2 at $4:$5:$6$\r$\n"
144
#####################################################################
145
# Main section - read parameters and start setup
146
#####################################################################
148
SetShellVarContext all
149
; Read agent setup folder from config
150
readINIStr $R0 "$exedir\ocsdat.ini" "Config" "InstallFolder"
151
; Read agent data folder from config
152
readINIStr $R1 "$exedir\ocsdat.ini" "Config" "DataFolder"
153
; Create agent install and data directories
154
StrCpy $logBuffer '${PRODUCT_NAME} : Creating OCS Inventort NG Agent install directory <$R0>...$\r$\n'
156
CreateDirectory "$R0"
157
StrCpy $logBuffer '${PRODUCT_NAME} : Creating OCS Inventort NG Agent ${AGENT_PLUGINS_DIR} directory <$R0\${AGENT_PLUGINS_DIR}>...$\r$\n'
159
CreateDirectory "$R0\${AGENT_PLUGINS_DIR}"
160
StrCpy $logBuffer '${PRODUCT_NAME} : Creating OCS Inventort NG Agent data directory <$R1>...$\r$\n'
162
CreateDirectory "$R1"
163
; Copy certificate and label file to agent data folder
164
StrCpy $logBuffer '${PRODUCT_NAME} : Installing OCS Inventort NG Agent data files to <$R1>...$\r$\n'
166
CopyFiles /SILENT "$exedir\OcsData\*" "$R1"
167
; Copy plugin files to agent plugins folder
168
StrCpy $logBuffer '${PRODUCT_NAME} : Installing OCS Inventort NG Agent plugin files to <$R0\${AGENT_PLUGINS_DIR}>...$\r$\n'
170
CopyFiles /SILENT "$exedir\OcsPlugins\*" "$R0\${AGENT_PLUGINS_DIR}"
172
StrCpy $logBuffer '${PRODUCT_NAME}: Lauching OCS Inventory NG Agent Setup...$\r$\n'
174
; Read agent setup command line from config
175
readINIStr $R0 "$exedir\ocsdat.ini" "Config" "CmdLine"
176
; Read optional parameters to overload config
179
; Launch agent setup with overloaded parameters before config parameters
180
ExecWait '"$exedir\OcsSetup.exe" $R1 $R0'
181
;********************************************
182
; read and paste OCS Agent Setup log
183
StrCpy $logBuffer '${PRODUCT_NAME} : ============== Start of OCS Inventory NG Agent setup log =============$\r$\n'
185
${FileJoin} $SETUP_LOG_FILE '$exedir\${AGENT_LOG_FILENAME}' $SETUP_LOG_FILE
186
StrCpy $logBuffer '${PRODUCT_NAME} : ============== End of OCS Inventory NG Agent setup log =============$\r$\n'
113
#####################################################################
114
# This function write content of OcsLogon_v variable in log file in
115
# a log file OcsAgentSetup.log located in install directory
116
#####################################################################
121
; Is there something to write ?
122
StrCmp $OcsLogon_v "" WriteLog_end
124
FileOpen $R0 $SETUP_LOG_FILE a
127
IfErrors WriteLog_end
129
FileWrite $R0 "$OcsLogon_v"
130
StrCpy $OcsLogon_v ""
134
; Restore used register
190
#####################################################################
192
#####################################################################
193
Function .onInstFailed
194
${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
195
StrCpy $logBuffer "${PRODUCT_NAME} : Failed end of ${PRODUCT_NAME} on $0/$1/$2 at $4:$5:$6$\r$\n"
199
#####################################################################
201
#####################################################################
202
Function .onInstSuccess
203
${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
204
StrCpy $logBuffer "${PRODUCT_NAME} : successfull end of ${PRODUCT_NAME} on $0/$1/$2 at $4:$5:$6$\r$\n"