remove code related to labeled brands
[unleashed-pkg5.git] / src / brand / image_install
blobb6bb36b5213cf907e68d4032747f7399c788c2b4
1 #!/bin/ksh -p
3 # CDDL HEADER START
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]
20 # CDDL HEADER END
22 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 # Use is subject to license terms.
27 # image_install is used when installing a zone in a 'p2v' scenario. In
28 # this case the zone install hook will branch off to this script which
29 # is responsible for setting up the physical system image in the zonepath
30 # and performing the various modifications necessary to enable a physical
31 # system image to run inside a zone. This script sets up the image in the
32 # zonepath then calls the p2v script to modify the image to run in a zone.
35 . /usr/lib/brand/ipkg/common.ksh
37 m_usage=$(gettext "\n install {-a archive|-d path} {-p|-u} [-s|-v]")
38 install_log=$(gettext " Log File: %s")
40 p2ving=$(gettext "Postprocessing: This may take a while...")
41 p2v_prog=$(gettext " Postprocess: ")
42 p2v_done=$(gettext " Result: Postprocessing complete.")
43 p2v_fail=$(gettext " Result: Postprocessing failed.")
45 media_missing=\
46 $(gettext "%s: you must specify an installation source using '-a' or '-d'.")
47 cfgchoice_missing=\
48 $(gettext "you must specify -u (sys-unconfig) or -p (preserve identity).")
50 # Clean up on interrupt
51 trap_cleanup()
53 msg=$(gettext "Installation cancelled due to interrupt.")
54 log "$msg"
56 trap_exit
59 # If the install failed then clean up the ZFS datasets we created.
60 trap_exit()
62 # umount any mounted file systems
63 [[ -n "$fstmpfile" ]] && umnt_fs
65 if (( $zone_is_mounted != 0 )); then
66 error "$v_unmount"
67 zoneadm -z $ZONENAME unmount
68 zone_is_mounted=0
71 if (( $EXIT_CODE != $ZONE_SUBPROC_OK )); then
72 /usr/lib/brand/ipkg/uninstall $ZONENAME $ZONEPATH -F
75 exit $EXIT_CODE
79 # The main body of the script starts here.
81 # This script should never be called directly by a user but rather should
82 # only be called by pkgcreatezone to install an OpenSolaris system image into
83 # a zone.
87 # Exit code to return if install is interrupted or exit code is otherwise
88 # unspecified.
90 EXIT_CODE=$ZONE_SUBPROC_USAGE
92 zone_is_mounted=0
93 trap trap_cleanup INT
94 trap trap_exit EXIT
96 # If we weren't passed at least two arguments, exit now.
97 (( $# < 2 )) && exit $ZONE_SUBPROC_USAGE
99 ZONENAME="$1"
100 ZONEPATH="$2"
101 # XXX shared/common script currently uses lower case zonename & zonepath
102 zonename="$ZONENAME"
103 zonepath="$ZONEPATH"
105 ZONEROOT="$ZONEPATH/root"
107 shift; shift # remove zonename and zonepath from arguments array
109 unset inst_type
110 unset msg
111 unset silent_mode
112 unset verbose_mode
115 # It is worth noting here that we require the end user to pick one of
116 # -u (sys-unconfig) or -p (preserve config). This is because we can't
117 # really know in advance which option makes a better default. Forcing
118 # the user to pick one or the other means that they will consider their
119 # choice and hopefully not be surprised or disappointed with the result.
121 unset unconfig_zone
122 unset preserve_zone
124 while getopts "a:d:psuv" opt
126 case "$opt" in
128 if [[ -n "$inst_type" ]]; then
129 fatal "$both_kinds" "zoneadm install"
131 inst_type="archive"
132 install_media="$OPTARG"
135 if [[ -n "$inst_type" ]]; then
136 fatal "$both_kinds" "zoneadm install"
138 inst_type="directory"
139 install_media="$OPTARG"
141 p) preserve_zone="-p";;
142 s) silent_mode=1;;
143 u) unconfig_zone="-u";;
144 v) verbose_mode="-v";;
145 *) exit $ZONE_SUBPROC_USAGE;;
146 esac
147 done
148 shift OPTIND-1
150 # The install can't be both verbose AND silent...
151 [[ -n $silent_mode && -n $verbose_mode ]] && \
152 fatal "$f_incompat_options" "-s" "-v"
154 [[ -z $install_media ]] && fatal "$media_missing" "zoneadm install"
156 # The install can't both preserve and unconfigure
157 [[ -n $unconfig_zone && -n $preserve_zone ]] && \
158 fatal "$f_incompat_options" "-u" "-p"
160 # Must pick one or the other.
161 [[ -z $unconfig_zone && -z $preserve_zone ]] && fail_usage "$cfgchoice_missing"
163 LOGFILE=$(/usr/bin/mktemp -t -p /var/tmp $ZONENAME.install_log.XXXXXX)
164 [[ -z "$LOGFILE" ]] && fatal "$e_tmpfile"
165 exec 2>>"$LOGFILE"
166 log "$install_log" "$LOGFILE"
168 vlog "Starting pre-installation tasks."
171 # From here on out, an unspecified exit or interrupt should exit with
172 # ZONE_SUBPROC_NOTCOMPLETE, meaning a user will need to do an uninstall before
173 # attempting another install, as we've modified the directories we were going
174 # to install to in some way.
176 EXIT_CODE=$ZONE_SUBPROC_NOTCOMPLETE
178 # ZONEROOT was created by our caller (pkgcreatezone)
180 vlog "Installation started for zone \"$ZONENAME\""
181 install_image "$inst_type" "$install_media"
184 # Run p2v.
186 # Getting the output to the right places is a little tricky because what
187 # we want is for p2v to output in the same way the installer does: verbose
188 # messages to the log file always, and verbose messages printed to the
189 # user if the user passes -v. This rules out simple redirection. And
190 # we can't use tee or other tricks because they cause us to lose the
191 # return value from the p2v script due to the way shell pipelines work.
193 # The simplest way to do this seems to be to hand off the management of
194 # the log file to the p2v script. So we run p2v with -l to tell it where
195 # to find the log file and then reopen the log (O_APPEND) when p2v is done.
197 log "$p2ving"
198 vlog "running: p2v $verbose_mode $unconfig_zone $ZONENAME $ZONEPATH"
199 /usr/lib/brand/ipkg/p2v -l "$LOGFILE" $verbose_mode $unconfig_zone $ZONENAME \
200 $ZONEPATH
201 p2v_result=$?
202 exec 2>>$LOGFILE
204 if (( $p2v_result != 0 )); then
205 log "$p2v_fail"
206 log ""
207 log "$install_fail"
208 log "$install_log" "$LOGFILE"
209 exit $ZONE_SUBPROC_FATAL
211 vlog "$p2v_done"
213 zone_is_mounted=1
214 zoneadm -z $ZONENAME mount -f || fatal "$e_badmount"
216 safe_copy $LOGFILE $ZONEPATH/lu/a/var/log/$ZONENAME.install$$.log
218 zoneadm -z $ZONENAME unmount || fatal "$e_badunmount"
219 zone_is_mounted=0
221 trap - EXIT
222 rm -f $LOGFILE
224 mount_active_ds
226 log ""
227 log "$m_complete" ${SECONDS}
228 printf "$install_log\n" "$ZONEROOT/var/log/$ZONENAME.install$$.log"
230 exit $ZONE_SUBPROC_OK