6932374 onu should not leave temporary publishers in the new BE
authorJohn Levon <john.levon@sun.com>
Tue, 11 May 2010 15:16:46 -0700
changeset 12386 b989d9696c5b
parent 12385 61a45f43f68d
child 12387 e2a7d18f1d90
6932374 onu should not leave temporary publishers in the new BE 6933504 onu could skip some refresh operations 6936233 onu ignores additional arguments 6936310 extend onu to just bring up pkg.depotd's 6936773 onu.sh man page could use a real world example
usr/src/tools/scripts/onu.1
usr/src/tools/scripts/onu.sh
--- a/usr/src/tools/scripts/onu.1	Tue May 11 15:03:51 2010 -0400
+++ b/usr/src/tools/scripts/onu.1	Tue May 11 15:16:46 2010 -0700
@@ -17,17 +17,16 @@
 .\" "
 .\" " CDDL HEADER END
 .\" "
-.\" "Copyright 2010 Sun Microsystems, Inc.  All rights reserved."
-.\" "Use is subject to license terms."
+.\" "Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
 .\"
-.TH onu 1 "11 February 2010"
+.TH onu 1 "4th May 2010"
 .SH NAME
 .I onu
 \- Os/Net Update
 .SH SYNOPSIS
-\fBonu [-e <URI> [-E <publisher>]] [ -O ] [-s <beName>] -t <beName> [-u <URI> [-U <publisher>]] [-vZ]\fP
+\fBonu [opts] [-s <beName>] -t <beName>\fP
 .br
-\fBonu [-d <dir>] [ -O ] [-s <beName>] -t <beName> [-vZ]\fP
+\fBonu [opts] -r\fP
 .LP
 .SH DESCRIPTION
 .IX "OS-Net build tools" "onu" "" "\fBonu\fP"
@@ -39,21 +38,21 @@
 (OS/Net) consolidation of Solaris, using beadm(1M) to create a new Boot
 Environment (BE) and pkg(1) to update the image.
 .LP
-Former users of bfu should note the following ways in which onu behaves
-differently from bfu.  First, as noted above, onu creates a new BE, rather
-than updating an existing BE in-place.  Second, onu will not install packages
-that are older than what is already installed in the source BE.  Third,
-conflicts in system configuration files are automatically resolved according
-to the files' "preserve" attribute, as described in pkg(5).
+After updating an image, 
+.I onu
+can then be used to start repository depot servers, in preparation for
+using
+.I pkg
+to install additional packages and/or zones.
 .SH OPTIONS
 .LP
-The following options are supported:
+The following global options are supported:
 .TP 4
 .B \-d <dir>
 Specifies that <dir> contains repo.redist and repo.extra sub-directories;
 .I onu
 will stand up a depot for each and use them for the publisher and extra
-packaging repositories.  Note that -d overrides -u, -U, -e, and -E, as well
+packaging repositories.  Note that -d ignores -u, -U, -e, and -E, as well
 as the environment variables used by those options.
 .TP 4
 .B \-e <URI>
@@ -67,14 +66,6 @@
 .B \-O
 Open mode, where the extra repository will not be used.
 .TP 4
-.B \-s <beName>
-Specifies that <beName> should be used as the source Boot Environment to
-clone.  The default is the active BE.
-.TP 4
-.B \-t <beName>
-Specifies the target BE name.  Note that this argument is required; there
-is no default value.
-.TP 4
 .B \-u <URI>
 Specifies that <beName> should be used as the origin URI for the publisher
 packaging repository.  See \fBONURI\fP below for default values.
@@ -85,9 +76,28 @@
 .TP 4
 .B \-v
 Verbose mode.
+.LP
+The first form of onu creates a new BE and then updates it, and takes
+the following options:
+.TP 4
+.B \-s <beName>
+Specifies that <beName> should be used as the source Boot Environment to
+clone.  The default is the active BE.
+.TP 4
+.B \-t <beName>
+Specifies the target BE name.  This argument is required; there
+is no default value.
 .TP 4
 .B \-Z
 Do not update any installed zones.
+.LP
+The second form of onu takes the following option:
+.TP 4
+.B \-r
+In the current BE, create the repository depot servers and configure
+the requested publishers appropriately, without updating. After
+\fBonu\fP exits, one or two pkg.depotd servers will be left running,
+allowing \fBpkg\fP operations using the related publishers to succeed.
 .SH EXIT STATUS
 .LP
 The following exit values are returned:
@@ -103,6 +113,75 @@
 .TP 4
 .B 2
 One of the commands used by the script failed.
+.SH NOTES
+.LP
+Former users of bfu should note the following ways in which onu behaves
+differently from bfu.  First, as noted above, onu creates a new BE, rather
+than updating an existing BE in-place.  Second, onu will not install packages
+that are older than what is already installed in the source BE.  Third,
+conflicts in system configuration files are automatically resolved according
+to the files' "preserve" attribute, as described in pkg(5).
+.LP
+If the
+.B -d
+option is given to specify a repository directory, the new
+publishers will not be available in the new BE. This can prevent correct
+zone installs or cause issues with installing additional packages
+sourced from the ON repositories. In both cases, the \fB-r\fR option
+can be used in the new BE to re-enable the publishers. See
+\fBEXAMPLES\fR.
+.LP
+Use of
+.I onu
+will prevent use of zone attach for ipkg-brand zones in the new BE,
+since the
+.B entire
+incorporation is removed.
+.LP
+By default,
+.I onu
+will attempt to update any ipkg-brand installed zones on the system; the
+.B -Z
+option may be used to disable this behavior.
+.SH EXAMPLES
+.LP
+\fBExample 1\fR Installing latest ON nightly build
+.LP
+.SP
+.IN +2
+.NF
+# onu -t new-nightly-be
+.FI
+.IN -2
+.SP
+.LP
+\fBExample 2\fR Installing an ON build from a directory
+.LP
+.SP
+.IN +2
+.NF
+# onu -d /path/to/my/ws/packages/`uname -p`/nightly -t new-nightly-be
+.FI
+.IN -2
+.SP
+.LP
+\fBExample 3\fR Installing additional packages in the new BE
+.LP
+.SP
+.IN +2
+.NF
+# onu -d /path/to/my/ws/packages/`uname -p`/nightly -t new-nightly-be
+.br
+# reboot
+.br
+# onu -r -d /path/to/my/ws/packages/`uname -p`/nightly
+.br
+# pkg install netcat
+.br
+#
+.FI
+.IN -2
+.SP
 .SH ENVIRONMENT
 .LP
 ONURI
@@ -131,30 +210,9 @@
 used as the publisher name for the extra repository.  If -E is not
 provided and this variable is not set, on-extra will be used.
 .LP
-.SH NOTES
-.LP
-Use of
-.I onu
-will prevent use of zone attach for ipkg-brand zones in the new BE,
-since the
-.B entire
-incorporation is removed.
-.LP
-By default,
-.I onu
-will attempt to update any ipkg-brand installed zones on the system; the
-.B -Z
-option may be used to disable this behavior.
-.LP
-If the
-.B -d
-option is given to specify a repository directory, subsequent zone
-installs in the new BE will not work. In this case, a suitable
-repository matching the one used must be set up in the global zone
-before a zone install is attempted, otherwise the package contents of
-the zone may differ incompatibly from the global zone version.
 .SH SEE ALSO
 .BR beadm "(1M), "
 .BR bfu "(1), "
 .BR pkg "(1), "
+.BR pkg.depotd "(1M), "
 .BR pkg "(5) "
--- a/usr/src/tools/scripts/onu.sh	Tue May 11 15:03:51 2010 -0400
+++ b/usr/src/tools/scripts/onu.sh	Tue May 11 15:16:46 2010 -0700
@@ -21,8 +21,7 @@
 #
 
 #
-# Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
-# Use is subject to license terms.
+# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
 #
 
 PATH=/usr/bin:/usr/sbin
@@ -35,27 +34,30 @@
 
 usage()
 {
-	echo "usage: $0 [-e URI [-E pub]] [-O] [-s beName] -t beName [-u URI [-U pub]] [-vZ]"
-	echo "usage: $0 [ -d dir ][ -O ][ -s beName ] -t beName [-vZ]"
-	echo "Use -s to specify the source BE to clone (default is the active BE)."
-	echo "Use -t to specify the target BE name."
-	echo "Use -u to specify the origin URI for the publisher packaging repository"
-	echo "\t(default is \$ONURI if set in the environment, otherwise"
-	echo "\t$DEFAULTONURI )."
-	echo "Use -U to specify the publisher prefix for the packaging repository"
-	echo "\t(default is \$ONPUB if set in the environment, otherwise"
-	echo "\t$DEFAULTONPUB )."
-	echo "Use -e to specify the origin URI for the extra repository (default is"
-	echo "\t\$ONEXTRAURI if set in the environment, otherwise"
-	echo "\t$DEFAULTONEXTRAURI )."
-	echo "Use -E to specify the publisher prefix for the extra repository (default"
-	echo "\tis \$ONEXTRAPUB if set in the environment, otherwise"
-	echo "\t$DEFAULTONEXTRAPUB )."
-	echo "Use -d to specify a directory containing redist and extra directories."
-	echo "\tNote that -d overrides -u, -U, -e and -E."
-	echo "Use -O for open mode, meaning that no extra repository will be used."
-	echo "Use -v for verbose mode."
-	echo "Use -Z to skip updating zones."
+	echo "usage: $0 [opts] [-s beName] -t beName"
+	echo "usage: $0 [opts] -r"
+	echo
+	echo "\t-d repodir : directory for repositories"
+	echo "\t-e uri : origin URI for extra repository"
+	echo "\t-E prefix : prefix for extra repository"
+	echo "\t-O : open mode, no extra repository will be used"
+	echo "\t-r : start repository servers only"
+	echo "\t-s : source BE to clone"
+	echo "\t-t : new BE name"
+	echo "\t-u uri : origin URI for redist repository"
+	echo "\t-U prefix:  prefix for redist repository"
+	echo "\t-v : verbose"
+	echo "\t-Z : skip updating zones"
+	echo
+	echo "Update to an ON build:"
+	echo "\tonu -t newbe -d /path/to/my/ws/packages/\`uname -p\`/nightly"
+	echo
+	echo "Update to the nightly build:"
+	echo "\tonu -t newbe"
+	echo
+	echo "Re-enable the publishers, and start any pkg.depotd servers"
+	echo "necessary in the current BE:"
+	echo "\tonu -r -d /path/to/my/ws/packages/\`uname -p\`/nightly"
 	exit 1
 }
 
@@ -85,17 +87,49 @@
 	exit_error "$*" failed: exit code $exit_code
 }
 
+configure_publishers()
+{
+	root=$1
+
+	do_cmd pkg -R $root set-publisher --no-refresh --non-sticky opensolaris.org
+	do_cmd pkg -R $root set-publisher -e --no-refresh -P -O $uri $redistpub
+	[ $open -eq 0 ] && {
+		do_cmd pkg -R $root set-publisher -e \
+		    --no-refresh -O $extrauri $extrapub
+	}
+	do_cmd pkg -R $root refresh --full
+}
+
+#
+# If we're working from a repodir, disable the new publishers in the new
+# BE; they won't work without further configuration, in which case the
+# -r option should be used.
+#
+unconfigure_publishers()
+{
+	root=$1
+
+	if [ -n "$repodir" ]; then
+		do_cmd pkg -R $root set-publisher -P opensolaris.org
+		do_cmd pkg -R $root set-publisher -d $redistpub
+		[ $open -eq 0 ] && {
+			do_cmd pkg -R $root set-publisher -d $extrapub
+		}
+	fi
+}
+
 update()
 {
-	tmpdir=$1
+	root=$1
+
+	pkg -R $root list entire > /dev/null 2>&1
+	[ $? -eq 0 ] && do_cmd pkg -R $root uninstall entire
 
-	do_cmd pkg -R $tmpdir set-publisher --non-sticky opensolaris.org
-	pkg -R $tmpdir list entire > /dev/null 2>&1
-	[ $? -eq 0 ] && do_cmd pkg -R $tmpdir uninstall entire
-	do_cmd pkg -R $tmpdir set-publisher -P -O $uri $redistpub
-	[ $open -eq 0 ] && do_cmd pkg -R $tmpdir set-publisher -O $extrauri $extrapub
-	do_cmd pkg -R $tmpdir refresh --full
-	do_cmd pkg -R $tmpdir image-update
+	configure_publishers $root
+
+	do_cmd pkg -R $root image-update
+
+	unconfigure_publishers $root
 }
 
 update_zone()
@@ -114,10 +148,6 @@
 
 	if [ "$zone_warned" = 0 ]; then
 		echo "WARNING: Use of onu(1) will prevent use of zone attach in the new BE" >&2
-		if [ -n "$repodir" ]; then
-			echo "WARNING: use of -d option will prevent new zone installs in the new BE" >&2
-		fi
-
 		echo "See onu(1)" >&2
 		zone_warned=1
 	fi
@@ -149,10 +179,11 @@
 extraport=13001
 no_zones=0
 zone_warned=0
+reposonly=0
 
 trap cleanup 1 2 3 15
 
-while getopts :d:E:e:Os:t:U:u:vZ i ; do
+while getopts :d:E:e:Ors:t:U:u:vZ i ; do
 	case $i in
 	d)
 		repodir=$OPTARG
@@ -166,6 +197,9 @@
 	O)
 		open=1
 		;;
+	r)
+		reposonly=1
+		;;
 	s)
 		sourcebe=$OPTARG
 		;;
@@ -190,7 +224,15 @@
 done
 shift `expr $OPTIND - 1`
 
-[ -z "$targetbe" ] && usage
+[ -n "$1" ] && usage
+
+if [ "$reposonly" -eq 1 ]; then
+	[ -n "$sourcebe" ] && usage
+	[ -n "$targetbe" ] && usage
+	[ "$no_zones" -eq 1 ] && usage
+else
+	[ -z "$targetbe" ] && usage
+fi
 [ -z "$uri" ] && uri=$ONURI
 [ -z "$uri" ] && uri=$DEFAULTONURI
 [ -z "$redistpub" ] && redistpub=$ONPUB
@@ -234,6 +276,17 @@
 	fi
 fi
 
+if [ "$reposonly" -eq 1 ]; then
+	configure_publishers /
+	if [ "$redistpid" -ne 0 ]; then
+		echo "$redistpub pkg.depotd running with pid $redistpid"
+	fi
+	if [ "$extrapid" -ne 0 ]; then
+		echo "$extrapub pkg.depotd running with pid $extrapid"
+	fi
+	exit 0
+fi
+
 createargs=""
 [ -n "$sourcebe" ] && createargs="-e $sourcebe"