Commits

Henk Langeveld committed 335167d

refactored the experimental repo setup

All action inside functions. Tested some of them separately.

  • Participants
  • Parent commits 2542e1b

Comments (0)

Files changed (1)

File setup-pkg-experimental

 # Setting up your build environment
 
-[[ $(zonename) == global ]] && { cat <<EOM
+function die { print -u2 "$*"; exit 1; }
 
-# 	/experimental
-# Note that the /experimental repo is under continuous development and may contain breakage. Thus we (as mentioned) strongly recommend building inside a dedicated development zone, rather than updating your main system.
-# We strongly recommend building packages inside a fresh local zone set
-# up exclusively for building. A good example howto on creating a
-# build-zone can be found in the CrossBow instructions, see Building in
-# zones.
-
-EOM
-exit 1
+function assert_valid_targetzone { typeset targetzone=${1:?targetzone}
+	case ${targetzone} in
+	(global)	print -u2 WARNING: building in the global zone carries risk.
+	esac
+	[[ $(zonename) == *(${targetzone}|global) ]] && return
+	zoneadm -z $targetzone list | read && return
+	print -u2 targetzone should match current zone name, or a zone within the current global
+	exit 1
 }
 
-# Some suggestions about build environment (dataset layouts, etc.) can
-# also be found in the illumos wiki: How to build illumos (note however
-# that compilers required for the core OS may be different than those
-# acceptable for userland software).
-# Ensuring your system is up to date
-# 
-# illumos-userland requires that your system be updated with the latest software from the pkg.openindiana.org/experimental repository.
+function install_from_experimental {
+	typeset targetzone=${1:?zonename required} 
+	typeset PATH=/usr/bin:/usr/sbin
+	typeset current_zone=$(zonename)
+	typeset root_prefix=
+	typeset PKG_CMD=pkg
+
+assert_valid_targetzone $targetzone
+
+if [[ $targetzone != $current_zone ]] ; then
+	# prepare pkg commands for execution from global
+
+	typeset root_prefix=$(zonepath $targetzone)
+	typeset ZONEROOT=$root_prefix/$targetzone/root
+	typeset PYTHONPATH
+
+	PKG_CMD="${ZONEROOT}/usr/bin/pkg -R ${ZONEROOT}"
+	zoneadm -z $targetzone halt
+	zoneadm -z $targetzone ready
+	export PYTHONPATH=${ZONEROOT}/usr/lib/python2.6/vendor-packages
+fi
+
+# illumos-userland requires that your system be updated with the latest
+# software from the pkg.openindiana.org/experimental repository.
 # 
 # The procedure to do this is as follows:
-/usr/bin/pkg set-publisher -p http://pkg.openindiana.org/experimental/
-/usr/bin/pkg set-publisher -P oi-experimental
-/usr/bin/pkg set-publisher --non-sticky openindiana.org
-/usr/bin/pkg install -v package/pkg
-/usr/bin/pkg update -v
 
-# The first line adds the experimental repo to your package publisher
-# list, the second line sets it as the primary publisher, and the third
-# line allows packages from the experimental repo to replace those
-# installed from the openindiana.org repo. The last line updates your
-# system with the newer packages.
+$PKG_CMD set-publisher -p http://pkg.openindiana.org/experimental/
+$PKG_CMD set-publisher -P oi-experimental
+$PKG_CMD set-publisher --non-sticky openindiana.org
+$PKG_CMD install -v package/pkg
+$PKG_CMD update -v
 
-# Note: If you are doing this in a zone and encounter an error from pkg about being unable to clone the current boot environment, you will need to update the zone from the global zone by doing:
+}
 
-if [[ $(zonename) == global ]] ; then
-: ${ZONE:?zonename required}
-ZONEROOT=`zonecfg -z $ZONE info zonepath | awk '{print $NF}'`
-zoneadm -z $ZONE halt
-zoneadm -z $ZONE ready
-export PYTHONPATH=${ZONEROOT}/root/usr/lib/python2.6/vendor-packages
-${ZONEROOT}/root/usr/bin/pkg -R ${ZONEROOT}/root set-publisher -p http://pkg.openindiana.org/experimental/
-${ZONEROOT}/root/usr/bin/pkg -R ${ZONEROOT}/root set-publisher -P oi-experimental
-${ZONEROOT}/root/usr/bin/pkg -R ${ZONEROOT}/root set-publisher --non-sticky openindiana.org
-${ZONEROOT}/root/usr/bin/pkg -R ${ZONEROOT}/root install -v package/pkg
-${ZONEROOT}/root/usr/bin/pkg -R ${ZONEROOT}/root update -v
-unset PYTHONPATH ZONE ZONEROOT
-fi
+function zonepath { typeset ZONE=${1:?}
+	zonecfg -z $ZONE info zonepath | nawk '{print $NF}'
+}
 
+return 0