1#!/bin/ksh93 -p 2# 3# CDDL HEADER START 4# 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. 8# 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. 13# 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] 19# 20# CDDL HEADER END 21# 22 23# 24# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 25# Copyright 2010, Richard Lowe 26# 27 28PATH=/usr/bin:/usr/sbin 29export PATH 30 31DEFAULTONURI="http://ipkg.sfbay/on-nightly" 32DEFAULTONPUB="on-nightly" 33 34usage() 35{ 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 58} 59 60exit_error() 61{ 62 echo $* 63 exit 2 64} 65 66do_cmd() 67{ 68 [ $verbose -gt 0 ] && echo $* 69 $* 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 75} 76 77configure_publishers() 78{ 79 root=$1 80 81 # 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. 85 # 86 typeset on_publisher=$(pkg -R $root list -Hv \ 87 "${consolidation}-incorporation" | cut -d/ -f3) 88 89 if [[ "$on_publisher" != "$redistpub" ]]; then 90 do_cmd pkg -R $root set-publisher --no-refresh \ 91 --non-sticky $on_publisher 92 fi 93 do_cmd pkg -R $root set-publisher -e --no-refresh -P -O $uri $redistpub 94 do_cmd pkg -R $root refresh --full 95} 96 97update() 98{ 99 root=$1 100 101 pkg -R $root list entire > /dev/null 2>&1 102 [ $? -eq 0 ] && do_cmd pkg -R $root uninstall entire 103 104 configure_publishers $root 105 106 do_cmd pkg -R $root image-update 107} 108 109update_zone() 110{ 111 zone=$1 112 113 name=`echo $zone | cut -d: -f 2` 114 if [ $name = "global" ]; then 115 return 116 fi 117 118 brand=`echo $zone | cut -d: -f 6` 119 if [ $brand != "ipkg" ]; then 120 return 121 fi 122 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 127 fi 128 129 state=`echo $zone | cut -d: -f 3` 130 131 case "$state" in 132 configured|incomplete) 133 return 134 ;; 135 esac 136 137 zoneroot=`echo $zone | cut -d: -f 4` 138 139 echo "Updating zone $name" 140 update $zoneroot/root 141} 142 143sourcebe="" 144targetbe="" 145uri="" 146repodir="" 147consolidation="osnet" 148verbose=0 149no_zones=0 150zone_warned=0 151reposonly=0 152 153while getopts :c:d:Ors:t:U:u:vZ i ; do 154 case $i in 155 c) 156 consolidation=$OPTARG 157 ;; 158 d) 159 repodir=$OPTARG 160 ;; 161 O) # no-op, compatibility with recommended use 162 ;; 163 r) 164 reposonly=1 165 ;; 166 s) 167 sourcebe=$OPTARG 168 ;; 169 t) 170 targetbe=$OPTARG 171 ;; 172 U) 173 redistpub=$OPTARG 174 ;; 175 u) 176 uri=$OPTARG 177 ;; 178 v) 179 verbose=1 180 ;; 181 Z) 182 no_zones=1 183 ;; 184 *) 185 usage 186 esac 187done 188shift `expr $OPTIND - 1` 189 190[ -n "$1" ] && usage 191 192if [ "$reposonly" -eq 1 ]; then 193 [ -n "$sourcebe" ] && usage 194 [ -n "$targetbe" ] && usage 195 [ "$no_zones" -eq 1 ] && usage 196else 197 [ -z "$targetbe" ] && usage 198fi 199[ -z "$uri" ] && uri=$ONURI 200[ -z "$uri" ] && uri=$DEFAULTONURI 201[ -z "$redistpub" ] && redistpub=$ONPUB 202[ -z "$redistpub" ] && redistpub=$DEFAULTONPUB 203 204if [ -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" 220fi 221 222if [ "$reposonly" -eq 1 ]; then 223 configure_publishers / 224 exit 0 225fi 226 227createargs="" 228[ -n "$sourcebe" ] && createargs="-e $sourcebe" 229 230# ksh seems to have its own mktemp with slightly different semantics 231tmpdir=`/usr/bin/mktemp -d /tmp/onu.XXXXXX` 232[ -z "$tmpdir" ] && exit_error "mktemp failed" 233 234do_cmd beadm create $createargs $targetbe 235do_cmd beadm mount $targetbe $tmpdir 236update $tmpdir 237do_cmd beadm activate $targetbe 238 239if [ "$no_zones" != 1 ]; then 240 for zone in `do_cmd zoneadm -R $tmpdir list -cip`; do 241 update_zone $zone 242 done 243fi 244 245exit 0 246