-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwpkg.js
10852 lines (9706 loc) · 332 KB
/
wpkg.js
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var WPKG_VERSION = "1.3.1";
/*******************************************************************************
*
* WPKG - Windows Packager
*
* Copyright 2003 Jerry Haltom<br>
* Copyright 2005 Aleksander Wysocki <papopypu (at) op . pl><br>
* Copyright 2005-2006 Tomasz Chmielewski <mangoo (at) wpkg . org><br>
* Copyright 2007-2011 Rainer Meier <r.meier (at) wpkg.org><br>
*
* Please report your issues to the list on http://wpkg.org/
*/
/**
* Displays command usage.
*/
function showUsage() {
var message = "" +
"If you cannot read this since it is displayed within a dialog-window please \n" +
"execute 'cscript wpkg.js /help' on the command line. This will print all \n" +
"messages to the console. \n\n" +
"Command Line Switches \n" +
"===================== \n" +
"Note: These command line switches overwrite parameters within config.xml. For \n" +
"example the /quiet flag overrides a possibly present quiet parameter within \n" +
"config.xml. \n" +
"Usually you should specify as few parameters as possible since changing \n" +
"config.xml on the server might be much easier than changing all client-side \n" +
"stored parameters. Typically you would use the following command-line in \n" +
"production: \n" +
" wpkg.js /synchronize \n" +
"\n" +
"Frequently used parameters (package operations, you need to choose one): \n" +
"======================================================================== \n" +
"\n" +
"/install:<package>[,package2[,package3,[...]]] \n" +
" Install the specified package(s) on the system. \n" +
"\n" +
"/query:<option> \n" +
" Display a list of packages matching the specified criteria. Valid \n" +
" options are: \n" +
"\n" +
" a - Query all packages (includes installed packages and package database). \n" +
" x - List packages which are not installed but are in package database. \n" +
" i - List all packages which are currently installed. \n" +
" I - List packages which are about to be installed during synchronization. \n" +
" u - List packages which are about to be upgraded during synchronization. \n" +
" d - List packages which are about to be downgraded during synchronization. \n" +
" r - List packages which are about to be removed during synchronization. \n" +
" m - List all modifications which would apply during synchronization \n" +
" (equal to Iudr) \n" +
" n - List packages which belong to the profile but are not modified during \n" +
" synchronization. \n" +
" s - List host attributes from settings (wpkg.xml). \n" +
" l - List host attributes read from local host. \n" +
"\n" +
"/remove:<package>[,package2[,package3,[...]]] \n" +
" Remove the specified package(s) from the system. \n" +
"\n" +
"/show:<package> \n" +
" Display a summary of the specified package, including it's state. \n" +
"\n" +
"/upgrade:<package>[,package2[,package3,[...]]] \n" +
" Upgrade the already installed package(s) on the system. \n" +
"\n" +
"/synchronize \n" +
" Synchronize the current program state with the suggested program state \n" +
" of the specified profile. This is the action that should be called at \n" +
" system boot time for this program to be useful. \n" +
"\n" +
"/help \n" +
" Show this message. \n" +
"\n" +
"\n" +
"Optional parameters (usually defined within config.xml): \n" +
"======================================================== \n" +
"\n" +
"/base:<path> \n" +
" Set the local or remote path to find the xml input files. \n" +
" Can also be set to a web URL for direct XML retrieval from wpkg_web. \n" +
"\n" +
"/dryrun[:<true>|<false>] \n" +
" Do not execute any actions. Implies debug mode. \n" +
"\n" +
"/quiet[:<true>|<false>] \n" +
" Use the event log to record all error/status messages. Use this when \n" +
" running unattended. \n" +
"\n" +
"/nonotify[:<true>|<false>] \n" +
" Logged in users are not notified about impending updates. \n" +
"\n" +
"/noreboot[:<true>|<false>] \n" +
" System does not reboot regardless of need. \n" +
"\n" +
"/quitonerror[:<true>|<false>] \n" +
" Quit execution if the installation of any package was unsuccessful \n" +
" (default: install next package and show the error summary). \n" +
"\n" +
"/sendStatus[:<true>|<false>] \n" +
" Send status messages on STDOUT which can be parsed by calling program to \n" +
" display status information to the user. \n" +
"\n" +
"/noUpgradeBeforeRemove[:<true>|<false>] \n" +
" Usually WPKG upgrades a package to the latest available version before it \n" +
" removes the package. This allows administrators to fix bugs in the package \n" +
" and assure proper removal.\n" +
"\n" +
"/applymultiple[:<true>|<false>] \n" +
" Apply profiles of all host nodes with matching attributes. \n" +
" Only first matching host node is returned if not switched on. \n" +
" This parameter must be used with caution, it can break existing setup. \n" +
"\n" +
"Rarely used parameters (mainly for testing): \n" +
"============================================ \n" +
"\n" +
"/config:<path> \n" +
" Path to the configuration file to be used. The path might be absolute \n" +
" or relative but including the XML file name. This parameter is entirely \n" +
" OPTIONAL and should normally not be specified at all. \n" +
" If not specified the configuration will be searched at: \n" +
" <script-path>\\config.xml \n" +
" where <script-path> is the directory from which the script is executed. \n" +
" e.g. '\\\\server\\share\\directory\\config.xml'. \n" +
" e.g. 'directory\\config.xml'. \n" +
" You can use environment variables as well as the following expressions: \n" +
" [HOSTNAME] Replaced by the executing hostname. \n" +
" [PROFILE] Replaced by the concatenated list of profiles applied. \n" +
"\n" +
"/settings:<path> \n" +
" Path to the settings (local WPKG database) file to be used. The path might \n" +
" be absolute or relative but including the XML file name. This parameter is \n" +
" entirely OPTIONAL and should normally not be specified at all. \n" +
" If not specified the settings file will be searched at: \n" +
" %SystemRoot%\\system32\\wpkg.xml \n" +
" e.g. '%SystemRoot%\\system32\\wpkg-custom.xml'. \n" +
" e.g. '\\\\server\share\directory\\[HOSTNAME].xml'. \n" +
" If you store the settings file on a share make sure the names is unique! \n" +
" You can use environment variables as well as the following expressions: \n" +
" [HOSTNAME] Replaced by the executing hostname. \n" +
" [PROFILE] Replaced by the concatenated list of profiles applied. \n" +
"\n" +
"/queryMode:<mode> \n" +
" Allows to switch to remote mode where package verification is skipped. \n" +
" remote: Disable package checks and assume that packages in settings \n" +
" database are still correctly installed. In remote mode also the \n" +
" host information is read from the local settings database. \n" +
" local: Default setting. Query verifies package status using all checks. \n" +
" Note: Query mode can only be used with the query switch. \n" +
"\n" +
"/profile:<profile> \n" +
" Force the name of the profile to use. If not specified, the profile to use \n" +
" is looked up in hosts.xml. \n" +
"\n" +
"/debug[:<true>|<false>] or /verbose[:<true>|<false>] \n" +
" Enable debug output. Please note that this parameter only influences \n" +
" notification and event log output. It does not affect the logging level. \n" +
" It is possible to get debug-level output even without using this \n" +
" switch. \n" +
"\n" +
"/force[:<true>|<false>] \n" +
" When used in conjunction with /synchronize WPKG will ignore the local \n" +
" settings file (wpkg.xml) and re-build the database with installed \n" +
" packages. \n" +
" When used in conjunction with /remove forces removal of the specified \n" +
" package even if not all packages which depend on the one to be removed \n" +
" could be removed. \n" +
"\n" +
"/forceinstall[:<true>|<false>] \n" +
" Force installation over existing packages. \n" +
"\n" +
"/host:<hostname> \n" +
" Use the specified hostname instead of reading it from the executing host. \n" +
"\n" +
"/os:<hostos> \n" +
" Use the specified operating system string instead of reading it from the \n" +
" executing host. \n" +
"\n" +
"/ip:<ip-address-1,ip-address-2,...,ip-address-n> \n" +
" Use the specified ipaddresses instead of reading it from the executing host. \n" +
"\n" +
"/domainname:<domain> \n" +
" Name of the windows domain the computer belongs to. \n" +
" This permit to use group membership even on a non-member workstation. \n" +
"\n" +
"/group:<group-name-1,group-name-2,...,group-name-n>\n" +
" Name of the group the computer must belongs to instead of reading it from \n" +
" the executing host. \n" +
"\n" +
"/ignoreCase[:<true>|<false>] \n" +
" Disable case sensitivity of packages and profiles. Therefore you can \n" +
" assign the package 'myapp' to a profile while only a package 'MyApp' is \n" +
" defined within the packages. \n" +
" Note that this change requires modification of the package/profile/host nodes \n" +
" read from the XML files. All IDs are converted to lowercase. \n" +
" Note: This requires converting all profile/package IDs to lowercase. \n" +
" Therefore you will only see lowercase entries within the log files \n" +
" and also within the local package database. \n" +
"\n" +
"/logAppend[:<true>|<false>] \n" +
" Append log files instead of overwriting existing files. \n" +
" NOTE: You can specify a log file pattern which will create a new file on \n" +
" each run. Appending logs might cause problems with some log rotation \n" +
" scripts as well. So use it with caution. \n" +
"\n" +
"/logfilePattern:<pattern> \n" +
" Pattern for log file naming: \n" +
" Recognized patterns: \n" +
" [HOSTNAME] Replaced by the executing hostname. \n" +
" [PROFILE] Replaced by the concatenated list of profiles applied. \n" +
" [YYYY] Replaced by year (4 digits). \n" +
" [MM] Replaced by month number (2 digits). \n" +
" [DD] Replaced by the day of the month (2 digits). \n" +
" [hh] Replaced by hour of the day (24h format, 2 digits). \n" +
" [mm] Replaced by minutes (2 digits). \n" +
" [ss] Replaced by seconds (2 digits). \n" +
"\n" +
" Examples: \n" +
" 'wpkg-[YYYY]-[MM]-[DD]-[HOSTNAME].log' \n" +
" results in a name like 'wpkg-2007-11-04-myhost.log' \n" +
" NOTE: Using [PROFILE] causes all log messages before reading profiles.xml \n" +
" to be temporarily written to local %TEMP% folder. So they might \n" +
" appear on the final log file with some delay. \n" +
"\n" +
"/logLevel:[0-31] \n" +
" Level of detail for log file: \n" +
" use the following values: \n" +
" Log level is defined as a bitmask. Just sum up the values of each log \n" +
" severity you would like to include within the log file and add this value \n" +
" to your config.xml or specify it at /logLevel:<#>. \n" +
" Specify 0 to disable logging. \n" +
" 1: log errors only \n" +
" 2: log warnings \n" +
" 4: log information \n" +
" 8: log audit success \n" +
" 16: log audit failure \n" +
" Example: \n" +
" 31 log everything (1+2+4+8+16=31) \n" +
" 13 log errors, information and audit success (1+4+8=13) \n" +
" 3 log errors and warnings only (1+2=3) \n" +
" Default is 0 which will suppress all messages printed before log level is \n" +
" properly initialized by config.xml or by /logLevel:<#> parameter. \n" +
"\n" +
"/log_file_path:<path> \n" +
" Path where the log files will be stored. Also allows specifying an UNC \n" +
" path (e.g. '\\server\share\directory'). Make sure the path exists and \n" +
" that the executing user has write access to it. \n" +
" NOTE: If you set this parameter within config.xml please note that you \n" +
" need to escape backslashes: \n" +
" e.g. '\\\\server\\share\\directory'. \n" +
"\n" +
"/noforcedremove[:<true>|<false>] \n" +
" Do not remove packages from local package database if remove fails even \n" +
" if the package does not exist in the package database on the server and \n" +
" is not referenced within the profile. \n" +
" By default packages which have been removed from the server package \n" +
" database and the profile will be uninstalled and then removed \n" +
" from the local package database even if uninstall failed. \n" +
" This has been introduced to prevent a package whose uninstall script \n" +
" fails to repeat its uninstall procedure on each execution without the \n" +
" possibility to fix the problem since the package (including its \n" +
" uninstall string) is available on the local machine only. \n" +
" HINT: If you like the package to stay in the local database (including \n" +
" uninstall-retry on next boot) just remove it from the profile but do not \n" +
" completely delete it from the package database. \n" +
"\n" +
"/noremove[:<true>|<false>] \n" +
" Disable the removal of all packages. If used in conjunction with the \n" +
" /synchronize parameter it will just add packages but never remove them. \n" +
" Instead of removing a list of packages which would have been removed \n" +
" during that session is printed on exit. Packages are not removed from \n" +
" the local settings database (wpkg.xml). Therefore it will contain a list \n" +
" of all packages ever installed. \n" +
" Note that each package which is requested to be removed (manually or by \n" +
" a synchronization request) will be checked for its state by executing its \n" +
" included package checks. If the package has been removed manually it will \n" +
" also be removed from the settings database. This does not apply to packages \n" +
" which do not specify any checks. Such packages will remain in the local \n" +
" settings database even if the software has been removed manually. \n" +
"\n" +
"/noDownload[:<true>|<false>] \n" +
" Ignore all download nodes in packages. \n" +
" Useful for testing and in case your download targets already exist. \n" +
"\n" +
"/norunningstate[:<true>|<false>] \n" +
" Do not export the running state to the registry. \n" +
"\n" +
"/rebootcmd:<option> \n" +
" Use the specified boot command, either with full path or \n" +
" relative to the location of wpkg.js \n" +
" Specifying 'special' as option uses tools\psshutdown.exe \n" +
" from www.sysinternals.com - if it exists - and a notification loop \n";
alert(message);
}
/*******************************************************************************
*
* Global variables
*
******************************************************************************/
/** base where to find the XML input files */
var wpkg_base = "";
/** forces to check for package existence but ignores wpkg.xml */
var force = false;
/** force installation */
var forceInstall = false;
/**
* Forced remove of non-existing packages from wpkg.xml even if uninstall
* command fails.
*/
var noForcedRemove = false;
/** defined if script should quit on error */
var quitonerror = false;
/** Debug output. */
var debug = false;
/** Dry run */
var dryrun = false;
/** notify user using net send? */
var nonotify = false;
/** timeout for user notifications. Works only if msg.exe is available */
var notificationDisplayTime = 10;
/** set to true to prevent reboot */
var noreboot = false;
/** stores if package removal should be skipped - see /noremove flag */
var noRemove = false;
/** allows disabling/enabling of running state export to registry */
var noRunningState = false;
/** type of reboot command */
var rebootCmd = "standard";
/** set to true for quiet mode */
var quietDefault = false;
/** registry path where WPKG stores its running state */
var sRegWPKG_Running = "HKLM\\Software\\WPKG\\running";
/** configuration file to hold the settings for the script */
var config_file_name = "config.xml";
/** name of package database file */
var packages_file_name = "packages.xml";
/** name of profiles database file */
var profiles_file_name = "profiles.xml";
/** name of hosts definition database file */
var hosts_file_name = "hosts.xml";
/** path from where to read package files */
var packages_path = "";
/** path from where to read profile files */
var profiles_path = "";
/** path from where to read host files */
var hosts_path = "";
/**
* specify if manually installed packages should be kept during synchronization
* true: keep manually installed packages false: remove any manually installed
* packages which do not belong to the profile
*/
var keepManual = true;
/**
* path where log-files are stored.<br>
* Defaults to "%TEMP%" if empty.
*/
var log_file_path = "%TEMP%";
/** path where downloads are stored, defaults to %TEMP% if not defined */
var downloadDir = "%TEMP%";
/** timeout for downloads */
var downloadTimeout = 7200;
/** if set to true logfiles will be appended, otherwise they are overwritten */
var logAppend = false;
/**
* set to true to enable sending of status messages to STDOUT, regardless of the
* status of /debug
*/
var sendStatus = false;
/**
* Set to true to disable upgrade-before-remove feature by default
*/
var noUpgradeBeforeRemove = false;
/**
* use the following values: Log level is defined as a bitmask. Just add up the
* values of each log severity you would like to include within the log file and
* add this value to your config.xml or specify it as /logLevel:<num>.
*
* Specify 0 to disable logging.
*
* <pre>
* 1: log errors only
* 2 : log warnings
* 4 : log information
* 8 : log audit success
* </pre>
*
* Example:
*
* <pre>
* 31 log everything (1+2+4+8+16=32)
* 13 logs errors, information and audit success (1+4+8=13)
* 3 logs errors and warnings only (1+2=3)
* </pre>
*
* Default is 0 which will suppress all messages printed before log level is
* properly initialized by config.xml or by /logLevel:<#> parameter.
*/
var logLevelDefault = 0xFF;
/**
* var logfile pattern Recognized patterns:
*
* <pre>
* [HOSTNAME] replaced by the executing hostname
* [PROFILE] replaced by the name
* [YYYY] replaced by year (4 digits)
* [MM] replaced by month number (2 digits)
* [DD] replaced by the day of the month (2 digits)
* [HH] replaced by hour of the day (24h format, 2 digits)
* [mm] replaced by minute (2 digits)
* </pre>
*
* Examples:
*
* <pre>
* wpkg-[YYYY]-[MM]-[DD]-[HOSTNAME].log
* </pre>
*
* results in a name like "wpkg-2007-11-04-myhost.log"
*/
var logfilePattern = "wpkg-[HOSTNAME].log";
/** web file name of package database if base is an http url */
var web_packages_file_name = "packages_xml_out.php";
/** web file name of profile database if base is an http url */
var web_profiles_file_name = "profiles_xml_out.php";
/** web file name of hosts database if base is an http url */
var web_hosts_file_name = "hosts_xml_out.php";
/** name of local settings file */
var settings_file_name = "wpkg.xml";
/** path to settings file, defaults to system folder if set to null */
var settings_file_path = null;
/** defines if package/profile IDs are handled case sensitively */
var caseSensitivity = true;
/** set to true to want to apply profiles of all matching host nodes */
var applyMultiple = false;
/** globally disable any downloads */
var noDownload = false;
/**
* Allows to disable inserting of host attributes to local settings DB. This
* is handy for testing as the current test-suite compares the local wpkg.xml
* database and the file will look different on all test machines if these
* attributes are present. This setting might be removed if all test-cases
* are adapted.
*/
var settingsHostInfo = true;
/**
* Query mode. In order to "simulate" the result of a query on a system on
* another (remote-) system you can set queryMode to "remote". This will
* disable package checks because they will not return the same results on a
* remote system.
*/
var queryMode = "local";
/**
* Default command execution timeout. This is the default timeout used when
* executing external commands. Each command which runs for longer than the
* defined amount of seconds will be be regarded as failed and WPKG will
* continue execution.
* NOTE: You can override the default timeout using the timeout=xxx attribute
* on command definition. It is strongly recommended to keep the default as-is
* and just define custom timeouts on commands which are known to finish within
* a shorter timeframe or of course if commands are known to run longer than
* the default timeout.
*/
var execTimeout = 3600;
/**
* XML namespaces.
*/
var namespaceSettings = "http://www.wpkg.org/settings";
var namespaceHosts = "http://www.wpkg.org/hosts";
var namespaceProfiles = "http://www.wpkg.org/profiles";
var namespacePackages = "http://www.wpkg.org/packages";
var namespaceConfig = "http://www.wpkg.org/config";
/*******************************************************************************
*
* Caching variables - used by internal functions.
*
******************************************************************************/
/** file to which the log is written to */
var logfileHandler = null;
/** path to the log file (corresponds to logfileHandler) */
var logfilePath = null;
/** store whether log file was opened in append mode */
var logfileAppendMode = logAppend;
/** stores if the user was notified about start of actions */
var was_notified = false;
/**
* holds a list of packages which have been installed during this execution this
* is used to prevent package dependencies without checks and "always execute" to
* be executed several times as well as preventing infinite- loops on recursive
* package installation.
*/
var packagesInstalled = new Array();
/**
* holds a list of packages which have been removed during this execution This
* is used to prevent removing packages multiple times during a session because
* they are referenced as dependencies by multiple other packages.
*/
var packagesRemoved = new Array();
/** host properties used within script */
var hostName = null;
var hostOs = null;
var domainName = null;
var ipAddresses = null;
var hostGroups = null;
var hostArchitecture = null;
var hostAttributes = null;
/** String representing path where the settings are stored */
var settings_file = null;
/** Flag whether settings path was processed to replace parameters */
var settings_file_processed = false;
/** declare variables for data storage */
var packages = null;
var profiles = null;
var hosts = null;
var settings = null;
var config = null;
/** List of profiles assigned directly to current host */
var applyingProfilesDirect = null;
/** profiles applying to the current host (including dependencies) */
var applyingProfilesAll = null;
/** caches the host node entries applying to the current host */
var applyingHostNodes = null;
/** Packages belonging to current host (package nodes) */
var profilePackageNodes = null;
/** stores the locale ID (LCID) which applies for the local executing user */
var LCID = null;
/** stores the host locale ID of the OS (LCID) which applies for the local machine */
var LCIDOS = null;
/** caches the language node applying to the current system locale */
var languageNode = null;
/** declare log level variable */
var logLevel = null;
/** actual value for log level */
var logLevelValue = 0x03;
/** buffer to store log entries while no real log file is available */
var logBuffer = null;
/** flag which is true if log is ready to be initialize */
var logInitReady = false;
/** flag which is set to true internally during log initialization */
var logInitializing = false;
/** declare quiet mode variable */
var quiet = null;
/** current value of quiet operation flag */
var quietMode = quietDefault;
/** stores if a postponed reboot is scheduled */
var postponedReboot = false;
/** set to true when a reboot is in progress */
var rebooting = false;
/** set to true to skip write attempts to event log */
var skipEventLog = false;
/** set to true to log event log entries to STDOUT (fallback mode) */
var eventLogFallback = false;
/** holds an array of packages which were not removed due to the /noremove flag */
var skippedRemoveNodes = null;
/**
* holds status of change: true: System has been changed (package
* installed/removed/updated/downgraded... false: System has not been touched
* (yet)
*/
var systemChanged = false;
/**
* Holds a list of packages which have been manually installed.
*/
var manuallyInstalled = null;
/**
* Marks volatile releases and "inverts" the algorithm that a longer version
* number is newer. For example 1.0RC2 would be newer than 1.0 because it
* appends characters to the version. Using "rc" as a volatile release marker
* the algorithm ignores the appendix and assumes that the string which omits
* the marker is newer.
*
* Resulting in 1.0 to be treated as newer than 1.0RC2.
*
* NOTE: The strings are compared as lower-case. So use lower-case definitions
* only!
*/
var volatileReleaseMarkers = ["rc", "i", "m", "alpha", "beta", "pre", "prerelease"];
/** stores if system is running on a 64-bit OS */
var x64 = null;
/** Stores variables assigned to host definitions applying to current host */
var hostsVariables = null;
/** Stores variables from profiles assigned to current host */
var profilesVariables = null;
/***********************************************************************************************************************
*
* Program execution
*
**********************************************************************************************************************/
/**
* Call the main function with arguments while catching all errors and
* forwarding them to the error output.
*/
try {
main();
} catch (e) {
// Log error message.
error("Message: " + e.message + "\n" +
"Description: " + e.description + "\n" +
"Error number: " + hex(e.number) + "\n" +
"Stack: " + e.stack + "\n" +
"Line: " + e.lineNumber + "\n"
);
notifyUserFail();
// Make sure log is initialized to write the output.
if (logBuffer != null) {
initializeLog();
}
exit(2);
}
/**
* Main execution method. Actually runs the script
*/
function main() {
// Do not open pop-up window while initializing.
setQuiet(true);
// Initialize WPKG internals.
initialize();
// Process command line arguments to determine course of action.
// Get special purpose argument lists.
var argv = getArgv();
var argn = argv.Named;
// var argu = argv.Unnamed;
if (argn.Item("query") != null) {
// Do not log to event log during query.
var eventLogStatus = isSkipEventLog();
setSkipEventLog(true);
if (getQueryMode() == "remote") {
getSettingHostAttributes();
}
// Now all parameters are set to build the final log file name
// even if [PROFILE] is used.
// WScript.Echo("Initializing Log");
// WScript.Echo("Buffer: " + logBuffer);
// Flag log file ready for initialization.
logInitReady = true;
// Do not log to log file during query.
var logValue = getLogLevel();
// setLogLevel(0);
// Read query argument characters.
var queryRequest = argn.Item("query").split("");
// Supported arguments:
// a Query all packages.
// x List packages which are not installed but in package database.
// i List all packages which are currently installed.
// I List packages which are about to be installed during synchronization.
// u List packages which are about to be upgraded during synchronization.
// d List packages which are about to be downgraded during synchronization.
// r List packages which are about to be removed during synchronization.
// m List all modifications which would apply during synchronization (equal to Iudr)
// n List packages which belong to the profile but are not modified during synchronization.
// s List host attributes from settings (wpkg.xml).
// l List host attributes read from local host.
var listSyncInstall = false;
var listSyncUpgrade = false;
var listSyncDowngrade = false;
var listSyncRemove = false;
var listSyncUnmodified = false;
for (var i=0; i<queryRequest.length; i++) {
var requestCharacter = queryRequest[i];
switch (requestCharacter) {
case "a":
queryAllPackages();
break;
case "x":
queryUninstalledPackages();
break;
case "i":
queryInstalledPackages();
break;
case "I":
listSyncInstall = true;
break;
case "u":
listSyncUpgrade = true;
break;
case "d":
listSyncDowngrade = true;
break;
case "r":
listSyncRemove = true;
break;
case "n":
listSyncUnmodified = true;
break;
case "m":
listSyncInstall = true;
listSyncUpgrade = true;
listSyncDowngrade = true;
listSyncRemove = true;
break;
case "s":
queryHostInformationFromSettings();
break;
case "l":
queryHostInformation();
break;
default:
break;
}
}
// Print requested output.
if (listSyncInstall || listSyncUpgrade || listSyncDowngrade || listSyncRemove || listSyncUnmodified) {
queryProfilePackages(listSyncInstall, listSyncUpgrade, listSyncDowngrade, listSyncRemove, listSyncUnmodified);
}
setSkipEventLog(eventLogStatus);
setLogLevel(logValue);
} else {
// set profile-based log level (if available)
var profileLogLevel = getProfilesLogLevel();
if (profileLogLevel != null) {
setLogLevel(profileLogLevel);
}
// Now all parameters are set to build the final log file name
// even if [PROFILE] is used.
// WScript.Echo("Initializing Log");
// WScript.Echo("Buffer: " + logBuffer);
// Flag log file ready for initialization.
logInitReady = true;
var message;
if(isDebug()) {
var hst = getHostNodes();
message = "Hosts file contains " + hst.length + " hosts:";
for (var iHost = 0; iHost < hst.length; iHost++ ) {
message += "\n'" + getHostNodeDescription(hst[iHost]) + "'";
}
dinfo(message);
var settingsPkg = getSettingNodes();
message = "Settings file contains " + settingsPkg.length + " packages:";
for (var iSettings = 0; iSettings < settingsPkg.length; iSettings++) {
if (settingsPkg[iSettings] != null) {
message += "\n'" + getPackageID(settingsPkg[iSettings]) + "'";
}
}
dinfo(message);
var packageNodes = getPackageNodes();
message = "Packages file contains " + packageNodes.length + " packages:";
for (var iPackage = 0; iPackage < packageNodes.length; iPackage++) {
if (packageNodes[iPackage] != null) {
message += "\n'" + getPackageID(packageNodes[iPackage]) + "'";
}
}
dinfo(message);
var profileNodes = getProfileNodes();
message = "Profile file contains " + profileNodes.length + " profiles:";
for (var iProfile = 0; iProfile < profileNodes.length; iProfile++) {
if (profileNodes[iProfile] != null) {
message += "\n'" + getProfileID(profileNodes[iProfile]) + "'";
}
}
dinfo(message);
// Get list of profiles directly assigned to host.
var profiles = getProfileList();
message = "Using profile(s): ";
for (var i=0; i < profiles.length; i++) {
message += "\n'" + profiles[i] + "'";
}
dinfo(message);
}
// Check if all referenced profiles are available.
var profileList = getProfileList();
var error = false;
message = "Could not locate referenced profile(s):\n";
for (var iProf = 0; iProf < profileList.length; iProf++) {
var currentProfile = getProfileNode(profileList[iProf]);
if (currentProfile == null) {
error = true;
message += profileList[iProf] + "\n";
}
}
if (error) {
throw new Error(message);
}
if (argn.Item("show") != null) {
var requestedPackageName = argn.Item("show");
// if case sensitive mode is disabled convert package name to lower case
if (!isCaseSensitive()) {
requestedPackageName = requestedPackageName.toLowerCase();
}
var message = queryPackage(getPackageNodeFromAnywhere(requestedPackageName), null);
info(message);
} else if (argn.Item("install") != null) {
var packageList = argn.Item("install").split(",");
for (var iPackage=0; iPackage < packageList.length; iPackage++) {
installPackageName(packageList[iPackage], true);
}
} else if (argn.Item("remove") != null) {
var packageList = argn.Item("remove").split(",");
for (var iPackage=0; iPackage < packageList.length; iPackage++) {
removePackageName(packageList[iPackage]);
}
} else if (argn.Item("upgrade") != null) {
var packageList = argn.Item("upgrade").split(",");
for (var iPackage=0; iPackage < packageList.length; iPackage++) {
installPackageName(packageList[iPackage], false);
}
} else if (isArgSet(argv, "/synchronize")) {
synchronizeProfile();
} else {
showUsage();
throw new Error("No action specified.");
}
}
exit(0);
}
/**
* Adds a sub-node for the given XML node entry.
*
* @param XMLNode
* the XML node to add to (e.g. packages or settings)
* @param subNode
* the node to be added to the XMLNode (for example a package node)
* NOTE: The node will be cloned before add
* @return Returns true in case of success, returns false if no node could be
* added
*/
function addNode(XMLNode, subNode) {
var returnvalue = false;
var result = XMLNode.appendChild(subNode.cloneNode(true));
if(result != null) {
returnvalue = true;
}
return returnvalue;
}
/**
* Adds a package node to the settings XML node. In case a package with the same
* ID already exists it will be replaced.
*
* @param packageNode
* the package XML node to add.
* @param saveImmediately
* Set to true in order to save settings immediately after adding.
* Settings will not be saved immediately if value is false.
* @return true in case of success, otherwise returns false
*/
function addSettingsNode(packageNode, saveImmediately) {
// first remove entry if one already exists
// get current settings node
var packageID = getPackageID(packageNode);
var settingsNode = getSettingNode(packageID);
if (settingsNode != null) {
dinfo("Removing currently existing settings node first: '" +
getPackageName(settingsNode) + "' (" + getPackageID(settingsNode) +
"), Revision " + getPackageRevision(settingsNode) + ".");
removeSettingsNode(settingsNode, false);
}
dinfo("Adding settings node: '" +
getPackageName(packageNode) + "' (" + getPackageID(packageNode) +
"), Revision " + getPackageRevision(packageNode) + ".");
var success = addNode(getSettings(), packageNode);
// save settings if remove was successful
if (success && saveImmediately) {
saveSettings(true);
}
return success;
}
/**
* Adds a package node to the list of skipped packages during removal process.
*
* @param packageNode
* the node which has been skipped during removal
*/
function addSkippedRemoveNodes(packageNode) {
var skippedNodes = getSkippedRemoveNodes();
skippedNodes.push(packageNode);
}
/**
* Appends dependent profile nodes of the specified profile to the specified
* array. Recurses into self to get an entire dependency tree.
*/
function appendProfileDependencies(profileArray, profileNode) {
var profileNodes = getProfileDependencies(profileNode);
// add nodes if they are not yet part of the array
for (var i=0; i < profileNodes.length; i++) {
var currentNode = profileNodes[i];
if(!searchArray(profileArray, currentNode)) {
dinfo("Adding profile dependencies of profile '" +
getProfileID(profileNode) + "': '" +
getProfileID(currentNode) + "'");
profileArray.push(currentNode);
// add dependencies of these profiles as well
appendProfileDependencies(profileArray, currentNode);
} else {
dinfo("Profile '" +
getProfileID(currentNode) + "' " +
"already exists in profile dependency tree. Skipping.");