~dliroulet/ocsinventory-windows-packager/trunk-1

« back to all changes in this revision

Viewing changes to Packager/instocs.nsi

  • Committer: Didier Liroulet
  • Date: 2013-06-05 18:58:28 UTC
  • Revision ID: didier.liroulet@ocsinventory-ng.org-20130605185828-61a33n5fytwexpz7
Update packager to fully support version 2.X of OCS Inventory NG agent, and also allow to include plugins

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
;!include "MUI.nsh"
2
 
!include "WordFunc.nsh"
3
 
!insertmacro WordFind
 
1
################################################################################
 
2
## OCS Inventory NG
 
3
## Copyleft OCS Inventory NG Team
 
4
## Web : http://www.ocsinventory-ng.org
 
5
##
 
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
################################################################################
 
10
 
 
11
;
 
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
 
15
; It Assumes that:
 
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
 
20
;
 
21
 
 
22
!include "MUI.nsh"
 
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"
10
 
silentinstall silent
11
 
OutFile ${appname}
12
 
var FILE_COLLECTION
13
 
var SETUP_LOG_FILE
14
 
var OcsLogon_v
15
 
ShowInstDetails hide
 
28
 
 
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"
 
33
 
 
34
Name "${PRODUCT_NAME}"
 
35
Icon "OCSInventory.ico"
 
36
OutFile "instOCS.exe"
 
37
 
 
38
SilentInstall Silent
 
39
ShowInstDetails Hide
 
40
 
 
41
var /GLOBAL SETUP_LOG_FILE       ; Setup log file to populate
 
42
var /GLOBAL logBuffer           ; Variable to write log
 
43
 
 
44
;Request application privileges for Windows Vista or higher ('user' or 'admin')
 
45
RequestExecutionLevel admin
 
46
 
 
47
################################################################################
 
48
# Version information
 
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}"
 
58
 
 
59
#####################################################################
 
60
# GetParameters
 
61
# input, none
 
62
# output, top of stack (replaces, with e.g. whatever)
 
63
# modifies no other variables.
 
64
#####################################################################
 
65
Function GetParameters
 
66
        Push $R0
 
67
        Push $R1
 
68
        Push $R2
 
69
        Push $R3
 
70
        StrCpy $R2 1
 
71
        StrLen $R3 $CMDLINE
 
72
        ;Check for quote or space
 
73
        StrCpy $R0 $CMDLINE $R2
 
74
        StrCmp $R0 '"' 0 +3
 
75
        StrCpy $R1 '"'
 
76
        Goto loop
 
77
        StrCpy $R1 " "
 
78
loop:
 
79
        IntOp $R2 $R2 + 1
 
80
        StrCpy $R0 $CMDLINE 1 $R2
 
81
        StrCmp $R0 $R1 get
 
82
        StrCmp $R2 $R3 get
 
83
        Goto loop
 
84
get:
 
85
        IntOp $R2 $R2 + 1
 
86
        StrCpy $R0 $CMDLINE 1 $R2
 
87
        StrCmp $R0 " " get
 
88
        StrCpy $R0 $CMDLINE "" $R2
 
89
        Pop $R3
 
90
        Pop $R2
 
91
        Pop $R1
 
92
        Exch $R0
 
93
FunctionEnd
 
94
 
 
95
#####################################################################
 
96
# This function write content of logBuffer variable in log file in
 
97
# a log file OcsAgentSetup.log located in install directory
 
98
#####################################################################
 
99
Function Write_Log
 
100
    ; Save used register
 
101
    Push $R0
 
102
    ClearErrors
 
103
    ; Is there something to write ?
 
104
    StrCmp $logBuffer "" WriteLog_end
 
105
    ; Open log file
 
106
    FileOpen $R0 $SETUP_LOG_FILE a
 
107
    ; Seek to end
 
108
    FileSeek $R0 END END
 
109
    IfErrors WriteLog_end
 
110
    ; Write
 
111
    FileWrite $R0 "$logBuffer"
 
112
    StrCpy $logBuffer ""
 
113
    ; Close file
 
114
    FileClose $R0
 
115
WriteLog_end:
 
116
    ; Restore used register
 
117
    Pop $R0
 
118
FunctionEnd
 
119
 
 
120
 
 
121
#####################################################################
 
122
# Init script
 
123
#####################################################################
16
124
Function .onInit
17
 
; Prevent Multiple Instances
18
 
   System::Call 'kernel32::CreateMutexA(i 0, i 0, t "instOCSNG") i .r1 ?e'
19
 
   Pop $R0
20
 
   StrCmp $R0 0 not_running
21
 
   Abort
 
125
    InitPluginsDir
 
126
    SetOutPath "$exedir"
 
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"
 
130
        Call Write_Log
 
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"
 
133
        Call Write_Log
 
134
    ; Prevent Multiple Instances
 
135
    System::Call 'kernel32::CreateMutexA(i 0, i 0, t "instOCSNG") i .r1 ?e'
 
136
    Pop $R0
 
137
    StrCmp $R0 0 not_running
 
138
        StrCpy $logBuffer "${PRODUCT_NAME} : ABORT because setup already running !$\r$\n"
 
139
        Call Write_Log
 
140
    Abort
22
141
not_running:
23
 
  ;InitPluginsDir
24
 
   SetOutPath "$exedir"
25
 
   call setv
26
142
FunctionEnd
27
143
 
28
 
function setv
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
39
 
 
40
 
;   strcpy  $FILE_COLLECTION "aaa|bbb"
41
 
;   messagebox mb_ok "COLLEC $FILE_COLLECTION"
42
 
   clearerrors
43
 
   SetShellVarContext all
44
 
   createdirectory $4
45
 
   StrCpy $OcsLogon_v '${appname}_:_Attempt to create "$4" dir...$\r$\n'
46
 
   Call Write_Log
47
 
;   execwait '"$exedir\OcsSetup.exe" $2'
48
 
;   messagebox mb_ok "dir cr�� :$4 "
49
 
;   messagebox mb_ok 'copy "$exedir\$5" "$4\$5"'
50
 
   clearerrors
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'
54
 
   Call Write_Log
55
 
no_cert:
56
 
   ;messagebox mb_ok '"copy2 "$7" "$8"'
57
 
  ; clearerrors
58
 
  ; copyfiles "$exedir\$7" "$4\$8"
59
 
  ; StrCpy $OcsLogon_v 'Copying "$exedir\$7" to "$4\$8"...$\r$\n'
60
 
  ; Call Write_Log
61
 
   clearerrors
62
 
   strcmp "" $9 suite 0
63
 
   fileopen $0 "$4\label" w
64
 
   filewrite $0 '$9'
65
 
   fileclose $0
66
 
   StrCpy $OcsLogon_v '${appname}_:_Writing label $9 to "$4\label"$\r$\n'
67
 
   Call Write_Log
68
 
   
69
 
suite:
70
 
   strcmp $FILE_COLLECTION "" endloopfiles
71
 
   ;;;
72
 
;   messagebox mb_ok "collect= $FILE_COLLECTION"
73
 
   ;********************************************
74
 
   ; TRAITEMENT DE LA COLLECTION DE FICHIERS
75
 
   ;********************************************
76
 
   ${WordFind} $FILE_COLLECTION "|" "*" $R0
77
 
   strcpy $1 "0"
78
 
loopfiles:
79
 
   intcmp $R0 $1 0 endloopfiles
80
 
   intop $1 $1 + 1
81
 
   ; retrieve current indexed_file
82
 
   ${WordFind} $FILE_COLLECTION "|" "+$1" $R1
83
 
   strcmp $R1 "" endloopfiles
84
 
   clearerrors
85
 
   copyfiles "$exedir\$R1" "$4\$R1"
86
 
   StrCpy $OcsLogon_v '${appname}_:_Copying "$exedir\$R1" to "$4\$R1"...$\r$\n'
87
 
   Call Write_Log
88
 
   goto loopfiles
89
 
endloopfiles:
90
 
  ;fin de traitement de la collection
91
 
  clearerrors
92
 
  execwait '"$exedir\OcsSetup.exe" $2'
93
 
  StrCpy $OcsLogon_v '${appname}_:_Lauching OcsSetup.exe (see Contents)...$\r$\n'
94
 
  Call Write_Log
95
 
  ;ins�rer log de ocsagentsetup
96
 
  StrCpy $OcsLogon_v '${appname}_:_============== Start of OcsSetup.exe log =============$\r$\n'
97
 
  Call Write_Log
98
 
  ${FileJoin} $SETUP_LOG_FILE '$exedir\${AgentLogFileName}' $SETUP_LOG_FILE
99
 
  StrCpy $OcsLogon_v '${appname}_:_============== End of OcsSetup.exe log =============$\r$\n'
100
 
  Call Write_Log
101
 
functionend
102
 
 
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"
106
 
  Call Write_Log
107
 
functionend
108
 
 
109
 
section
 
144
#####################################################################
 
145
# Main section - read parameters and start setup
 
146
#####################################################################
 
147
Section "Run setup"
 
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'
 
155
    Call Write_Log
 
156
    CreateDirectory "$R0"
 
157
    StrCpy $logBuffer '${PRODUCT_NAME} : Creating OCS Inventort NG Agent ${AGENT_PLUGINS_DIR} directory <$R0\${AGENT_PLUGINS_DIR}>...$\r$\n'
 
158
    Call Write_Log
 
159
    CreateDirectory "$R0\${AGENT_PLUGINS_DIR}"
 
160
    StrCpy $logBuffer '${PRODUCT_NAME} : Creating OCS Inventort NG Agent data directory <$R1>...$\r$\n'
 
161
    Call Write_Log
 
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'
 
165
    Call Write_Log
 
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'
 
169
    Call Write_Log
 
170
    CopyFiles /SILENT "$exedir\OcsPlugins\*" "$R0\${AGENT_PLUGINS_DIR}"
 
171
    ; Launch agent setup
 
172
    StrCpy $logBuffer '${PRODUCT_NAME}: Lauching OCS Inventory NG Agent Setup...$\r$\n'
 
173
    Call Write_Log
 
174
    ; Read agent setup command line from config
 
175
    readINIStr $R0 "$exedir\ocsdat.ini" "Config" "CmdLine"
 
176
    ; Read optional parameters to overload config
 
177
    Call GetParameters
 
178
    Pop $R1
 
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'
 
184
    Call Write_Log
 
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'
 
187
    Call Write_Log
110
188
SectionEnd
111
189
 
112
 
 
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
 
#####################################################################
117
 
Function Write_Log
118
 
  ; Save used register
119
 
  Push $R0
120
 
  ClearErrors
121
 
  ; Is there something to write ?
122
 
  StrCmp $OcsLogon_v "" WriteLog_end
123
 
  ; Open log file
124
 
  FileOpen $R0 $SETUP_LOG_FILE a
125
 
  ; Seek to end
126
 
  FileSeek $R0 END END
127
 
  IfErrors WriteLog_end
128
 
  ; Write
129
 
  FileWrite $R0 "$OcsLogon_v"
130
 
  StrCpy $OcsLogon_v ""
131
 
  ; Close file
132
 
  FileClose $R0
133
 
WriteLog_end:
134
 
  ; Restore used register
135
 
  Pop $R0
136
 
FunctionEnd
137
 
 
138
 
 
 
190
#####################################################################
 
191
#
 
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"
 
196
    Call Write_Log
 
197
FunctionEnd
 
198
 
 
199
#####################################################################
 
200
#
 
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"
 
205
    Call Write_Log
 
206
FunctionEnd