-
Notifications
You must be signed in to change notification settings - Fork 11
/
create_zone.sh
6774 lines (5665 loc) · 203 KB
/
create_zone.sh
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
#!/usr/bin/ksh
#
# use "create_zone.sh {-v} -h" to get the usage help
#
# **** Note: The main code starts after the line containing "main:" ****
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License"). You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2006 - 2013 Bernd Schemmer All rights reserved.
# Use is subject to license terms.
#
# Notes:
#
# - use "create_zone.sh {-v} {-v} -h" to get the usage help
#
# - use "create_zone.sh -H 2>create_zone.doc" to get the documentation
#
# - this is a Kornshell script - it may not function correctly in other shells
# - the script was written and tested with ksh88 but should also work in ksh93
#
# The documentation for create_zone.sh and the newest version can be found here:
#
# http://bnsmb.de/solaris/create_zone.html
#
##
# -----------------------------------------------------------------------------
##
## create_zone.sh - script to create zones unattended
##
## Author: Bernd Schemmer ([email protected])
##
## Version: see variable ${__SCRIPT_VERSION} below
## (see variable ${__SCRIPT_TEMPLATE_VERSION} for the template
## version used)
##
## Supported OS: Solaris 10 and newer
##
##
## Description
##
## This script can be used to create and configure a zone without user interaction.
##
## The script supports a finish script for the zone, a customization script for the zone,
## and a SMF profile. Various settings for the zone can be done via parameter and a
## configuration file.
##
## Configuration file
##
## This script supports a configuration file called create_zone.conf.
## The configuration file is searched in the working directory,
## the home directory of the user executing this script and /etc
## (in this order).
##
## The configuration file is read before the parameter are read.
##
## See the variable __CONFIG_PARAMETER below for the possible entries in
## the config file.
##
## Predefined parameter
##
## see the subroutines ShowShortUsage and ShowUsage
##
## Note: The current version of the script template can be found here:
##
## http://bnsmb.de/solaris/scriptt.html
##
##
## Credits
## wpollock (http://wikis.sun.com/display/~wpollock)
## -- http://wikis.sun.com/display/BigAdmin/A+Script+Template+and+Useful+Techniques+for+ksh+Scripts?focusedCommentId=12517624#comment-12517624
##
## Source for the function PrintWithTimeStamp:
## Bernd Fingers blog:
## http://blogs.sun.com/blogfinger/entry/prepend_command_output_lines_with
##
## Nicolas Dorfsman for the idea for the parameter -N (cloning) and -t (template)
##
##
## History:
## 12.06.2006 /bs
## initial release
## 12.03.2008 v1.1.0 /bs
## added support for IP instances
## use a newer version of the script template
## 15.03.2008 v1.1.1 /bs
## added the config options zone_memory_limit, zone_swap_limit, zone_cpu_count, and zone_cpu_shares
## 17.03.2008 v1.1.2 /bs
## added the option -e (edit)
## added the config option zone_inherited_dir and the option -d
## added the syntax xx.xx.xx.xx/yy for the IP address (use /yy to specify the netmask)
## 18.03.2008 v1.1.3 /bs
## added the config option zone_writable_dir and the option -w (writabledir)
## improved the error handling
## 15.05.2008 v1.1.4 /bs
## added workaround for the "GLDv3 support" for the ce adapter
## see: http://sunsolve.sun.com/search/document.do?assetkey=1-61-234401-1
## added the config options zone_gldv3_check
## 08.02.2009 v1.1.5 /bs
## added support for the defrouter configuration for zones in Solaris U6 and newer
## The list of file that are copied to a zone with exclusive IP stack can now be
## configured in the config file; see the variable EXCLUSIVE_IP_STACK_CONFIG_FILES
## 15.02.2009 v1.1.6 /bs
## added support for ZFS datasets (parameter -Z)
## added support for cloning a zone (parameter -N)
## 18.02.2009 v1.1.7 /bs
## added support for other global config entries
## added suport for devices for the zone
## 25.02.2009 v1.1.8 /bs
## added support for new dladm options
## added the parameter -t (--templatedir) to specify template directories
## added the config options zone_netmask for zones with exclusive IP stack
## create_zone.sh did not create a complete sysidcfg for zones with exclusive IP. Fixed.
## remove the call of prtdiag; __MACHINE_SUBTYPE is now always empty
## 28.02.2009 v1.1.9 /bs
## the default for the zone template directories (parameter -t) is now
## "${DEFAULT_ZONE_PATH}/template_dir"
## if that directory exist
## create_zones.sh now creates a correct sysidcfg file if USE_EXISTING_NAMESERVER_CONFIG
## is set to y
## 29.03.2009 v1.1.10 /bs
## added the parameter -R (--readonlydir) to configure add. read-only directories for the
## zone
## 31.08.2009 v1.1.11 /bs
## corrected a bug in the format of the created sysidcfg file
## added code to set the timezone in the file /etc/TIMEZONE in the zone to avoid one reboot
## added
## svcadm disable svc:/application/cde-printinfo:default
## to the builtin customize script for the zones
## The default run level for the customize script is now rcS.d:
## DEFAULT_ZONE_CUSTOMIZE_SCRIPT_TARGET="/etc/rcS.d/S99customize_script"
## The script noew creates a config file inside the zone with the zone configuration
## variables called
## /etc/create_zone.cfg
## (this are all variables used in this script with a name beginning with ZONE_)
## 03.09.2009 v1.1.12 /bs
## the script did not handle timezones with a slash "/" correct. Fixed.
## the script now removes the entries for localhost from the /etc/hosts file before
## copying it to the zone
## 09.09.2009 v1.1.13 /bs
## the script did not handle incomplete resolv.conf files correct. Fixed
## 17.09.2009 v1.1.14 /bs
## not released
##
## 17.09.2009 v1.1.15 /bs
## added code to copy files from the global zone to the non-global zone
## (parameter -c)
## the home directory for root is now configured as in the global zone
## 29.09.2010 v1.1.16/bs
## added a workaround for a bug in the zoneadm commands
## 22.03.2011 v1.1.17 /bs
## added a check for additional directories for the zone
## removed the restriction to run only once at a time
## added the keyword zone_add_network_interface to define additional network
## interfaces for the zone
## added the parameter -B (zone_config_only)
## some cosmetic changes
## 25.10.2012 v1.1.18 /bs
## changed the code to cleanup existing zone directories -- now it only deletes the
## files and directories in the zone directory and not the zone directory
## 01.11.2012 v1.1.19 /bs
## corrected a bug in the TIMEZONE handling
## 07.11.2012 v1.1.20 /bs
## added the parameter -P <zone_path_absolute>
## ZFS filesystems are now supported for the global directories to be used by
## the zone (parameter -w and -R)
## added support for flash image installations (-x zone_flashimage)
## -x zone_netmask= is now also used for shared IP stack configurations
## code cleanup${THIS_MOUNTPOOINT
## added more parameter checks
## 17.12.2012 v1.1.21 /bs
## added code to workaround a "bug" in the zfs list command
## (zfs list <dirname> returns always 0)
## 18.12.2012 v1.1.22 /bs
## disabled all not necessary checks if configure only mode is used
## added the parameter -F to disable all zone configuration checks
## code cleanup
## 10.01.2013 v1.1.23/bs
## added the parameter -x zone_hostid=<hostid>
## create_zone.sh will now NOT stop or delete a zone if -O and -B are used
## added the keyword zone_set_global_option for -x
##
## 13.02.2013 v1.1.24/bs
## corrected invalid options for ZFS filesystems for the zone (ro instead rw)
##
## 26.03.2013 v1.1.25/bs
## corrected some bugs for configure only tasks
## use "cp -p" instead of "cp " to copy files
##
## 19.07.2013 v1.1.26/bs
## added support for capped-cpu (parameter -x zone_capped_cpu_count)
## added initial support for branded zones (parameter -x brand)
##
## script template History
## -----------------------
## 1.22.0 08.06.2006 /bs (BigAdmin Version 1)
## public release; starting history for the script template
##
## 1.22.1 12.06.2006 /bs
## added true/false to CheckYNParameter and ConvertToYesNo
##
## 1.22.2. 21.06.2006 /bs
## added the parameter -V
## added the use of environment variables
## added the variable __NO_TIME_STAMPS
## added the variable __NO_HEADERS
## corrected a bug in the function executeCommandAndLogSTDERR
## added missing return commands
##
## 1.22.3 24.06.2006 /bs
## added the function StartStop_LogAll_to_logfile
## added the variable __USE_TTY (used in AskUser)
## corrected an spelling error (dev/nul instead of /dev/null)
##
## 1.22.4 06.07.2006 /bs
## corrected a bug in the parameter error handling routine
##
## 1.22.5 27.07.2006 /bs
## corrected some minor bugs
##
## 1.22.6 09.08.2006 /bs
## corrected some minor bugs
##
## 1.22.7 17.08.2006 /bs
## add the CheckParameterCount function
## added the parameter -T
## added long parameter support (e.g --help)
##
## 1.22.8 07.09.2006 /bs
## added code to save the env variable LANG and set it temporary to C
##
## 1.22.9 20.09.2006 /bs
## corrected code to save the env variable LANG and set it temporary to C
##
## 1.22.10 21.09.2006 /bs content/sunsolve/archives/082007.html
## cleanup comments
## the number of temporary files created automatically is now variable
## (see the variable __NO_OF_TEMPFILES)
## added code to install the trap handler in all functions
##
## 1.22.11 19.10.2006 /bs
## corrected a minor bug in AskUser (/c was not interpreted by echo)
## corrected a bug in the handling of the parameter -S (-S was ignored)
##
## 1.22.12 31.10.2006 /bs
## added the variable __REQUIRED_ZONE
##
## 1.22.13 13.11.2006 /bs
## the template now uses TMP or TEMP if set for the temporary files
##
## 1.22.14 14.11.2006 /bs
## corrected a bug in the function AskUser (the default was y not n)
##
## 1.22.15 21.11.2006 /bs
## added initial support for other Operating Systems
##
## 1.22.16 05.07.2007 /bs
## enhanced initial support for other Operating Systems
## Support for other OS is still not fully tested!
##
## 1.22.17 06.07.2007 /bs
## added the global variable __TRAP_SIGNAL
##
## 1.22.18 01.08.2007 /bs
## __OS_VERSION and __OS_RELEASE were not set - corrected
##
## 1.22.19 04.08.2007 /bs
## wrong function used to print "__TRAP_SIGNAL is \"${__TRAP_SIGNAL}\"" - fixed
##
## 1.22.20 12.09.2007 /bs
## the script now checks the ksh version if running on Solaris
## made some changes for compatibility with ksh93
##
## 1.22.21 18.09.2007 /bs (BigAdmin Version 2)
## added the variable __FINISHROUTINES
## changed __REQUIRED_ZONE to __REQUIRED_ZONES
## added the variable __KSH_VERSION
## reworked the trap handling
##
## 1.22.22 23.09.2007 /bs
## added the signal handling for SIGUSR1 and SIGUSR2 (variables __SIGUSR1_FUNC and __SIGUSR2_FUNC)
## added user defined function for the signals HUP, BREAK, TERM, QUIT, EXIT, USR1 and USR2
## added the variables __WARNING_PREFIX, __ERROR_PREFIX, __INFO_PREFIX, and __RUNTIME_INFO_PREFIX
## the parameter -T or --tee can now be on any position in the parameters
## the default output file if called with -T or --tee is now
## /var/tmp/${0##*/}.$$.tee.log
##
## 1.22.23 25.09.2007 /bs
## added the environment variables __INFO_PREFIX, __WARNING_PREFIX,
## __ERROR_PREFIX, and __RUNTIME_INFO_PREFIX
## added the environment variable __DEBUG_HISTFILE
## reworked the function to print the usage help :
## use "-h -v" to view the extented usage help and use "-h -v -v" to
## view the environment variables used also
##
## 1.22.24 05.10.2007 /bs
## another minor fix for ksh93 compatibility
##
## 1.22.25 08.10.2007 /bs
## only spelling errors corrected
##
## 1.22.26 19.11.2007 /bs
## only spelling errors corrected
##
## 1.22.27 29.12.2007 /bs
## improved the code to create the lockfile (thanks to wpollock for the info; see credits above)
## improved the code to create the temporary files (thanks to wpollock for the info; see credits above)
## added the function rand (thanks to wpollock for the info; see credits above)
## the script now uses the directory name saved in the variable $TMPDIR for temporary files
## if it's defined
## now the umask used for creating temporary files can be changed (via variable __TEMPFILE_UMASK)
##
## 1.22.28 12.01.2008 /bs
## corrected a syntax error in the show usage routine
## added the function PrintWithTimestamp (see credits above)
##
## 1.22.29 31.01.2008 /bs
## there was a bug in the new code to remove the lockfile which prevented
## the script from removing the lockfile at program end
## if the lockfile already exist the script printed not the correct error
## message
##
## 1.22.30 28.02.2008 /bs
## Info update: executeCommandAndLog does NOT return the RC of the executed
## command if a logfile is defined
## added inital support for CYGWIN
## (tested with CYGWIN_NT-5.1 v..1.5.20(0.156/4/2)
## Most of the internal functions are NOT tested yet in CYGWIN
## GetCurrentUID now supports UIDs greater than 254; the function now prints the UID to STDOUT
## Corrected bug in GetUserName (only a workaround, not the solution)
## now using printf in the AskUserRoutine
##
## ----------------
## Version variables
##
## __SCRIPT_VERSION - the version of your script
##
# Note: CYGWIN ksh does not like typeset -r
##
typeset __SCRIPT_VERSION="v1.1.26"
##
## __SCRIPT_TEMPLATE_VERSION - version of the script template
##
typeset __SCRIPT_TEMPLATE_VERSION="1.22.30 28.02.2008"
##
## ----------------
##
## Predefined return codes:
##
## 1 - show usage and exit
## 2 - invalid parameter found
##
## 210 - 236 reserved for the runtime system
## 237 - script file has to many lines for the debug handler
## 238 - unsupported Operating system
## 239 - script runs in a not supported zone
## 240 - internal error
## 241 - a command ended with an error (set -e is necessary to activate this trap)
## 242 - the current user is not allowed to execute this script
## 243 - invalid machine architecture
## 244 - invalid processor type
## 245 - invalid machine platform
## 246 - error writing the config file
## 247 - include script not found
## 248 - unsupported OS version
## 249 - Script not executed by root
## 250 - Script is already running
##
## 251 - QUIT signal received
## 252 - User break
## 253 - TERM signal received
## 254 - unknown external signal received
##
## 3 "Use either the parameter ZONE_PATH or ZONE_PATH_ABSOLUTE -- not both"
## 4 "ZONE_PATH_ABSOLUTE can not be the root directory"
## 5 "The parameter for the name of the zone is missing"
## 8 "The parameter for the IP address of the zone is missing"
## 11 "The directory for the zone \"${ZONE_PATH}\" does not exist"
## 12 "You must specifiy a network interface (-A) if creating a zone with exclusive IP stack (-I)"
## 15 "Can not detect the interface for the zone (use -A to specify the interface)"
## 14 "Script aborted by the user"
## 17 "Error reading the customize script for the zone \"${ZONE_CUSTOMIZE_SCRIPT_SOURCE}\" "
## 20 "Zone configuration is not okay"
## 23 "Error calling zonecfg -z ${ZONE_NAME} delete -F"
## 26 "Can not cleanup the existing zone directory \"${THIS_ZONE_PATH}\""
## 27 "Can not create the directory \"${WRITABLE_GLOBAL_DIR}\" "
## 28
## 29 "Error configuring the zone \"${ZONE_NAME}\""
## 32 "Error installing the zone \"${ZONE_NAME}\""
## 35 "Error preparing the zone \"${ZONE_NAME}\""
## 36 "Use either dedicated CPUs or CPU shares for the zone -- but not both"
## 37 "Use either a flashimage or a source zone for the installation -- but not both"
## 38 "A flashimage or a zone to be cloned can not be used if zone_config_only is true"
##
## 100 - error creating the sysidcfg file of the zone
## 102 - error creating one of the files for the nameserver configuration
## 105 - error creating the directory for the customize script for the zone
## 106 - error creating the customize script for the zone
## 107 - error creating the SMF profile for the zone
## 108 - the finish script for the zone returned an error
## 109 - error booting the zone
##
## ----------------
## Used environment variables
##
#
# Note: The variable __USED_ENVIRONMENT_VARIABLES is used in the function ShowUsage
#
__USED_ENVIRONMENT_VARIABLES="
## __DEBUG_CODE
## __RT_VERBOSE_LEVEL
## __QUIET_MODE
## __VERBOSE_MODE
## __VERBOSE_LEVEL
## __OVERWRITE_MODE
## __USER_BREAK_ALLOWED
## __NO_TIME_STAMPS
## __NO_HEADERS
## __USE_COLORS
## __USE_RBAC
## __TEE_OUTPUT_FILE
## __INFO_PREFIX
## __WARNING_PREFIX
## __ERROR_PREFIX
## __RUNTIME_INFO_PREFIX
## __DEBUG_HISTFILE
"
#
# binaries and scripts used in this script:
#
# basename cat cp cpio cut date dd dirname expr find grep id ln ls nawk prtdiag pwd
# reboot rm sed sh tee touch tty umount uname who zonename
#
# /usr/bin/pfexec
# /usr/ucb/whoami or $( whence whoami )
# /usr/openwin/bin/resize or $( whence resize )
#
# AIX: oslevel
#
# -----------------------------------------------------------------------------
# variables for the trap handler
__FUNCTION="main"
# alias to install the trap handler
#
# Note: The statement LINENO=${LINENO} is necessary to use the variable LINENO in the trap command
#
alias __settrap="
LINENO=\${LINENO}
trap 'GENERAL_SIGNAL_HANDLER SIGHUP \${LINENO} \${__FUNCTION}' 1
trap 'GENERAL_SIGNAL_HANDLER SIGINT \${LINENO} \${__FUNCTION}' 2
trap 'GENERAL_SIGNAL_HANDLER SIGQUIT \${LINENO} \${__FUNCTION}' 3
trap 'GENERAL_SIGNAL_HANDLER SIGTERM \${LINENO} \${__FUNCTION}' 15
trap 'GENERAL_SIGNAL_HANDLER SIGUSR1 \${LINENO} \${__FUNCTION}' USR1
trap 'GENERAL_SIGNAL_HANDLER SIGUSR2 \${LINENO} \${__FUNCTION}' USR2
"
##
## ----------------
## ##### general hints
##
## Do not use variable names beginning with __ (these are reserved for
## internal use)
##
# -----------------------------------------------------------------------------
## __KSH_VERSION - ksh version (either 88 or 93)
##
__KSH_VERSION=88 ; f() { typeset __KSH_VERSION=93 ; } ; f ;
# save the language setting and switch the language temporary to C
#
__SAVE_LANG="${LANG}"
LANG=C
export LANG
# -----------------------------------------------------------------------------
## ##### constants
##
## __TRUE - true (0)
## __FALSE - false (1)
##
# Note: CYGWIN ksh does not like typeset -r
##
typeset __TRUE=0
typeset __FALSE=1
## ----------------
## __OS - Operating system (e.g. SunOS)
##
__OS="$( uname -s )"
case ${__OS} in
CYGWIN* ) set +o noclobber
;;
* )
:
;;
esac
## ----------------
## internal variables
##
## __TRAP_SIGNAL - current trap caught by the trap handler
## This is a global variable that can be used in the exit routines
##
__TRAP_SIGNAL=""
# -----------------------------------------------------------------------------
## __USE_RBAC - set this variable to ${__TRUE} to execute this script
## with RBAC
## default is ${__FALSE}
##
## Note: You can also set this environment variable before starting the script
##
__USE_RBAC=${__USE_RBAC:=${__FALSE}}
# -----------------------------------------------------------------------------
## __TEE_OUTPUT_FILE - name of the output file if called with the parameter -T
## default: var/tmp/$( basename $0 ).$$.tee.log
##
## Note: You can also set this environment variable before starting the script
##
__TEE_OUTPUT_FILE="${__TEE_OUTPUT_FILE:=/var/tmp/${0##*/}.$$.tee.log}"
# -----------------------------------------------------------------------------
# use the parameter --tee to automatically call the script and pipe
# all output to tee
if [ "${__PPID}"x = ""x ] ; then
__PPID=$PPID ; export __PPID
if [[ \ $*\ == *\ -T* || \ $*\ == *\ --tee\ * ]] ; then
echo "Saving STDOUT and STDERR to \"${__TEE_OUTPUT_FILE}\" ..."
exec $0 $@ 2>&1 | tee -a "${__TEE_OUTPUT_FILE}"
__MAINRC=$?
echo "STDOUT and STDERR saved in \"${__TEE_OUTPUT_FILE}\"."
exit ${__MAINRC}
fi
fi
[ "${__PPID}"x = ""x ] && __PPID=$PPID ; export __PPID
# -----------------------------------------------------------------------------
#
# Set the variable ${__USE_RBAC} to ${__TRUE} to activate RBAC support
#
# Allow the use of RBAC to control who can access this script. Useful for
# administrators without root permissions
#
if [ "${__USE_RBAC}" = "${__TRUE}" ] ; then
if [ "$_" != "/usr/bin/pfexec" -a -x /usr/bin/pfexec ]; then
/usr/bin/pfexec $0 $*
exit $?
else
echo "${0%%*/} ERROR: /usr/bin/pfexec not found or not executable!" >&2
exit 238
fi
fi
# -----------------------------------------------------------------------------
##
## ##### defined variables that may be changed
##
## __DEBUG_CODE - code executed at start of every sub routine
## Note: Use always "__DEBUG_CODE="eval ..." if you want to use variables or aliases
## Default debug code : none
##
# __DEBUG_CODE=""
## __FUNCTION_INIT - code executed at start of every sub routine
## (see the hints for __DEBUG_CODE)
## Default init code : install the trap handlers
##
if [[ ${__OS} == CYGWIN* ]] ; then
__FUNCTION_INIT=""
else
__FUNCTION_INIT=" eval __settrap"
fi
##
## sample debug code:
## __DEBUG_CODE=" eval echo Entering the subroutine \${__FUNCTION} ... "
##
## Note: Use an include script for more complicate debug code, e.g.
## __DEBUG_CODE=" eval . /var/tmp/mydebugcode"
##
## __CONFIG_PARAMETER
## The variable __CONFIG_PARAMETER contains the configuration variables
##
## The defaults for these variables are defined here. You
## can use a config file to overwrite the defaults.
##
## Use the parameter -C to create a default configuration file
##
## Note: The config file is read and interpreted via ". configfile"
## therefore you can also add some code her
##
__CONFIG_PARAMETER='
# extension for backup files
DEFAULT_BACKUP_EXTENSION=".$$.backup"
## EXCLUSIVE_IP_STACK_CONFIG_FILES
## network configuration files that will be copied from the global zone
## to the non-global zone if an exclusive IP stack is used
## Note: Add only fully qualified filenames here!
##
EXCLUSIVE_IP_STACK_CONFIG_FILES="
/etc/netmasks
/etc/networks
/etc/defaultrouter
/etc/hosts
"
## NAME_SERVER_CONFIG_FILES
## name server configuration files
## Note: Add only fully qualified filenames here!
##
NAME_SERVER_CONFIG_FILES="
/etc/resolv.conf
/etc/nsswitch.conf
"
## DEFAULT_FREE_SPACE_FOR_THE_ZONE
## free space neccessary for the zone in KB
## (the default depends on the type of the zone)
##
DEFAULT_FREE_SPACE_FOR_THE_ZONE=""
## DEFAULT_FREE_SPACE_FOR_A_BIG_ZONE
## default free space needed for a big zone in KB
##
DEFAULT_FREE_SPACE_FOR_A_BIG_ZONE=3500000
## DEFAULT_FREE_SPACE_FOR_A_SMALL_ZONE
## default free space needed for a small zone in KB
##
DEFAULT_FREE_SPACE_FOR_A_SMALL_ZONE=200000
## DEFAULT_ZONE_CONFIG_ONLY
## if true the zone will only be configured but not installed
## default: configure and install the zone
##
DEFAULT_ZONE_CONFIG_ONLY=${__FALSE}
## DEFAULT_NO_ZONE_CONFIG_CHECKS
## if true the script will not check the zone configuration
## default: check the zone configuration before creating the zone
##
DEFAULT_NO_ZONE_CONFIG_CHECKS=${__FALSE}
## DEFAULT_ZONE_MODE
## default type of the new zone;
## possible values: small (= sparse zone) or big (= whole root zone)
##
DEFAULT_ZONE_MODE="small"
## DEFAULT_ZONE_CLONE_SOURCE
## source zone for cloning
##
DEFAULT_ZONE_CLONE_SOURCE=""
## DEFAULT_ZONE_PATH
## base directory for zones (can be a symbolic link;
## this will be resolved by the script)
## Use either ZONE_PATH or ZONE_PATH_ABSOLUTE -- not both
## (see comments for ZONE_PATH_ABSOLUTE)
##
DEFAULT_ZONE_PATH="/zones"
## DEFAULT_ZONE_PATH_ABSOLUTE
## absolute directory for the zone (can be a symbolic link;
## this will be resolved by the script)
##
## e.g.
## ZONE_NAME=myzone
## ZONE_PATH=/zones/myzone
## -> The zone will be created in the directory /zones/myzone/myzone
##
## ZONE_NAME=myzone
## ZONE_PATH_ABSOLUTE=/zones/myzone
## -> The zone will be created in the directory /zones/myzone
##
## Notes:
## Use either ZONE_PATH or ZONE_PATH_ABSOLUTE -- not both
##
DEFAULT_ZONE_PATH_ABSOLUTE=""
## DEFAULT_ZONE_FLASHIMAGE
## flash image for the installation of the zone
## default: none
##
DEFAULT_ZONE_FLASHIMAGE=""
## DEFAULT_ZONE_ROOT_PASSWORD
## default for the root password is the password
## of the existing root user
##
DEFAULT_ZONE_ROOT_PASSWORD="$( grep root /etc/shadow 2>/dev/null | cut -f2 -d ":" )"
## DEFAULT_ZONE_TZ
## the default timezone is the timezone of the machine
##
DEFAULT_ZONE_TZ="$( grep "^TZ=" /etc/TIMEZONE 2>/dev/null | cut -f2 -d"=" )"
[ "${DEFAULT_ZONE_TZ}"x = ""x ] && DEFAULT_ZONE_TZ="${TZ}"
## DEFAULT_ZONE_LOCALE
## default locale is the current locale
##
DEFAULT_ZONE_LOCALE="${LANG}"
[ "${DEFAULT_ZONE_LOCAL}"x = ""x ] && DEFAULT_ZONE_LOCALE="C"
## DEFAULT_ZONE_TERMINAL
## default terminal type for the zone
##
DEFAULT_ZONE_TERMINAL="${TERM:-vt100}"
## DEFAULT_ZONE_TIMESERVER
## default timeserver for the zones
##
DEFAULT_ZONE_TIMESERVER="localhost"
## DEFAULT_ZONE_CUSTOMIZE_SCRIPT_SOURCE
## default customize script for the zone
## Possible values for this variabe are:
## "builtin", "none", or the name of an existing script
## The customize script runs inside the new zone
## while first rebooting the zone
##
DEFAULT_ZONE_CUSTOMIZE_SCRIPT_SOURCE="builtin"
## DEFAULT_ZONE_CUSTOMIZE_SCRIPT_TARGET
## fully qualified name of the customize script inside the zone
##
## Note: The runlevel in which the script runs depends on the path of the
## customize scripts
## The default is rcS.d = single-user-mode
##
DEFAULT_ZONE_CUSTOMIZE_SCRIPT_TARGET="/etc/rcS.d/S99customize_script"
## DEFAULT_ZONE_SMF_PROFILE
## SMF site profile for the zone; default: none
##
DEFAULT_ZONE_SMF_PROFILE=""
## DEFAULT_ZONE_IP_ADDRESS
## there is no default IP address for the zone
##
DEFAULT_ZONE_IP_ADDRESS=""
## DEFAULT_ZONE_IP_STACK
## this can be either SHARED or EXCLUSIVE; the default is SHARED
##
DEFAULT_ZONE_IP_STACK="SHARED"
## DEFAULT_ZONE_NETMASK
## netmask for the zone
##
DEFAULT_ZONE_NETMASK=""
## DEFAULT_ZONE_DEFAULT_ROUTER
## default router for the zones
## Note: A default router for a zone can only be configured for zones in Solaris 10 Update 6 and newer
##
DEFAULT_ZONE_DEFAULT_ROUTER=""
# $( netstat -rn | grep "^default" | tr -s " " | cut -f2 -d " " | head -1 )"
## ZONE_GLDV3_CHECK
## Do check the GLDv3 capabiltiy (yes, default) of the network adapter or not (no)
##
DEFAULT_ZONE_GLDV3_CHECK="yes"
## DEFAULT_ZONE_NAME
## there is no default name for the zone
##
DEFAULT_ZONE_NAME=""
## DEFAULT_ZONE_GLOBAL_OPTIONS
## additional global options for the zone
## that use the syntax "option=value" or "option"
## You can NOT use blanks in the parameter
## for this option!
## Please note that the script DOES not check the syntax or semantic for these entries!
##
DEFAULT_ZONE_GLOBAL_OPTIONS=""
## DEFAULT_ZONE_BRAND
## brand for the zone, e.g. SUNWsolaris8
## Default is : use the installed Solaris version
##
DEFAULT_ZONE_BRAND=""
## DEFAULT_ZONE_SET_GLOBAL_OPTIONS
## additional global options for the zone
## that use the syntax "set option=value"
## Please note that the script DOES not check the syntax or semantic for these entries!
##
DEFAULT_ZONE_SET_GLOBAL_OPTIONS=""
## DEFAULT_ZONE_HOSTID
## hostid for the zone
##
DEFAULT_ZONE_HOSTID=""
## DEFAULT_USE_EXISTING_NAMESERVER_CONFIG
## default nameserver configuration is:
## use the existing nameserver configuration
##
DEFAULT_USE_EXISTING_NAMESERVER_CONFIG=${__TRUE}
## DEFAULT_ZONE_AUTOBOOT
## enable zone autoboot?; default is false
##
DEFAULT_ZONE_AUTOBOOT=${__FALSE}
## DEFAULT_ZONE_NETWORK_INTERFACE
## the default network interface for the zone
## The default is the network interface which hosts the
## network with the IP address for the zone
##
DEFAULT_ZONE_NETWORK_INTERFACE=""
## DEFAULT_ZONE_ADD_NETWORK_INTERFACE
## additional network interfaces for the zones
##
DEFAULT_ZONE_ADD_NETWORK_INTERFACE=""
## DEFAULT_BOOT_THE_ZONE_NOW
## boot the zone after installation?
##
DEFAULT_BOOT_THE_ZONE_NOW=${__FALSE}
## DEFAULT_ZONE_MEMORY_LIMIT
## the memory limit for the zone
## There is no default for this keyword
## Note that this configuration is only supported in
## Solaris 10 8/07 and newer!
##
DEFAULT_ZONE_MEMORY_LIMIT=""
## DEFAULT_ZONE_SWAP_LIMIT
## the swap limit for the zone
## There is no default for this keyword
## Note that this configuration is only supported in
## Solaris 10 8/07 and newer!
##
DEFAULT_ZONE_SWAP_LIMIT=""
## DEFAULT_ZONE_CAPPED_CPU_COUNT
## the max. number of CPUs for the zone
## There is no default for this keyword
##
DEFAULT_ZONE_CAPPED_CPU_COUNT=""
## DEFAULT_ZONE_CPU_COUNT
## the number of CPUs for the zone
## There is no default for this keyword
## Note that this configuration is only supported in
## Solaris 10 8/07 and newer!
##
DEFAULT_ZONE_CPU_COUNT=""
## DEFAULT_ZONE_CPU_SHARES
## the number of CPU shares for the zone
## There is no default for this keyword
## Note that this configuration is only supported in
## Solaris 10 8/07 and newer!
##
DEFAULT_ZONE_CPU_SHARES=""
## DEFAULT_ZONE_INHERITED_DIRS
## add. directories that should be inherited by the zone
## Note: Directories with space or tabs in the name are NOT supported!
##
DEFAULT_ZONE_INHERITED_DIRS=""
## DEFAULT_ZONE_WRITABLE_DIRS
## directories that should be mounted r/w in the zone
## Format of the entries:
## zone_dir:global_dir
## Note: Directories with space or tabs in the name are NOT supported!
## global_dir can be either a directory or ZFS filesystem.
##
DEFAULT_ZONE_WRITABLE_DIRS=""
## DEFAULT_ZONE_READONLY_DIRS
## directories that should be mounted r/o in the zone
## Format of the entries:
## zone_dir:global_dir
## Note: Directories with space or tabs in the name are NOT supported!
## global_dir can be either a directory or ZFS filesystem.
##
DEFAULT_ZONE_READONLY_DIRS=""
## DEFAULT_ZONE_DATASETS
## ZFS datasets for the zone
##
DEFAULT_ZONE_DATASETS=""
## DEFAULT_ZONE_DEVICES
##
DEFAULT_ZONE_DEVICES=""
## DEFAULT_EDIT_ZONE_CONFIG
## edit the zone configuration before creating the zone
## after exiting the editor the user can choose to continue
## or to abort the zone installation
##
## Note: The editor used is ${EDITOR}
##
DEFAULT_EDIT_ZONE_CONFIG=${__FALSE}
## DEFAULT_ZONE_TEMPLATE_DIRS
## Template directories for the zone; all files and directories in the
## directories listed in this variable are copied to the root dir of the
## zone
if [ -d "${DEFAULT_ZONE_PATH}/template_dir" ] ; then
ZONE_TEMPLATE_DIRS="${DEFAULT_ZONE_PATH}/template_dir"
else
ZONE_TEMPLATE_DIRS=""
fi
## DEFAULT_ZONE_FILES_TO_COPY
## File which should be copied from the global zone to the non-global zone
## The file(s) are copied to the same location in the non-global zone
##
DEFAULT_ZONE_FILES_TO_COPY=""
## DEFAULT_ZONE_FINISH_SCRIPT
##
## finish script for creating the zone
## This script is called in the global zone after the new
## zone is created and configured but before the zone is booted
## The parameters for the script are
## - the fully qualified name of the directory for the zone
##
## Note: Please write your finish scripts so that they handle multiple parameter correct
## because there may be additional parameter in a future version of this script!
##
## The finish script must return 0 if everything is okay; everthing else
## is interpreted as error and the script stops.
##
## Note that you can change the configuration of the zone from within the finish script
## with a few exceptions (e.g. you can NOT add directories to inherit here)
##
## All environment variables beginning with ZONE_ are exported and can be used by the
## finish script. The exported variables are:
##
## ZONE_CONFIG_ONLY
## ZONE_AUTOBOOT
## ZONE_CLONE_SOURCE
## ZONE_CUSTOMIZE_SCRIPT_CONTENTS
## ZONE_CUSTOMIZE_SCRIPT_SOURCE
## ZONE_CUSTOMIZE_SCRIPT_TARGET
## ZONE_FINISH_SCRIPT
## ZONE_IP_ADDRESS
## ZONE_LOCALE
## ZONE_MODE
## ZONE_NAME
## ZONE_NETWORK_INTERFACE
## ZONE_ADD_NETWORK_INTERFACE
## ZONE_PATH
## ZONE_PATH_ABSOLUTE