8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / tools / scripts / onu.sh.in
blob9a4e81e7a24e089f31cf832e843906b8e1f505d6
1 #!/bin/ksh93 -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
24 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
25 # Copyright 2010, Richard Lowe
28 PATH=/usr/bin:/usr/sbin
29 export PATH
31 DEFAULTONURI="http://ipkg.sfbay/on-nightly"
32 DEFAULTONPUB="on-nightly"
34 usage()
36 echo "usage: $0 [opts] [-s beName] -t beName"
37 echo "usage: $0 [opts] -r"
38 echo
39 echo "\t-c consolidation : consolidation being upgraded"
40 echo "\t-d repodir : directory for repositories"
41 echo "\t-r : configure publisher only"
42 echo "\t-s : source BE to clone"
43 echo "\t-t : new BE name"
44 echo "\t-u uri : origin URI for redist repository"
45 echo "\t-U prefix: prefix for redist repository"
46 echo "\t-v : verbose"
47 echo "\t-Z : skip updating zones"
48 echo
49 echo "Update to an ON build:"
50 echo "\tonu -t newbe -d /path/to/my/ws/packages/\`uname -p\`/nightly"
51 echo
52 echo "Update to the nightly build:"
53 echo "\tonu -t newbe"
54 echo
55 echo "Re-enable the publishers in the current BE:"
56 echo "\tonu -r -d /path/to/my/ws/packages/\`uname -p\`/nightly"
57 exit 1
60 exit_error()
62 echo $*
63 exit 2
66 do_cmd()
68 [ $verbose -gt 0 ] && echo $*
70 exit_code=$?
71 [ $exit_code -eq 0 ] && return
72 # pkg(1) returns 4 if "nothing to do", which is safe to ignore
73 [ $1 = "pkg" -a $exit_code -eq 4 ] && return
74 exit_error "$*" failed: exit code $exit_code
77 configure_publishers()
79 root=$1
82 # Get the publisher name from the 'list -v' output. It may seem we
83 # could do this more tidily using 'info', but that is
84 # internationalized.
86 typeset on_publisher=$(pkg -R $root list -Hv \
87 "${consolidation}-incorporation" | cut -d/ -f3)
89 if [[ "$on_publisher" != "$redistpub" ]]; then
90 do_cmd pkg -R $root set-publisher --no-refresh \
91 --non-sticky $on_publisher
93 do_cmd pkg -R $root set-publisher -e --no-refresh -P -O $uri $redistpub
94 do_cmd pkg -R $root refresh --full
97 update()
99 root=$1
101 pkg -R $root list entire > /dev/null 2>&1
102 [ $? -eq 0 ] && do_cmd pkg -R $root uninstall entire
104 configure_publishers $root
106 do_cmd pkg -R $root image-update
109 update_zone()
111 zone=$1
113 name=`echo $zone | cut -d: -f 2`
114 if [ $name = "global" ]; then
115 return
118 brand=`echo $zone | cut -d: -f 6`
119 if [ $brand != "ipkg" ]; then
120 return
123 if [ "$zone_warned" = 0 ]; then
124 echo "WARNING: Use of onu(1) will prevent use of zone attach in the new BE" >&2
125 echo "See onu(1)" >&2
126 zone_warned=1
129 state=`echo $zone | cut -d: -f 3`
131 case "$state" in
132 configured|incomplete)
133 return
135 esac
137 zoneroot=`echo $zone | cut -d: -f 4`
139 echo "Updating zone $name"
140 update $zoneroot/root
143 sourcebe=""
144 targetbe=""
145 uri=""
146 repodir=""
147 consolidation="osnet"
148 verbose=0
149 no_zones=0
150 zone_warned=0
151 reposonly=0
153 while getopts :c:d:Ors:t:U:u:vZ i ; do
154 case $i in
156 consolidation=$OPTARG
159 repodir=$OPTARG
161 O) # no-op, compatibility with recommended use
164 reposonly=1
167 sourcebe=$OPTARG
170 targetbe=$OPTARG
173 redistpub=$OPTARG
176 uri=$OPTARG
179 verbose=1
182 no_zones=1
185 usage
186 esac
187 done
188 shift `expr $OPTIND - 1`
190 [ -n "$1" ] && usage
192 if [ "$reposonly" -eq 1 ]; then
193 [ -n "$sourcebe" ] && usage
194 [ -n "$targetbe" ] && usage
195 [ "$no_zones" -eq 1 ] && usage
196 else
197 [ -z "$targetbe" ] && usage
199 [ -z "$uri" ] && uri=$ONURI
200 [ -z "$uri" ] && uri=$DEFAULTONURI
201 [ -z "$redistpub" ] && redistpub=$ONPUB
202 [ -z "$redistpub" ] && redistpub=$DEFAULTONPUB
204 if [ -n "$repodir" ]; then
205 redistdir=$repodir/repo.redist
206 [ -d $redistdir ] || exit_error "$redistdir not found"
207 typeset cfgfile=$redistdir/cfg_cache
208 [[ ! -e $cfgfile ]] && cfgfile=$redistdir/pkg5.repository
209 # need an absolute path
210 [[ $redistdir == /* ]] || redistdir=$PWD/$redistdir
211 redistpub=$(python@PYTHON_VERSION@ <<# EOF
212 import ConfigParser
213 p = ConfigParser.SafeConfigParser()
214 p.read("$cfgfile")
215 pp = p.get("publisher", "prefix")
216 print "%s" % pp
217 EOF) || exit_error "Cannot determine publisher prefix"
218 [[ -n "$redistpub" ]] || exit_error "Repository has no publisher prefix"
219 uri="file://$redistdir"
222 if [ "$reposonly" -eq 1 ]; then
223 configure_publishers /
224 exit 0
227 createargs=""
228 [ -n "$sourcebe" ] && createargs="-e $sourcebe"
230 # ksh seems to have its own mktemp with slightly different semantics
231 tmpdir=`/usr/bin/mktemp -d /tmp/onu.XXXXXX`
232 [ -z "$tmpdir" ] && exit_error "mktemp failed"
234 do_cmd beadm create $createargs $targetbe
235 do_cmd beadm mount $targetbe $tmpdir
236 update $tmpdir
237 do_cmd beadm activate $targetbe
239 if [ "$no_zones" != 1 ]; then
240 for zone in `do_cmd zoneadm -R $tmpdir list -cip`; do
241 update_zone $zone
242 done
245 exit 0