packages/upgrade-X
author Alan Coopersmith <Alan.Coopersmith@Sun.COM>
Wed, 27 Aug 2008 15:52:08 -0700
changeset 512 dca0b5524781
parent 478 5a5ab6772794
child 513 9c7b32aa7a41
permissions -rw-r--r--
6741768 upgrade-X script improvements

#!/bin/ksh93

###
#
# @(#)upgrade-X	1.40 08/08/27
#
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, and/or sell copies of the Software, and to permit persons
# to whom the Software is furnished to do so, provided that the above
# copyright notice(s) and this permission notice appear in all copies of
# the Software and that both the above copyright notice(s) and this
# permission notice appear in supporting documentation.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
# OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
# INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Except as contained in this notice, the name of a copyright holder
# shall not be used in advertising or otherwise to promote the sale, use
# or other dealings in this Software without prior written authorization
# of the copyright holder.
#
###########################################################################
#
# Description: This script upgrades X software on a Solaris Nevada
#	       system. It should be run as root from a X package area.
#
# Arguments:	-a 	Ignored (was: install ALL packages, which is now the
#			default behaviour.)
#		-q	Be quiet and don't report packages that aren't 
#			installed.
#
###

# Update this when X package version number changes
XVERS="6.9.0.5.11"

# Set up error reporting function
progname="$0"

function fatal_error
{
    print -u2 "${progname}: ERROR: $*"
    exit 1
}

###
#  
#   First check for a correct upgrade environment. 
#
###

MACH="$(uname -p)"

DATE="$(LANG=C date '+%d%b%y-%H:%M:%S')"

USER="$(/bin/id | grep root | wc -l)"
if [[ $USER -eq 0 ]] ; then
    fatal_error "You must be root to run this script"
fi

X_BASE_PKG=SUNWxwplt/pkginfo

if [[ -f ${X_BASE_PKG} ]]; then
    X_ARCH="$(awk -F= '$1 == "ARCH" {print $2}' ${X_BASE_PKG})"
    X_VERSION="$(awk -F= '$1 == "SUNW_PRODVERS" {print $2}' ${X_BASE_PKG})"
    X_BUILD="$(nawk '/^VERSION=/ {FS="[,.]+" ; print $(NF-4)/100}' ${X_BASE_PKG})"
else
    fatal_error "Cannot find base X package -- SUNWxwplt\n" \ 
	"You need to run this script from the X ${XVERS} package area"
fi

if [[ "${X_ARCH}" != "${MACH}" ]]; then
    fatal_error "SUNWxwplt package has wrong architecture (${X_ARCH}).\n" \
	"It should have a ${MACH} architecture string."
fi

if [[ -z "${X_VERSION}" ]]; then
    fatal_error "Cannot find SUNWxwplt package version.\n" \
	"It should have a X ${XVERS} version string."
else
    if [[ "${X_VERSION}" != "${XVERS}" ]]; then
	fatal_error "SUNWxwplt package has wrong version (${X_VERSION}).\n" \
	    "It should have a X ${XVERS} version string."
    fi
fi

OS_REV="$(uname -r)"

if [[ "$OS_REV" != "5.11" ]] ; then
    fatal_error "Incorrect Solaris version number.\n" \
	"X ${XVERS} is only supported on Solaris Nevada or later"
fi

if [[ -f /usr/bin/pkg ]] ; then
    if /usr/bin/pkg list SUNWxwplt > /dev/null 2>&1 ; then
	fatal_error "Cannot run on system with IPS installed X packages."
    fi
fi

PKG_UPGRADE_LOG=/var/tmp/SunSoft_X${XVERS}_B${X_BUILD}_upgrade.log.${DATE}

####
#
#   Process command line options
#
####

QUIET=0

while getopts aq flag ; do
    case $flag in
      a)	;;
      q)	QUIET=1 ;;
      ?)	printf "Usage: %s: [-q]\n"  $0
		exit 1 ;;
    esac
done

####
#
#   List of packages to upgrade
#
####

# List of official (deliverable) X Consolidation packages for all platforms
# and all supported builds/releases
pkg_list="
	SUNWfontconfig 
	SUNWfontconfig-root
	SUNWfontconfig-docs 
	SUNWfreetype2
	SUNWi1of
	SUNWvncviewer
	SUNWxcursor-themes
	SUNWxorg-cfg
	SUNWxorg-client-docs
	SUNWxorg-client-programs
	SUNWxorg-clientlibs
	SUNWxorg-compatlinks
	SUNWxorg-devel-docs
	SUNWxorg-doc
	SUNWxorg-graphics-ddx
	SUNWxorg-headers
	SUNWxorg-server
	SUNWxorg-tsol-module
	SUNWxprint-server
	SUNWxscreensaver-hacks
	SUNWxscreensaver-hacks-gl
	SUNWxsun-server
	SUNWxvnc
	SUNWxwacx
	SUNWxwcft
	SUNWxwdem
	SUNWxwdim
	SUNWxwdxm
	SUNWxwfnt
	SUNWxwfs
	SUNWxwfsw
	SUNWxwhl
	SUNWxwice
	SUNWxwinc
	SUNWxwman
	SUNWxwmod
	SUNWxwoft
	SUNWxwopt
	SUNWxwpft
	SUNWxwplr
	SUNWxwplt
	SUNWxwpmn
	SUNWxwrtl
	SUNWxwslb
	SUNWxwsrv
	SUNWxwsvr
	SUNWxwts
	SUNWxwxft
"

# Some packages are only built for certain platforms currently
case "${MACH}" in
    sparc)      
        pkg_list+=" SUNWxwpsr" 
        ;;
    i386)       
        pkg_list+=" SUNWxorg-mesa" 
        ;;
esac

####
#
#   Deal with changes since various older Nevada builds
#
####        

# Packages to remove first, either because they are obsolete and not
# being replaced, or because they have been modified to conflict with
# other packages, and need to be removed before those other packages
# are added
REM_PKGS=""

# snv_19: SUNWxwfnt split into SUNWxwfnt & SUNWxwfsw packages [6276301]
# Need to remove SUNWxwfnt before installing SUNWxwfsw if 
# SUNWxwfsw is not currently installed
if ! /bin/pkginfo -q SUNWxwfsw ; then
    REM_PKGS+=" SUNWxwfnt"
fi

# snv_42: 6424854 Xsun & Xprt servers split out of SUNWxwplt
# Need to remove SUNWxwplt before installing SUNWxsun-server if 
# SUNWxsun-server isn't currently installed
if ! /bin/pkginfo -q SUNWxsun-server ; then
    REM_PKGS+=" SUNWxwplt"
fi

# snv_46: 6261914 Removal of STSF & Xst [PSARC 2006/087]
REM_PKGS+=" SUNWstsf SUNWstsfr SUNWxwxst"

# snv_91: 6699573 CDE Font Administration Tools removal [LSARC 2008/010]
REM_PKGS+=" SUNWxwfa"

# snv_97: 6731942 Remove SUNWxwsrc package
REM_PKGS+=" SUNWxwsrc"

# Various compatibility links in SUNWxorg-server have been replaced with
# files in other packages, so we need to remove SUNWxorg-server first
# (for example: 6658871 changed /usr/X11/lib/X11/fonts/Type1 from a link
# in SUNWxorg-server to a directory in SUNWxwcft, 6684643 changed 
# /usr/X11/lib/X11/rgb.txt from a link to a file in SUNWxwplt and so on)
if /bin/pkginfo -q SUNWxorg-server ; then
    REM_PKGS+=" SUNWxorg-server"
fi


# Check for shared SMF manifest scripts now required by our packages
if [[ ! -f /usr/sadm/install/scripts/i.manifest ]] ; then
    fatal_error "Cannot install on a Nevada build older than nv_17.\n" \ 
     "This build of X requires a system with the shared SMF manifest class\n" \
     "action scripts installed in /usr/sadm/install/scripts/i.manifest\n" \
     "(See Solaris bug id 6209178)\n"
fi

# S10/greenline upgrade support
function svc_disable 
{
    svcname="svc:$1:default";
    if [[ "$2" = "" ]] ; then
	manifest="/var/svc/manifest/$1.xml"
    else
	manifest="/var/svc/manifest/$2"
    fi

    if [[ -f $manifest ]] ; then
	/usr/sbin/svcadm -v disable -s $svcname 2>&1 | tee -a $PKG_UPGRADE_LOG
    fi
}


###
#
#   Do the upgrade
#
###

print ""
print "Starting X ${XVERS} Build ${X_BUILD} upgrade."
print "  An upgrade log file can be found at:"
print "    $PKG_UPGRADE_LOG"
print ""

VERBOSE="-n -a /tmp/admin.$$"

cat >/tmp/admin.$$ <<EOF
basedir=default
mail=
runlevel=quit
conflict=nocheck
setuid=nocheck
action=nocheck
partial=nocheck
instance=unique
idepend=nocheck
rdepend=nocheck
space=quit
EOF

# Back up OWconfig before adding/removing packages to 
# workaround pkg bug 4946663/4992643
cp /usr/openwin/server/etc/OWconfig /var/tmp/OWconfig.${DATE}

# Remove all instances of the specified package
function remove_package 
{
    pkg=$1
    if /bin/pkginfo -q ${pkg}.\* ; then
	for p in $(pkginfo ${pkg}.\* | awk '{print $2}') ; do
	    case "$pkg" in
		SUNWxwplr*)
		    svc_disable network/fs/tcp6 network/fs-tcp6.xml
		    svc_disable application/opengl/ogl-select
		    svc_disable application/x11/xfs
		    svc_disable application/x11/xvnc-inetd
		    ;;
		SUNWfontconfig-root*)
		    svc_disable application/font/fc-cache
		    ;;
		SUNWstsfr*)
		    svc_disable application/font/stfsloader
		    ;;
	    esac
	    /usr/sbin/pkgrm ${VERBOSE} ${p} 2>&1 \
		| tee -a ${PKG_UPGRADE_LOG} | grep $pkg
	done
    fi
}

for pkg in ${REM_PKGS} ; do
    remove_package $pkg
done

for pkg in ${pkg_list} ; do
    remove_package $pkg

    if [[ -e $pkg ]] ; then
	/usr/sbin/pkgadd -S ${VERBOSE}  -d . $pkg 2>&1 \
	    | tee -a ${PKG_UPGRADE_LOG} | grep $pkg
	print ""
    else
	if [[ $QUIET -eq 0 ]] ; then
	    print "No replacement found for $pkg"
	fi
    fi
done

# Start the rebuild of fontconfig caches now, instead of at next reboot
/usr/sbin/svccfg -s application/font/fc-cache setprop options/force_rebuild="true"
/usr/sbin/svcadm restart application/font/fc-cache


print "X ${XVERS} upgrade is complete"
print " "
print "  An upgrade log file can be found at:"
print "    $PKG_UPGRADE_LOG"

exit 0