Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 342 lines (319 sloc) 9.79 KB
#!/bin/ksh
#
# upgrade to a new version of Tribblix
#
# the current upgrade is from m18 (or earlier) to m19
# which crosses the loader boundary - grub is kept by default,
# but m20 will be new-loader only
#
ZAPLIBDIR="/usr/lib/zap"
CFGDIR="/etc/zap"
BEADM="/sbin/beadm"
ZFSCMD="/usr/sbin/zfs"
DOIT=""
ACTIVATE="false"
#
# The general strategy here is:
# beadm create newver
# beadm mount newver /a
# update zap on the new be
# (in the new context) zap update-overlay -a
# beadm activate newver
# init 6
#
#
# The package TRIBzap-upgrade supplies the files
# /etc/zap/version.list
# /etc/zap/version.current
#
VLISTFILE="${CFGDIR}/version.list"
VINSTFILE="${CFGDIR}/version.current"
if [ ! -f "${VLISTFILE}" ]; then
echo "ERROR: upgrade capability not present"
exit 1
fi
if [ ! -f "${VINSTFILE}" ]; then
echo "ERROR: upgrade capability not present"
exit 1
fi
if [ ! -f "${BEADM}" ]; then
echo "ERROR: upgrade capability not present, beadm missing"
exit 1
fi
show_available() {
INSTVER=`cat $VINSTFILE`
/usr/bin/awk -F'|' '{print $1,$2,$3}' $VLISTFILE | while read nver nurl ntext
do
if [ "X$nver" = "X$INSTVER" ]; then
echo "${nver}: (current)"
else
echo "${nver}: $ntext"
fi
done
}
validate() {
INSTVER=`cat $VINSTFILE`
/usr/bin/awk -F'|' '{print $1,$2}' $VLISTFILE | while read nver nurl
do
if [ "X$1" = "X$INSTVER" ]; then
echo "ERROR: $1 is the current version"
exit 1
elif [ "X$nver" = "X$1" ]; then
echo "$nurl"
return
fi
done
echo "ERROR: unrecognized version $1"
exit 1
}
bail() {
echo $1
exit 1
}
case $# in
0)
echo "Usage: zap upgrade [-n] [-B] new_version | list | current"
exit 1
;;
esac
case $1 in
'list')
show_available
exit 0
;;
'current')
cat $VINSTFILE
exit 0
;;
esac
while getopts "nB" opt; do
case $opt in
n)
DOIT="echo"
;;
B)
ACTIVATE="true"
;;
esac
done
shift $((OPTIND - 1))
#
# Beyond here is an upgrade, either real or dry-run
#
echo $*
NEWVER="$1"
#
# validate the requested version, and get the corresponding URL
#
NEWURL=$(validate $NEWVER) || bail "$NEWURL"
#
# find the current BE and matching FS dataset
#
OLDBE=`$BEADM list -H | awk -F\; '{if ($3=="NR") print $1}'`
OLDDS=`$BEADM list -Ha | awk -F\; '{if ($3=="NR") print $2}'`
if [ -z "$OLDBE" ]; then
echo "ERROR: Unable to find current BE name"
exit 1
fi
#
# find a BE name that is unused
#
BENAME="$NEWVER"
$BEADM list $BENAME > /dev/null 2>&1
BESTATUS=$?
BENUM=0
while [ $BESTATUS -eq 0 ]
do
BENUM=$(($BENUM+1))
BENAME="${NEWVER}-${BENUM}"
$BEADM list $BENAME > /dev/null 2>&1
BESTATUS=$?
done
WCLIENT=/usr/bin/curl
WARGS="-f -s -o"
if [ ! -x $WCLIENT ]; then
WCLIENT=/usr/bin/wget
WARGS="-q -O"
fi
NPKG=${NEWURL##*/}
CACHE_DIR=`${ZAPLIBDIR}/zap-cfg cache-dir`
$DOIT ${WCLIENT} ${WARGS} ${CACHE_DIR}/${NPKG} $NEWURL
$DOIT $BEADM create $BENAME
ALTROOT="/a"
BENUM=0
while [ -d $ALTROOT ]
do
BENUM=$(($BENUM+1))
ALTROOT="/a.${BENUM}"
done
#
# and the ZFS dataset it corresponds to
# -a could return multiple lines, one with a dataset and possibly
# multiple snapshots; match the dataset by looking for a /
#
NEWDS=`$BEADM list -Ha $BENAME | awk -F\; '{if ($2~/\//) print $2}'`
echo New BE will be called $BENAME
echo Backed by dataset $NEWDS
echo And will be driven from $NEWURL
#
# update zap in the new BE
#
$DOIT mkdir $ALTROOT
$DOIT $BEADM mount $BENAME $ALTROOT
$DOIT zap uninstall -R $ALTROOT TRIBzap
$DOIT ${ZAPLIBDIR}/instzap -R $ALTROOT ${CACHE_DIR}/${NPKG} TRIBzap
#
# must refresh the overlays and catalog, as contents and dependencies
# may have changed
#
$DOIT /usr/bin/zap -C ${ALTROOT} refresh-overlays
#
# first we must update SUNWcsd
#
$DOIT /usr/bin/zap -C ${ALTROOT} update SUNWcsd
#
# replace the critical state files from the running system
# the assumption here is that SUNWcsd installs blank files
#
$DOIT /usr/bin/cp -p /etc/devlink.tab ${ALTROOT}/etc/devlink.tab
$DOIT /usr/bin/cp -p /etc/driver_classes ${ALTROOT}/etc/driver_classes
$DOIT /usr/bin/cp -p /etc/driver_aliases ${ALTROOT}/etc/driver_aliases
$DOIT /usr/bin/cp -p /etc/iu.ap ${ALTROOT}/etc/iu.ap
$DOIT /usr/bin/cp -p /etc/minor_perm ${ALTROOT}/etc/minor_perm
$DOIT /usr/bin/cp -p /etc/name_to_major ${ALTROOT}/etc/name_to_major
$DOIT /usr/bin/cp -p /etc/path_to_inst ${ALTROOT}/etc/path_to_inst
$DOIT /usr/bin/cp -p /etc/security/device_policy ${ALTROOT}/etc/security/device_policy
$DOIT /usr/bin/cp -p /etc/security/extra_privs ${ALTROOT}/etc/security/extra_privs
#
# remove any obsoleted packages
#
if [ -f ${ALTROOT}/usr/share/zap/deprecated.pkgs ]; then
echo "Removing obsoleted packages"
for oldpkg in `cat ${ALTROOT}/usr/share/zap/deprecated.pkgs`
do
$DOIT /usr/bin/zap uninstall -R ${ALTROOT} ${oldpkg}
done
fi
#
# remove any obsoleted overlays
# note this just removes any metadata, any constituent packages
# needing removal must be listed in deprecated.pkgs
#
if [ -f ${ALTROOT}/usr/share/zap/deprecated.ovl ]; then
echo "Removing obsoleted overlays"
for oldovl in `cat ${ALTROOT}/usr/share/zap/deprecated.ovl`
do
$DOIT /usr/bin/rm -f ${ALTROOT}/var/sadm/overlays/${oldovl}.pkgs
$DOIT /usr/bin/rm -f ${ALTROOT}/var/sadm/overlays/${oldovl}.ovl
$DOIT /usr/bin/rm -f ${ALTROOT}/var/sadm/overlays/${oldovl}.pkgs.bak
$DOIT /usr/bin/rm -f ${ALTROOT}/var/sadm/overlays/${oldovl}.ovl.bak
$DOIT /usr/bin/rm -f ${ALTROOT}/var/sadm/overlays/installed/${oldovl}
done
fi
#
# now update the remaining overlays
#
$DOIT /usr/bin/zap -C ${ALTROOT} update-overlay -a
#
# do it again, because the overlay structure might have changed and
# we need to be sure that any newly added overlays get updated too
#
$DOIT /usr/bin/zap -C ${ALTROOT} update-overlay -a
#
# this is a manual hack for m19 and the new loader
# we need to be absolutely sure that the loader and
# agpgart packages get installed
#
$DOIT /usr/bin/zap -C ${ALTROOT} install TRIBsys-boot-loader
$DOIT /usr/bin/zap -C ${ALTROOT} install TRIBdrv-graphics-agpgart
#
# FIXME and any isolated packages?
#
# shut down pkgserv otherwise the BE cannot be unmounted
#
$DOIT /usr/bin/pkgadm sync -R ${ALTROOT} -q
#
# refresh common administratively modified files
#
$DOIT /usr/bin/cp -p /etc/passwd ${ALTROOT}/etc/passwd
$DOIT /usr/bin/cp -p /etc/shadow ${ALTROOT}/etc/shadow
$DOIT /usr/bin/cp -p /etc/group ${ALTROOT}/etc/group
$DOIT /usr/bin/cp -p /etc/logadm.conf ${ALTROOT}/etc/logadm.conf
$DOIT /usr/bin/cp -p /etc/dumpadm.conf ${ALTROOT}/etc/dumpadm.conf
$DOIT /usr/bin/cp -p /etc/coreadm.conf ${ALTROOT}/etc/coreadm.conf
$DOIT /usr/bin/cp -p /etc/syslog.conf ${ALTROOT}/etc/syslog.conf
$DOIT /usr/bin/cp -p /etc/nsswitch.conf ${ALTROOT}/etc/nsswitch.conf
$DOIT /usr/bin/cp -p /etc/user_attr ${ALTROOT}/etc/user_attr
$DOIT /usr/bin/cp -p /etc/resolv.conf ${ALTROOT}/etc/resolv.conf
$DOIT /usr/bin/cp -p /etc/inet/hosts ${ALTROOT}/etc/inet/hosts
$DOIT /usr/bin/cp -p /etc/inet/netmasks ${ALTROOT}/etc/inet/netmasks
$DOIT /usr/bin/cp -p /etc/inet/networks ${ALTROOT}/etc/inet/networks
$DOIT /usr/bin/cp -p /etc/inet/protocols ${ALTROOT}/etc/inet/protocols
$DOIT /usr/bin/cp -p /etc/inet/services ${ALTROOT}/etc/inet/services
$DOIT /usr/bin/cp -p /etc/inet/inetd.conf ${ALTROOT}/etc/inet/inetd.conf
$DOIT /usr/bin/cp -p /etc/inet/ipsecalgs ${ALTROOT}/etc/inet/ipsecalgs
$DOIT /usr/bin/cp -p /etc/inet/ipaddrsel.conf ${ALTROOT}/etc/inet/ipaddrsel.conf
$DOIT /usr/bin/cp -p /etc/inet/secret/ike.preshared ${ALTROOT}/etc/inet/secret/ike.preshared
$DOIT /usr/bin/cp -p /etc/zones/index ${ALTROOT}/etc/zones/index.pre-upgrade
$DOIT /usr/bin/cp -p /etc/default/init ${ALTROOT}/etc/default/init
$DOIT /usr/bin/cp -p /etc/ipadm/ipadm.conf ${ALTROOT}/etc/ipadm/ipadm.conf
$DOIT /usr/bin/cp -p /etc/dladm/* ${ALTROOT}/etc/dladm
grep /swap /etc/vfstab >> ${ALTROOT}/etc/vfstab
#
# FIXME: these 2 often get mangled, need fixing properly
#
$DOIT /usr/bin/cp -p /etc/minor_perm ${ALTROOT}/etc/minor_perm
$DOIT /usr/bin/cp -p /etc/name_to_major ${ALTROOT}/etc/name_to_major
#
# if there is a zonelib hierarchy for sparse root zones, it needs
# to be cleaned out (at this point zones aren't supported but at
# least cleaning out zonelib will ensure that any newly created
# zones will work)
#
if [ -d ${ALTROOT}/zonelib/lib/svc ]; then
$DOIT /usr/bin/rm -fr ${ALTROOT}/zonelib/lib
$DOIT /usr/bin/mkdir -p ${ALTROOT}/zonelib/lib
fi
#
# FIXME - bootloader switch
#
# Originally, the upgrade script forced grub as the bootloader on
# upgrade. This is clearly wrong now that new installs start with the
# new loader, as we would then force a switch to the old grub.
# Therefore, we no longer force anything. However, that still leaves
# systems that were installed with loader but then had grub forced
# on upgrade, which will then be switched at the *next* upgrade.
# We need to check for that and undo the grub selection in that case.
#
#
# need to update the boot archive
#
$DOIT /usr/sbin/bootadm update-archive -R $ALTROOT
$DOIT $BEADM unmount $BENAME
$DOIT rmdir $ALTROOT
#
# activation is optional
# observation indicates that beadm might leave the old dataset mountable
# on /, which the system tries to do at boot, which fails then causing the
# whole boot to fail, so override that just in case it's wrong. The correct
# setting for canmount is 'noauto' but some older Tribblix installs didn't
# set it that way
#
echo "Upgrade complete"
$DOIT $ZFSCMD set canmount=noauto $OLDDS
$DOIT $ZFSCMD set canmount=noauto $NEWDS
$DOIT $ZFSCMD set mountpoint=/ $OLDDS
$DOIT $ZFSCMD set mountpoint=/ $NEWDS
if [ "X${ACTIVATE}" = "Xtrue" ]; then
echo "Activating new BE"
$DOIT $BEADM activate $BENAME
$DOIT init 6
else
echo ""
echo "====================================================="
echo "|| To switch to the newly upgraded version, issue ||"
echo "|| the following commands: ||"
printf "|| beadm activate %-31s||\n" $BENAME
echo "|| init 6 ||"
echo "====================================================="
fi