5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
22 # Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 # Use is subject to license terms.
26 .
/usr
/lib
/brand
/solaris10
/common.ksh
28 m_usage
=$
(gettext "solaris10 brand usage:\n\tinstall -u | -p [-v | -s] -a archive | -d directory.\n\tThe -a archive option specifies an archive name which can be a flar,\n\ttar, pax or cpio archive.\n\tThe -d directory option specifies an existing directory.\n\tThe -u option unconfigures the zone, -p preserves the configuration.")
30 no_install
=$
(gettext "Could not create install directory '%s'")
32 product_vers
=$
(gettext " Product: %s")
33 install_vers
=$
(gettext " Installer: %s")
34 install_zone
=$
(gettext " Zone: %s")
35 install_path
=$
(gettext " Path: %s")
36 installing
=$
(gettext " Installing: This may take several minutes...")
37 no_installing
=$
(gettext " Installing: Using pre-existing data in zonepath")
38 install_prog
=$
(gettext " Installing: %s")
40 install_fail
=$
(gettext " Result: *** Installation FAILED ***")
41 install_log
=$
(gettext " Log File: %s")
43 install_good
=$
(gettext " Result: Installation completed successfully.")
45 sanity_ok
=$
(gettext " Sanity Check: Passed. Looks like a Solaris 10 system.")
46 sanity_fail
=$
(gettext " Sanity Check: FAILED (see log for details).")
49 p2ving
=$
(gettext "Postprocessing: This may take a while...")
50 p2v_prog
=$
(gettext " Postprocess: ")
51 p2v_done
=$
(gettext " Result: Postprocessing complete.")
52 p2v_fail
=$
(gettext " Result: Postprocessing failed.")
54 root_full
=$
(gettext "Zonepath root %s exists and contains data; remove or move aside prior to install.")
57 $
(gettext "you must specify an installation source using '-a', '-d' or '-r'.\n%s")
60 $
(gettext "you must specify -u (sys-unconfig) or -p (preserve identity).\n%s")
62 mount_failed
=$
(gettext "ERROR: zonecfg(1M) 'fs' mount failed")
64 not_flar
=$
(gettext "Input is not a flash archive")
65 bad_flar
=$
(gettext "Flash archive is a corrupt")
66 unknown_archiver
=$
(gettext "Archiver %s is not supported")
68 # Clean up on interrupt
71 msg
=$
(gettext "Installation cancelled due to interrupt.")
74 # umount any mounted file systems
80 # If the install failed then clean up the ZFS datasets we created.
83 if (( $EXIT_CODE != $ZONE_SUBPROC_OK )); then
84 /usr
/lib
/brand
/solaris10
/uninstall
$ZONENAME $ZONEPATH -F
91 # The main body of the script starts here.
93 # This script should never be called directly by a user but rather should
94 # only be called by zoneadm to install a s10 system image into a zone.
98 # Exit code to return if install is interrupted or exit code is otherwise
101 EXIT_CODE
=$ZONE_SUBPROC_USAGE
103 trap trap_cleanup INT
106 # If we weren't passed at least two arguments, exit now.
107 (( $# < 2 )) && exit $ZONE_SUBPROC_USAGE
111 # XXX shared/common script currently uses lower case zonename & zonepath
115 ZONEROOT
="$ZONEPATH/root"
116 logdir
="$ZONEROOT/var/log"
118 shift; shift # remove ZONENAME and ZONEPATH from arguments array
126 # It is worth noting here that we require the end user to pick one of
127 # -u (sys-unconfig) or -p (preserve config). This is because we can't
128 # really know in advance which option makes a better default. Forcing
129 # the user to pick one or the other means that they will consider their
130 # choice and hopefully not be surprised or disappointed with the result.
136 while getopts "a:d:Fpr:suv" opt
140 if [[ -n "$inst_type" ]]; then
141 fatal
"$incompat_options" "$m_usage"
144 install_media
="$OPTARG"
147 if [[ -n "$inst_type" ]]; then
148 fatal
"$incompat_options" "$m_usage"
150 inst_type
="directory"
151 install_media
="$OPTARG"
154 p
) preserve_zone
="-p";;
156 if [[ -n "$inst_type" ]]; then
157 fatal
"$incompat_options" "$m_usage"
160 install_media
="$OPTARG"
163 u
) unconfig_zone
="-u";;
165 *) printf "$m_usage\n"
166 exit $ZONE_SUBPROC_USAGE;;
171 # The install can't be both verbose AND silent...
172 if [[ -n $silent_mode && -n $OPT_V ]]; then
173 fatal
"$incompat_options" "$m_usage"
176 if [[ -z $install_media ]]; then
177 fatal
"$media_missing" "$m_usage"
180 # The install can't both preserve and unconfigure
181 if [[ -n $unconfig_zone && -n $preserve_zone ]]; then
182 fatal
"$incompat_options" "$m_usage"
185 # Must pick one or the other.
186 if [[ -z $unconfig_zone && -z $preserve_zone ]]; then
187 fatal
"$cfgchoice_missing" "$m_usage"
190 LOGFILE
=$
(/usr
/bin
/mktemp
-t -p /var
/tmp
$ZONENAME.install_log.XXXXXX
)
191 if [[ -z "$LOGFILE" ]]; then
194 zone_logfile
="${logdir}/$ZONENAME.install$$.log"
196 log
"$install_log" "$LOGFILE"
198 vlog
"Starting pre-installation tasks."
201 # From here on out, an unspecified exit or interrupt should exit with
202 # ZONE_SUBPROC_NOTCOMPLETE, meaning a user will need to do an uninstall before
203 # attempting another install, as we've modified the directories we were going
204 # to install to in some way.
206 EXIT_CODE
=$ZONE_SUBPROC_NOTCOMPLETE
210 vlog
"Installation started for zone \"$ZONENAME\""
211 install_image
"$inst_type" "$install_media"
213 [[ "$SANITY_SKIP" == "1" ]] && touch $ZONEROOT/.sanity_skip
216 vlog
"running: p2v $OPT_V $unconfig_zone $ZONENAME $ZONEPATH"
221 # Getting the output to the right places is a little tricky because what
222 # we want is for p2v to output in the same way the installer does: verbose
223 # messages to the log file always, and verbose messages printed to the
224 # user if the user passes -v. This rules out simple redirection. And
225 # we can't use tee or other tricks because they cause us to lose the
226 # return value from the p2v script due to the way shell pipelines work.
228 # The simplest way to do this seems to be to hand off the management of
229 # the log file to the p2v script. So we run p2v with -l to tell it where
230 # to find the log file and then reopen the log (O_APPEND) when p2v is done.
232 /usr
/lib
/brand
/solaris10
/p2v
-l "$LOGFILE" -m "$p2v_prog" \
233 $OPT_V $unconfig_zone $ZONENAME $ZONEPATH
237 if (( $p2v_result == 0 )); then
243 log
"$install_log" "$LOGFILE"
244 exit $ZONE_SUBPROC_FATAL
247 # Add a service tag for this zone.
248 add_svc_tag
"$ZONENAME" "install $inst_type `basename $install_media`"
251 log
"$install_good" "$ZONENAME"
255 safe_copy
$LOGFILE $zone_logfile
257 log
"$install_log" "$zone_logfile"
260 # This needs to be set since the exit trap handler is going run.
261 EXIT_CODE
=$ZONE_SUBPROC_OK
263 exit $ZONE_SUBPROC_OK