#!/bin/ksh # Author: Bernd Finger, Sun Microsystems # Purpose: rename firefox packages to include version numbers so that # multiple firefox versions can be installed in parallel TMPDIR=/tmp SPOOLDIR=${TMPDIR}/extracted-firefox-$(date +%Y%m%d-%H%M%S) PKG_FILENAME_BZ2=$1 PKG_FILENAME=$(echo ${PKG_FILENAME_BZ2} | sed 's,\.bz2,,') if [[ ! -f ${PKG_FILENAME_BZ2} ]]; then echo "File ${PKG_FILENAME_BZ2} does not exist. Exiting." exit 1 fi printf "Expanding package file ${PKG_FILENAME_BZ2} to ${PKG_FILENAME}..." if [[ -f ${PKG_FILENAME} ]]; then echo "File ${PKG_FILENAME} already exists. Will use that one." else bzip2 -dc ${PKG_FILENAME_BZ2} > ${PKG_FILENAME} if [[ $? -ne 0 ]]; then echo " Error." exit 1 else echo " done." fi fi OLD_PKG_NAME=$(pkginfo -d ${PKG_FILENAME} | nawk '{print $2}') MOZ_VERSION=$(pkginfo -d ${PKG_FILENAME} -l | nawk '/VERSION/{gsub (",", " "); gsub ("\\.", "");print $2}') NEW_PKG_NAME=${OLD_PKG_NAME}-${MOZ_VERSION} mkdir -p ${SPOOLDIR} echo "Spool directory ${SPOOLDIR} created." printf "Extracting package file ${PKG_FILENAME} to spool directory..." echo pkgadd -d ${PKG_FILENAME} -s ${SPOOLDIR} ${OLD_PKG_NAME} pkgadd -d ${PKG_FILENAME} -s ${SPOOLDIR} ${OLD_PKG_NAME} if [[ $? -ne 0 ]]; then echo " Error." exit 1 else echo " done." fi # cd ${SPOOLDIR}/${OLD_PKG_NAME}/reloc/sfw/lib # OLD_DIR_NAME=$(echo *) cd ${SPOOLDIR}/${OLD_PKG_NAME}/reloc OLD_DIR_NAME=$(find . -type d -name firefox | nawk 'BEGIN{FS="/"}NR==1{print $NF}') NEW_DIR_NAME=${OLD_DIR_NAME}-${MOZ_VERSION} cd ${SPOOLDIR}/${OLD_PKG_NAME} printf "Now in directory: " pwd ls -al echo "Renaming directory ${OLD_DIR_NAME} to ${NEW_DIR_NAME}:" find . -type d -name ${OLD_DIR_NAME} | nawk '{a=$1;sub ("'${OLD_DIR_NAME}'", "'${NEW_DIR_NAME}'", a); print ("mv "$1" "a)}' find . -type d -name ${OLD_DIR_NAME} | nawk '{a=$1;sub ("'${OLD_DIR_NAME}'", "'${NEW_DIR_NAME}'", a); system ("mv "$1" "a)}' if [[ $? -ne 0 ]]; then echo " Error." exit 1 else echo " done." fi printf "Changing pkginfo file..." sed '/^PKG/s,'${OLD_PKG_NAME}','${NEW_PKG_NAME}',' pkginfo > pkginfo.new mv -f pkginfo.new pkginfo if [[ $? -ne 0 ]]; then echo " Error." exit 1 else echo " done." fi printf "Checking if sum supports option s..." sum -s /dev/null >/dev/null 2>&1 RC=$? if [[ ${RC} -eq 0 ]]; then SUM_OPTION=" -s" echo " yes" else SUM_OPTION="" echo " no" fi SUM_PKGINFO=$(sum${SUM_OPTION} pkginfo | nawk '{print $1}') SIZE_PKGINFO=$(ls -l pkginfo | nawk '{print $5}') printf "Changing pkgmap file..." nawk '$3=="pkginfo"{printf ("%s %s %s %s %s %s\n", $1, $2, $3, "'${SIZE_PKGINFO}'", "'${SUM_PKGINFO}'", $6)} $3!="pkginfo"{sub ("'${OLD_DIR_NAME}'", "'${NEW_DIR_NAME}'"); print}' pkgmap > pkgmap.new mv -f pkgmap.new pkgmap echo " done." cd ${SPOOLDIR} mv ${OLD_PKG_NAME} ${NEW_PKG_NAME} echo echo "Please install ${NEW_PKG_NAME} by executing:" echo "cd ${SPOOLDIR}" echo "pkgadd -d . ${NEW_PKG_NAME}"