#!/bin/sh # # $Id: pkg_install,v 1.2 2003-06-03 09:42:30-07 rpr Exp $ # # Script: pkg_install # # Purpose: This program will install the list of packages residing # in the target directory # # Author: Rodney P. Rutherford # # Born on Date: July 30, 1999 # # Modification History: # # 1.0 - Thu Sep 30 16:58:37 PDT 1999 - Rodney Rutherford # - Original script created and tested # #------------------------------------------------------------------------------ VERSION='1.0 -- Thu Sep 30 16:58:37 PDT 1999' COPYRIGHT='Copyright (C) 1999' AUTHOR='Rodney P. Rutherford ' SCRIPT=`basename $0` #------------------------------------------------------------------------------ # #======================== Start of Configuration ============================== # # Admin environment variables. Update these per the local environment: # ADMIN_DIR=/var/adm ADMIN_FILE=Sysadmin.history DESTDIR=/var/sadm NOASK=/tmp/noask_pkgadd PWD=`pwd` PRODUCT=`basename ${PWD}` LOG=$DESTDIR/${PRODUCT}.log # #------------------------------------------------------------------------------ # Fixed environment variables. These normally should not need updating. # PATH=/usr/bin:/usr/sbin:/usr/ucb FORCE=NO HOST=`hostname` STATUS=0 TIMESTAMP=`/usr/bin/date` TTY=`tty` ID=`id` USER=`expr "${ID}" : 'uid=\([^(]*\).*'` # #========================= End of Configuration =============================== # #========================== Start of Functions ================================ # # echo_tty will echo the string to both stdout, when it is being # redirected to the logfile, and to the tty in which the script # is being run. # echo_tty () { STRING=$1 echo "\n${STRING}" if [ "$TTY" != "not a tty" ] then echo "\n${STRING}" > $TTY fi } show_license () { echo "" echo " $SCRIPT version $VERSION" echo " $COPYRIGHT $AUTHOR" echo " This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. " } # # Function to install packages # install_packages () { while read name do PKGINFO="`pkginfo -d $PDIR $name`" echo_tty "\t\t$PKGINFO" logger -p user.err "$SCRIPT - Installing $name package" if [ -f ${PDIR}/${name}.answer ] then /usr/sbin/pkgadd -a $NOASK -r ${PDIR}/${name}.answer \ -d $PDIR $name else /usr/sbin/pkgadd -a $NOASK -d $PDIR $name fi done < $POF # # Verify all packages were installed on system. # while read package do echo_tty "\tVerifying installation of package ${package}..." /usr/sbin/pkgchk -n $package if [ $? -ne 0 ] then STATUS=255 echo " ******************************************************" echo " Package $package FAILED installation..." echo " ******************************************************" echo "" fi done < $POF } show_usage () { echo "" echo " $SCRIPT version $VERSION" echo " $COPYRIGHT $AUTHOR" echo "" echo " $SCRIPT will install the list of packages residing in the" echo " target directory." echo "" echo " Usage: $SCRIPT [-d directory] [-o order file] [-p post script]" echo "\t[-d directory] - path to packages, default is current directory" echo "\t[-f ] - force option, skips check to see if already installed" echo "\t[-o order file] - install order file, default is pkg_order" echo "\t[-p post script] - postinstall script, default is pkg_postinstall" echo "\t[-h] - show this usage message." echo "\t[-l] - show the license info." echo "" } error_check () { if [ $? -ne 0 ] then STATUS=255 export STATUS fi } # #========================= End of Functions =============================== # #====================== Start of Main Program ============================= # # Set default file permissions # umask 022 # # Clear the screen to easily see any install messages # clear # # Check to make sure the script is being run as root # if [ "$USER" != "0" ] then echo "" echo "\tERROR: You must be root to run $0" echo "" echo "\tExiting..." echo "" exit 2 fi # # Get any command line arguments specified # if [ $# -gt 0 ] then while getopts hld:fo:p: option do case $option in d) PDIR=$OPTARG if [ ! -d "$PDIR" ] then echo "" echo "\tERROR: The package directory specified was not found!" echo "" echo "\tExiting..." echo "" exit 3 fi ;; o) POF=$OPTARG if [ ! -r "$POF" ] then echo "" echo "\tERROR: The package order file specified was not found!" echo "" echo "\tExiting..." echo "" exit 4 fi ;; p) PST=$OPTARG if [ ! -r "$PST" ] then echo "" echo "\tERROR: The postinstall script specified was not found!" echo "" echo "\tExiting..." echo "" exit 5 fi ;; f) FORCE=YES;; h) show_usage; exit 1;; l) show_license; exit 1;; \?) show_usage; exit 1;; esac done fi # # If options were not set on the command line, set the defaults # PDIR=${PDIR:-`pwd`} POF=${POF:-${PDIR}/pkg_order} PST=${PST:-${PDIR}/pkg_postinstall} # # Check to make sure packages even exist # PKGCOUNT=`pkginfo -d $PDIR | wc -l` if [ "$PKGCOUNT" -eq "0" ] then echo "" echo "\tNo packages exist in the target directory:" echo "" echo "\t\t$PDIR" echo "" echo "\tExiting..." echo "" exit 6 fi # # Check/Create package order file # echo_tty "\tChecking for `basename $POF` file..." if [ ! -r $POF ] then echo_tty "\tPackage order file not found, creating temporary file..." pkginfo -d $PDIR | awk '{print $2}' > /tmp/package_order POF=/tmp/package_order fi # # If FORCE is not set, check to see if packages are already installed. # Exit if they are. # if [ "$FORCE" = "NO" ] then echo "" echo "\tChecking to see if packages are already installed..." sleep 2 EXIT=NO for name in `cat $POF` do pkginfo -q $name if [ $? -eq 0 ] then echo "\t\tThe $name package is already installed." EXIT=YES fi done if [ "$EXIT" = "YES" ] then echo "" echo "\tERROR: Some or all of the packages are already installed!" echo "" echo "\tPlease remove the existing packages with pkgrm before" echo "\tinstalling, or use the -f option to force the install." echo "" echo "\tExiting..." echo "" exit 7 fi else echo "" echo "\tWARNING: You specified the force option." echo "\t Any packages already installed will be overwritten." echo "" echo "\tDo you wish to continue? [y/n]: \c" while read answer do case $answer in y | Y | yes | YES ) break;; *) echo ""; echo "\tExiting..."; echo ""; exit 8;; esac done fi # # Redirect all output to a log file. This will overwrite any existing log # file of the same name. First we have to make sure the log directory exists. # if [ ! -d $DESTDIR ] then mkdir -m 755 -p $DESTDIR error_check fi exec > $LOG 2>&1 # # Echo starting messages # logger -p user.err "$SCRIPT - $PRODUCT being installed." echo_tty "$HOST: The $SCRIPT script started `date`" # # Create the temporary noask_pkgadd file # echo_tty "\tCreating the temporary noask_pkgadd file" echo "# adminfile3 # default basedir mail= instance=overwrite partial=nocheck runlevel=nocheck idepend=nocheck rdepend=nocheck space=nocheck setuid=nocheck conflict=nocheck action=nocheck basedir=default" > $NOASK # # Echo all environment variables to the log for troubleshooting # purposes if needed # echo "" echo "\t==========================User Environment===========================" echo "" env echo "" echo "\t==========================Script Environment==========================" echo "" echo "ADMIN_DIR=$ADMIN_DIR" echo "ADMIN_FILE=$ADMIN_FILE" echo "DESTDIR=$DESTDIR" echo "NOASK=$NOASK" echo "PWD=$PWD" echo "PRODUCT=$PRODUCT" echo "LOG=$LOG" echo "" echo "PATH=$PATH" echo "HOST=$HOST" echo "STATUS=$STATUS" echo "TIMESTAMP=$TIMESTAMP" echo "TTY=$TTY" echo "ID=$ID" echo "USER=$USER" echo "" echo "PDIR=$PDIR" echo "POF=$POF" echo "PST=$PST" echo "POF=$POF" echo "" echo "\t=====================End of Script Environment=======================" # # Install the packages # echo_tty "\tThe logfile is $LOG" echo_tty "\tInstalling ${PRODUCT} packages..." install_packages error_check # # Run the post install script if specified # if [ -r $PST ] then echo_tty "\tRunning the post install script..." . $PST error_check fi # # Update the admin history file # echo_tty "\tUpdating the ${ADMIN_FILE} file in ${ADMIN_DIR}..." echo "" >> $ADMIN_DIR/$ADMIN_FILE date >> $ADMIN_DIR/$ADMIN_FILE echo "" >> $ADMIN_DIR/$ADMIN_FILE echo "\tThe following packages have been installed:" >> $ADMIN_DIR/$ADMIN_FILE echo "" >> $ADMIN_DIR/$ADMIN_FILE for pkg in `cat $POF` do pkginfo $pkg >> $ADMIN_DIR/$ADMIN_FILE error_check done echo "" >> $ADMIN_DIR/$ADMIN_FILE echo "See the file $LOG in /var/sadm for details." >> $ADMIN_DIR/$ADMIN_FILE echo "" >> $ADMIN_DIR/$ADMIN_FILE # # Check for errors and exit # if [ $STATUS -eq 255 ] then echo_tty "WARNING: The $PRODUCT failed to install properly" echo_tty "Exiting..." echo_tty "" /usr/ucb/logger -p user.err "$SCRIPT - The install FAILED!" test -f /tmp/package_order && /bin/rm /tmp/package_order /bin/rm $NOASK exit 9 else echo_tty "$HOST: The $SCRIPT script completed `date`" echo_tty "" test -f /tmp/package_order && /bin/rm /tmp/package_order /bin/rm $NOASK exit 0 fi