/bin/tpinstall
Korn Shell | 1503 lines | 953 code | 157 blank | 393 comment | 215 complexity | b74fb429b09ea6ed34c3d3162d214ba6 MD5 | raw file
- #!/usr/bin/ksh
- #########################################################################
- # #
- # Name: tpinstall (shell script) #
- # #
- # Completed: 28th August, 2003. #
- # #
- # Updated: 5th July, 2004. #
- # #
- # Author: Simon Edwards, Proprius Consulting Ltd. #
- # #
- # Arguments: Commit a package: #
- # -c -p pkg [-v] #
- # -c Indicate we wish to commit the package #
- # -p Specifies the name of the package #
- # -v Verbose mode, show progress messages. #
- # #
- # Install a package: #
- # -i -d depot -p pkgfile [-f] [-v] [-r dir] [l] [-n] [-s] #
- # -P #
- # -i Indicate we wish to install the package #
- # -d Directory containing the tarp files. #
- # -p The file containing the tarp package. #
- # [See notes on PACKAGE FILES below for more #
- # details.] #
- # -f Force installation, (allowing the same version #
- # or an older version to be installed). #
- # -v Verbose mode, show progress messages. #
- # -r Indicates the top level directory to install #
- # to, overriding the ROOTDIR setting in the #
- # package specification. #
- # -l List the dependencies for installing the #
- # package and then exit. #
- # -x Ignore dependency installation, just install #
- # the required package. #
- # -n Do not commit the package - leave it in #
- # installed state. #
- # -s Do not run the postinstall.perms script - #
- # leaving permissions to default values. #
- # [Useful when installing the packages that are #
- # by default owned by somebody else]. #
- # [When running as a normal user the chown #
- # will now be ignored.] #
- # -P Preview mode - (best used with verbose mode) #
- # show the details pertaining to the installation #
- # without actually performing the install. #
- # #
- # Purpose: #
- # #
- # This program will install a tarp package. The tarp PACKAGE FILE #
- # is a tar file which contains the programs to install - relative to #
- # the root directory - as well as the following special files: #
- # #
- # spec The package specification file, which must contain #
- # at least the following fields: #
- # NAME, DESCRIPTION, VERSION. #
- # Optionally includes VENDOR, LICENSE, ROOTDIR, #
- # and DEPENDENCIES. #
- # #
- # checkinstall A script to run to check to see if the package can be #
- # installed. If returns 0, it can be, if returns 1 it #
- # can not be. #
- # preinstall A script to extract and run prior to installation - #
- # if it returns 0 the package can be installed. If it #
- # returns 1 the package can be force installed, and #
- # if it returns 2 the package can not be installed. #
- # postinstall This script is run when the package has been #
- # successfully installed. #
- # preremove This script is run before removing the package from #
- # the system. #
- # postremove This package is run after removing the package from #
- # the system. #
- # #
- # All four of the pre and post install scripts have a #
- # variable set called PACKAGE - which is the name of #
- # the current package, and VERSION which stores the #
- # version of the package. #
- # #
- # PACKAGE FILES #
- # A tarp package (as described above) allows a single #
- # package to be installed. However the latest verion #
- # also supports installation or update from a TARP #
- # BUNDLE. This is a single file that contains a number #
- # of package files. #
- # #
- # A tarp bundle has the extension name of tarpb and #
- # contains 1 or more packages. It is possible to #
- # specify the name of the bnudle to install all #
- # packages, (at least those where the checkinstall #
- # script - if it exists - is successful). Or it is #
- # possible to upadate from it - just install the #
- # components that are newer and are already installed. #
- # #
- # It is also possible to install just a specified #
- # component using the naming scheme of: bundle.package. #
- # #
- # Package Database: #
- # #
- # The list of installed packages is kept in a database, #
- # usually in /var/adm/tarp. Each package is kept in a #
- # sub-directory called the name of the package. This #
- # sub-directory contains the current spec file, as well #
- # as the pre/post install/remove scripts. #
- # #
- # This directory also a file called cksums which contains #
- # a list of the files installed and the cksum in the #
- # format of: #
- # /full/path|cksum #
- # #
- # The checksum is based on the results of cksum if #
- # running on HP-UX, or MD5 if running under Linux. #
- # #
- # The directory also contains a status file which can #
- # contain "installed", "committed", "broken". #
- # When a package is installed, but not committed, any #
- # files that already exist are kept in the directory #
- # under a sub-directory called saved_files. #
- # #
- # In this instance when a installed package is removed, #
- # any over-written files are recovered. When a package #
- # is committed then these files are removed, meaning #
- # de-installation of the package will remove the files #
- # completely. #
- # #
- # A new version of the same package can only be #
- # installed if an existing version is committed. #
- # #
- # If a package is installed from a bundle, or a #
- # complete bundle is installed, then the name of the #
- # directory the files are installed into is: #
- # bundle.package #
- # #
- # The package name does not need to be unique - so #
- # beware. #
- # #
- # Limitations: [1] Current version does not include all the cleanup #
- # functionality when failures occur. This will be #
- # added in later versions. #
- # #
- # VERSION: #(@)1.1 Original (SE) #
- # #(@)1.2 Corrected handling of cpio stderr (SE)> #
- # #(@)1.3 Updated to support bash (SE)> #
- # #(@)1.4 Change integer to typeset -i (SE)> #
- # #(@)1.5 Revert to ksh (bash problems) (SE)> #
- # #(@)1.7 Log pre/post installation improvements (SE)> #
- # #(@)1.8 Correct compress/bzip2 syntax problems (SE)> #
- # #(@)1.9 Implement VOLATILE_EXT option info (SE)> #
- # #(@)1.10 Fixes of 0007, 0008, 0009 and 0010 (SE)> #
- # #(@)1.11 Small syntax correction... #
- # #(@)1.12 Support for OVERWRITE in spec file (SE)> #
- # #
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
- # VERSION HISTORY: #
- # #
- # Version: 1.12 #
- # Date: 6th February, 2004. #
- # Author: Simon Edwards, Proprius Consulting Ltd. #
- # Changes: Support for OVERWRITE in spec file, which defaults to #
- # YES if not specified. If set to NO it means that the #
- # package must be removed using tpremove first - newer #
- # versions can simply 'update' the previous version. #
- # #
- # Version: 1.7 #
- # Date: 26th December, 2003. #
- # Author: Simon Edwards, Proprius Consulting Ltd. #
- # Changes: Fixed bug 0002 (so the post installation script is #
- # actually run), and improvement 0003 (so the output of #
- # pre and post installation scripts are captured and #
- # kept). #
- # Also modified to support installation from compressed, #
- # gzip compressed and bzip2 format archives as well #
- # (improvement 0004). #
- # #
- # Version: 1.3 #
- # Date: 4th September, 2003. #
- # Author: Simon Edwards, Proprius Consulting Ltd. #
- # Changes: Modified to ensure that ARG_DEPOT and ARG_ROOTDIR #
- # are exported - allowing them to be used for pre and #
- # post installation scripts, (so your know the relative #
- # location of the files installed). #
- # #
- # Version: 1.2 #
- # Date: 2nd September, 2003. #
- # Author: Simon Edwards, Proprius Consulting Ltd. #
- # Changes: Modified the handling of the cpio stderr slightly, #
- # since linux dumps out the file names as well as the #
- # errors to this file descriptor. #
- # Version: #
- # Date: #
- # Author: #
- # Changes: #
- # #
- #########################################################################
- print=print
- TMP_BUNDLE_DEPOT=""
- export ARG_PKG=""
- export ARG_DEPOT=""
- export ARG_ROOTDIR=""
- ARG_INDENT=0
- ARG_FORCE=0
- ARG_UPDATE=0
- ARG_NOPERMS=0
- ARG_VERBOSE=0
- ARG_LISTDEPS=0
- ARG_NODEPS=0
- ARG_NOCOMMIT=0
- ARG_PREVIEW=0
- ARG_INBUNDLE=""
- ind[0]=""
- ind[1]=" "
- ind[2]=" "
- ind[3]=" "
- ind[4]=" "
- ind[5]=" "
- function logmsg
- {
- [[ $ARG_VERBOSE -eq 1 ]] && $print "MSG : ${ind[$ARG_INDENT]}$1"
- }
- function logwarn
- {
- $print "WARN : ${ind[$ARG_INDENT]}$1"
- }
- function logwarnfile
- {
- for cline in $(<$1)
- do
- $print "WARN : ${ind[$ARG_INDENT]}$cline"
- done
- }
- function logerror
- {
- $print "ERROR: ${ind[$ARG_INDENT]}$1" >&2
- [[ -n "$2" ]] && exit $2
- }
- function logerrorfile
- {
- for cline in $(<$1)
- do
- $print "ERROR: ${ind[$ARG_INDENT]}$cline"
- done
- [[ -n "$2" ]] && exit $2
- }
- function showscriptinfo
- {
- typeset XX
- XX=$VERBOSE
- VERBOSE=1
- if [[ -n "$prelogoutput" && -s "$prelogoutput" ]]
- then
- logmsg "Pre installation script output can be found in $prelogoutput"
- fi
- if [[ -n "$prelogerror" && -s "$prelogerror" ]]
- then
- logmsg "Pre installation script errors can be found in $prelogerror"
- fi
- if [[ -n "$postlogoutput" && -s "$postlogoutput" ]]
- then
- logmsg "Post installation script output can be found in $postlogoutput"
- fi
- if [[ -n "$postlogerror" && -s "$postlogerror" ]]
- then
- logmsg "Post installation script errors can be found in $postlogerror"
- fi
- VERBOSE=$XX
- }
- function cleanup
- {
- typeset dir="$1"
- cd
- if [[ -n "$TMPDIR" && -d "$TMPDIR" ]]
- then
- logmsg "Cleaning up directory $TMPDIR"
- rm -rf $TMPDIR
- fi
- if [[ -n "$TMP_BUNDLE_DEPOT" && -d "$TMP_BUNDLE_DEPOT" ]]
- then
- logmsg "Cleaning up temporary bundle depot $TMP_BUNDLE_DEPOT"
- rm -rf $TMP_BUNDLE_DEPOT
- else
- logmsg "No TMP_BUNDLE_DEPOT defined (no tmp depot to remove)"
- fi
- #################################################################
- # We also remove any old copies of an installed package we #
- # have just updated... #
- #################################################################
- [[ -d $TARP_DB/$ARG_PKG.tmp ]] && rm -rf $TARP_DB/$ARG_PKG.tmp
- #################################################################
- # Remove any preinstall and postinstall log files that are #
- # empty. #
- #################################################################
- [[ -n "$prelogoutput" && ! -s "$prelogoutput" ]] &&
- rm -f $prelogoutput
- [[ -n "$prelogerror" && ! -s "$prelogerror" ]] &&
- rm -f $prelogerror
- [[ -n "$postlogoutput" && ! -s "$postlogoutput" ]] &&
- rm -f $postlogoutput
- [[ -n "$postlogerror" && ! -s "$postlogerror" ]] &&
- rm -f $postlogerror
- [[ ! -d "$dir/saved_files" ]] && return
- logmsg "Restoring original files..."
- (cd $dir/saved_files && tar cpf - . 2>/dev/null) |
- (cd $ARG_ROOTDIR && tar xpf - ) || {
- logwarn "Unable to restore all files overwritten!";
- logwarn "dir=$dir,ARG_ROOTDIR=$ARG_ROOTDIR";
- }
- [[ -f /tmp/tpinstall-$$.3 ]] && rm -f /tmp/tpinstall-$$.3
- }
- function usage {
- printf "Usage: Installing a package:\n $_PRG -i -p [bundle.]pkg [-d depot] [-f] [-v] [-r root] [-l] [-x] [-n]\n\n" >&2
- printf " Preview package installation:\n $_PRG -P -i -p [bundle.]pkg [-d depot] [-f] [-v] [-r root] [-l] [-x] [-n]\n\n" >&2
- printf " Comitting a package:\n $_PRG -c -p [bundle.]pkg [-v]\n\n" >&2
- printf " Updating a bundle:\n $_PRG -u -c -p bundle [-v]\n\n" >&2
- printf "Written by Simon Edwards, Proprius Consulting (www.proprius.co.uk)\n" >&2
- printf "For more information please see the $_PRG(1M) manual page.\n\n" >&2
- exit 1
- }
- TARP_DB=${TARP_DB:-/var/adm/tarpdb}
- _PRG=$(basename $0)
- typeset -i commit=0
- typeset -i install=0
- [[ -x /opt/oss/bin/gawk ]] && awk=/opt/oss/bin/gawk
- [[ -z "$awk" && -x /usr/bin/gawk ]] && awk=/usr/bin/gawk
- [[ -z "$awk" && -x /usr/bin/nawk ]] && awk=/usr/bin/nawk
- [[ -z "$awk" ]] && awk=awk
- [[ ! -d $TARP_DB ]] && {
- mkdir -p $TARP_DB 2>/dev/null || {
- showscriptinfo;
- logerror "Unable to create directory: $TARP_DB" 10;
- }
- }
- if [[ "$($print "$0" | $awk '{print substr($0,1,2)}')" = ".." ]]
- then
- _PRG2=$PWD/$0
- else
- [[ "$($print "$0" | $awk '{print substr($0,1,1)}')" = "." ]] &&
- _PRG2=$PWD/$_PRG ||
- _PRG2=$0
- fi
- while getopts ":cid:p:fsPxvr:luj:B:" copt
- do
- case $copt in
- B) ARG_INBUNDLE=$OPTARG
- ;;
- j) ARG_INDENT=$OPTARG
- ;;
- u) ARG_UPDATE=1
- ;;
- v) ARG_VERBOSE=1
- ;;
- s) ARG_NOPERMS=1
- ;;
- f) ARG_FORCE=1
- ;;
- n) ARG_NOCOMMIT=1
- ;;
- c) commit=1
- ;;
- i) install=1
- ;;
- x) ARG_NODEPS=1
- ;;
- l) ARG_LISTDEPS=1
- ;;
- P) ARG_PREVIEW=1
- ;;
- d) ARG_DEPOT=$OPTARG
- ;;
- p) ARG_PKG=$OPTARG
- ;;
- r) ARG_ROOTDIR=$OPTARG
- ;;
- ?) usage
- ;;
- esac
- done
- BUNDLE=$($print -- "$ARG_PKG" | $awk -v FS="\." 'NF==2 {print $1}')
- [[ -n "$BUNDLE" ]] && {
- ARG_PKG=$(print "$ARG_PKG" | $awk -v FS="\." '{print $2}');
- }
- ((install+commit!=1)) && usage
- [[ -z "$ARG_PKG" ]] && usage
- [[ -z "$ARG_DEPOT" ]] && ARG_DEPOT="$PWD"
- ARCH="$(uname -m|sed 's/\///g')"
- OS="$(uname)"
- [[ -z "$ARG_ROOTDIR" ]] && ARG_ROOTDIR="/"
- ((install==1)) && [[ $ARG_PREVIEW -eq 1 ]] &&
- logmsg "Previewing installation of package $ARG_PKG.."
- logmsg "Package database directory: $TARP_DB"
- #########################################################################
- # If we have specified a depot, then make sure we are able to find #
- # it - and it contains details of the package to install. #
- #########################################################################
- if [[ $install -eq 1 ]]
- then
- if [[ -n "$ARG_DEPOT" ]]
- then
- fc=$($print $ARG_DEPOT|$awk '{print substr($0,1,1);}')
- if [[ "$fc" != "/" ]]
- then
- showscriptinfo
- logerror "Depot must be given as absolute path" 12
- fi
- fi
- #################################################################
- # We may need to check for a BUNDLE first rather than a #
- # package, the methods taken depending on whether BUNDLE is #
- # set or not: #
- # BUNDLE not set: #
- # [1] Check for bundle files - .tarpb, .tarpb.EXT #
- # [2] If not found check for package - .tarp, .tarp.EXT #
- # [3] Abort if none found #
- # #
- # BUNDLE set: #
- # [1] Check for bundle files - BUNDLE.tarpb, BUNDLE.tarpb.EXT #
- # [2] Abort if none found #
- # #
- # In all cases, EXT can be Z, gz or bz2 #
- #################################################################
- #################################################################
- # Please note that bundle names are in the following format: #
- # BUNDLE,version.tarpb[.Z|.gz|.bz2 #
- #################################################################
- if [[ -n "$BUNDLE" ]]
- then
- matches="$(cd $ARG_DEPOT; eval ls "${BUNDLE},*.tarpb" "${BUNDLE},*.tarpb.gz" "${BUNDLE},*.tarpb.bz2" "${BUNDLE},*.tarpb.Z" 2>/dev/null)"
- else
- bmatches="$(cd $ARG_DEPOT; eval ls "${ARG_PKG},*.tarpb" "${ARG_PKG},*.tarpb.gz" "${ARG_PKG},*.tarpb.bz2" "${ARG_PKG},*.tarpb.Z" 2>/dev/null)"
- matches="$(cd $ARG_DEPOT; eval ls "${ARG_PKG},*.tarp" "${ARG_PKG},*.tarp.gz" "${ARG_PKG},*.tarp.bz2" "${ARG_PKG},*.tarp.Z" 2>/dev/null)"
- if [[ -n "$bmatches" ]]
- then
- if [[ -n "$matches" ]]
- then
- logwarn "Package $ARG_PKG matching bundle and package - default to bundle."
- else
- logmsg "Found matching bundle $ARG_PKG in depot $ARG_DEPOT"
- fi
- BUNDLE=$ARG_PKG
- matches="$bmatches"
- ARG_PKG=".*"
- fi
- fi
- if [[ -z "$matches" && $install -eq 1 ]]
- then
- showscriptinfo
- if [[ -n "$BUNDLE" ]]
- then
- logerror "Unable to find bundle $BUNDLE in depot $ARG_DEPOT" 2
- else
- logerror "Unable to find package $ARG_PKG in depot $ARG_DEPOT" 2
- fi
- fi
- fi
- #########################################################################
- # #
- # If we do not have a bundle then do the following: #
- # If we have a series of matches we need to decide which one we #
- # intend to install. To choose the package the following rules are #
- # applied: #
- # [1] If any files exist for the specified OS-Arch exist, then #
- # discard all others from the list. #
- # [2] If any files exist for this OS, with no architecture, then #
- # discard all others from the list. #
- # [3] Discard any files with an OS different from ours. #
- # [4] Discard any files with the same OS, but different architecture. #
- # #
- # From the remaining list choose one which has the highest version #
- # number. #
- # Remember that the format of the package is as follows: #
- # name,version[,OS[,Arch]].tarp #
- # #
- # If BUNDLE is set then we need to do the following: #
- # [1] Sort the version numbers and choose the highest. #
- # [2] ARG_PKG is .* or name to install. #
- #########################################################################
- function get_latest_match
- {
- $print "$*" |
- $awk -v debug=0 -v OS=$OS -v ARCH=$ARCH 'function cmpver(v1,v2,x1,x2) {
- split(v1,x1,/-/); split(v2,x2,/-/);
- if(x1[1]>x2[1]) return 1;
- if(x1[1]<x2[1]) return -1;
- if(x1[2]>x2[2]) return 1;
- if(x1[2]<x2[2]) return -1;
- if(x1[3]>x2[3]) return 1;
- if(x1[3]<x2[3]) return -1;
- return 0;
- }
- {
- p1=".*,[0-9]+(-[0-9]+)+," OS "," ARCH ".tarp";
- p2=".*,[0-9]+(-[0-9]+)+," OS ".tarp";
- s1=".*,[0-9]+(-[0-9]+)+";
- this=$0;
- if(match($0,p1)) {
- JUST_THIS_OSARCH=1;
- }
- if(match($0,p2)) {
- JUST_THIS_OS=1;
- }
- # Get rid of the pkgname and release
- sub(s1,"",this);
- sub(/\.tarp.*$/,"",this);
- if(this == "") {
- matches[X++]=$0;
- next;
- }
- if(debug) print "this = " this > "/dev/tty"
- # Ignore packages for different operating system
- if(JUST_THIS_OSARCH || JUST_THIS_OS)
- {
- if(substr(this,2,length(OS)) != OS) next;
- if(debug) print "OS matched: " OS > "/dev/tty";
- }
- if(JUST_THIS_OSARCH)
- {
- x=index(this,",");
- # Ignore packages for same OS, but different architecture
- if(substr(this,length(this)-length(ARCH)+1) != ARCH) next;
- }
- matches[X++]=$0;
- if(debug) print "Added: " $0 > "/dev/tty";
- }
- END {
- # If JUST_THIS_OSARCH is set, then ignore generic files
- # from the list.
- p1=".*,[0-9]+(-[0-9]+)+," OS "," ARCH "\\.tarp";
- p2=".*,[0-9]+(-[0-9]+)+," OS "\\.tarp";
- p3=",[0-9]+(-[0-9]+)+";
- if(JUST_THIS_OSARCH) {
- X2=0;
- for(i in matches) {
- match(matches[i],p1);
- if(debug) print "Check: " matches[i] > "/dev/tty";
- if(RSTART==1) {
- matches2[X2++]=matches[i];
- }
- }
- }
- if(JUST_THIS_OS && ! JUST_THIS_OSARCH) {
- X2=0;
- for(i in matches) {
- match(matches[i],p2);
- if(RSTART==1) {
- matches2[X2++]=matches[i];
- }
- }
- }
- if(JUST_THIS_OS+JUST_THIS_OSARCH==0) {
- if(debug) print "Only match generic packages" > "/dev/tty";
- X2=0;
- for(i in matches) {
- if(debug) print "Check: " matches[i] > "/dev/tty";
- matches2[X2++]=matches[i];
- }
- }
- # matches2 contains a list of candidates, so now we
- # pick one which has the highest version...
- CVERSION="0-0-0";
- hadmatch=0;
- for(i in matches2) {
- match(matches2[i],p3);
- if(debug) print matches2[i] " : len=" RLENGTH ",start=" RSTART > "/dev/tty";
- mstr=substr(matches2[i],RSTART,RLENGTH);
- mstr=substr(mstr,2,length(mstr)-1);
- if(debug) print "Comparing " CVERSION " and " mstr > "/dev/tty";
- if(cmpver(mstr,CVERSION)==1) {
- CVERSION=mstr;
- CFILE=matches2[i];
- hadmatch=1;
- }
- }
- # Print the matched file, or nothing if no matches!
- if(hadmatch) {
- print CFILE,CVERSION;
- }
- }'
- }
- if [[ $install -eq 1 ]]
- then
- xxdata="$(get_latest_match $matches)"
- install_file="$($print $xxdata | $awk '{print $1}')"
- install_version="$($print $xxdata | $awk '{print $2}'|sed 's/-/./g')"
- if [[ -z "$install_version" ]]
- then
- showscriptinfo
- logerror "No matching packages found." 4
- fi
- logmsg "Installing from file $install_file";
- fi
- ## HERE - install_file/version will be BUNDLE if BUNDLE set...
- if [[ -n "$BUNDLE" ]]
- then
- logmsg " [$install_file is a bundle]"
- logmsg " [Installing packages of pattern \"$ARG_PKG\" from bundle $BUNDLE version $install_version]"
- #########################################################
- # Now get a list of packages that will be considered #
- # for installation... #
- #########################################################
- flist="$(tar tf "$ARG_DEPOT/$install_file"| sort | uniq |
- $awk -v P="$ARG_PKG" 'BEGIN {last="";} /\.tarp$/ || /\.tarp\.gz$/ || /\.tarp\.Z$/ || /\/.tarp\.bz2$/ {if(match(substr($0,3),P)) {p=substr($0,3,index($0,",")-3); if(p!=last) {printf(" "); } else {printf("|");} printf("%s",substr($0,3));}}')"
- logmsg "Initial package list: $flist"
- #################################################################
- # This is the interesting bit ... we recursively call this #
- # program to check each file, and if suitable install it... #
- # We break down the list of packages into common names - since #
- # a bundle can actually have code for multiple architectures #
- # available... #
- #################################################################
- TMP_BUNDLE_DEPOT=$TARP_DB/bundle-$$.tmp
- mkdir $TMP_BUNDLE_DEPOT 2>/dev/null || {
- logerror "Unable to create temporary directory.";
- logerror "[Directory is $TMP_BUNDLE_DEPOT]" 22;
- }
-
- #################################################################
- # We actually extract everything - since we might have #
- # dependencies on other things in the bundle. #
- #################################################################
- logmsg "Extracting bundle contents to temporary directory."
- logmsg "[directory = $TMP_BUNDLE_DEPOT]"
- cwd=$PWD
- cd $TMP_BUNDLE_DEPOT
- tar xf $ARG_DEPOT/$install_file 2>/dev/null || {
- logerror "Unable to extract bundle contents." 23;
- }
- #################################################################
- # We now call tpinstall for each of the attempted sets of #
- # packages to install. #
- #################################################################
- export TMP_BUNDLE_DEPOT
- newilist=""
- for cinstall in $flist
- do
- tmatches="$(get_latest_match "$($print "$cinstall" | sed 's/\|/ /g')")"
- install_file="$($print $tmatches | $awk '{print $1}')"
- install_version="$($print $tmatches | $awk '{print $2}'|sed 's/-/./g')"
- install_pkg="$($print $install_file | $awk -v FS=, '{print $1}')"
- cmd="$_PRG2 -i -p $install_pkg -d $TMP_BUNDLE_DEPOT -l"
- ((ARG_VERBOSE)) && cmd="$cmd -v"
- [[ -n "$BUNDLE" ]] && cmd="$cmd -B $BUNDLE"
- logmsg "Installing $install_pkg."
- logmsg " Finding dependencies for $install_pkg [version $install_version]:"
- logmsg " $cmd"
- eval "$cmd" >> /tmp/tps-$$.errs 2>&1
- rc=$?
- [[ $rc = 99 ]] && {
- logmsg " Package installed at required version.";
- continue;
- }
- if [[ $rc != 0 ]]
- then
- logerror "Unable to find dependencies for $install_pkg - aborting"
- logerror "See file /tmp/tps-$$.errs for details."
- fi
- newilist="$newilist $cinstall"
- done
- logmsg "All dependencies are available - continuing."
- #################################################################
- # We now attempt to install the packages... #
- #################################################################
- [[ -f "/tmp/tps-$$.errs" ]] && rm -f "/tmp/tps-$$.errs"
- for cinstall in $newilist
- do
- tmatches="$(get_latest_match "$($print "$cinstall" | sed 's/\|/ /g')")"
- install_file="$($print $tmatches | $awk '{print $1}')"
- install_version="$($print $tmatches | $awk '{print $2}'|sed 's/-/./g')"
- install_pkg="$($print $install_file | $awk -v FS=, '{print $1}')"
- [[ -z "$install_file" ]] && continue
- cmd="$_PRG2 -i -p $install_pkg -d $TMP_BUNDLE_DEPOT -j 2 -B $BUNDLE"
- ((ARG_VERBOSE)) && cmd="$cmd -v"
- ((ARG_PREVIEW)) && cmd="$cmd -P"
- ((ARG_NOPERMS)) && cmd="$cmd -s"
- ((ARG_NOPERMS)) && cmd="$cmd -s"
- [[ -n "$ARG_ROOTDIR" ]] && cmd="$cmd -r $ARG_ROOTDIR"
- logmsg "Installation of $install_pkg [version $install_version]:"
- logmsg " $cmd"
- [[ ! -f /tmp/tps-$$.errs ]] && $print "" >/tmp/tps-$$.errs
- ll=$(wc -l < /tmp/tps-$$.errs)
- eval "$cmd" 2>&1 | tee -a /tmp/tps-$$.errs
- if [[ -n "$($awk -v LL=$ll 'NR>LL && /ERROR/ {print 1}' /tmp/tps-$$.errs)" ]]
- then
- cleanup
- logerror "Unable to install $install_pkg - aborting"
- logerror "See file /tmp/tps-$$.errs for details." 24
- fi
- done
- cleanup
- logmsg "Packages successfully installed - see /tmp/tps-$$.errs for details."
- exit 0
- fi
- [[ $ARG_LISTDEPS -eq 1 ]] && $print "V $install_version"
- #########################################################################
- # If we are about to commit a package, then we actually do quite #
- # little - we change the status file to "committed" and remove the #
- # saved_files sub-directory. #
- #########################################################################
- if [[ $commit -eq 1 ]]
- then
- if [[ ! -d $TARP_DB/$ARG_PKG ]]
- then
- showscriptinfo
- logerror "Package $ARG_PKG is not yet installed" 3
- fi
- #################################################################
- # Change the status to committed, assuming that it is #
- # currently set to installed. #
- #################################################################
- if [[ ! -f "$TARP_DB/$ARG_PKG/status" ]]
- then
- status="Unknown";
- else
- status="$(<$TARP_DB/$ARG_PKG/status)"
- fi
- if [[ "$status" != "installed" ]]
- then
- showscriptinfo
- logerror "Can not commit a package when in $status status" 6
- fi
- #################################################################
- # Now removed the saved_files sub-directory if it exists. #
- #################################################################
- if [[ -d "$TARP_DB/$ARG_PKG/saved_files" ]]
- then
- rm -rf "$TARP_DB/$ARG_PKG/saved_files"
- fi
- #################################################################
- # We now change the status to committed and remove the #
- # saved_files sub-directory. #
- #################################################################
- $print "committed" > /$TARP_DB/$ARG_PKG/status 2>/dev/null || {
- showscriptinfo;
- logerror "Unable to update package database - aborting" 7;
- }
- logmsg "Package $ARG_PKG successfully committed."
- exit 0
- fi
- #########################################################################
- # First step to install a package is to check to see if it is already #
- # installed and if so, make sure it is currently committed. #
- #########################################################################
- if [[ -z "$ARG_INBUNDLE" ]]
- then
- spec_dir=$ARG_PKG
- else
- spec_dir=$ARG_INBUNDLE.$ARG_PKG
- fi
- logmsg "Checking for $TARP_DB/$spec_dir"
- if [[ -d "$TARP_DB/$spec_dir" ]]
- then
- [[ -f "$TARP_DB/$spec_dir/status" ]] &&
- status="$(< $TARP_DB/$spec_dir/status)" ||
- status="Unknown";
- if [[ "$status" != "committed" ]]
- then
- showscriptinfo
- logerror "Package currently installed, but in state $status - not committed!" 8
- fi
- #################################################################
- # We need to get the version of the currently installed #
- # and ensure that the new version to install is greater, #
- # unless the force argument is specified. #
- #################################################################
- VERSION=$($awk -v FS=":" '/^VERSION:/ {print $2}' $TARP_DB/$spec_dir/spec)
- [[ -z "$VERSION" ]] && VERSION="0.0.0";
- #################################################################
- # Get 1 if the package to install is newer... #
- #################################################################
- isnewer=$($print "" | $awk -v IV="$VERSION" -v NV=$install_version '
- function cmpver(v1,v2,x1,x2) {
- split(v1,x1,/\./); split(v2,x2,/\./);
- if(x1[1]>x2[1]) return 1;
- if(x1[1]<x2[1]) return -1;
- if(x1[2]>x2[2]) return 1;
- if(x1[2]<x2[2]) return -1;
- if(x1[3]>x2[3]) return 1;
- if(x1[3]<x2[3]) return -1;
- return 0;
- }
- {print cmpver(NV,IV);exit;}')
- if [[ $isnewer -ne 1 && $ARG_FORCE -eq 0 ]]
- then
- showscriptinfo
- logwarn "Version selected for installation is not newer than currently installed version"
- exit 99
- fi
- typeset -u OVERWRITE
- OVERWRITE=$($awk -v FS=":" '/^OVERWRITE:/ {print $2}' $TARP_DB/$spec_dir/spec)
- [[ -z "$OVERWRITE" ]] && OVERWRITE="YES"
- if [[ "$OVERWRITE" = NO ]]
- then
- logerror "Package can not be overwritten - please remove old version first." 22
- fi
- fi
- #########################################################################
- # Ok, so the package is committed, and we have the correct version to #
- # install, so unpack the software in a temporary location. #
- #########################################################################
- TMPDIR="$TARP_DB/tpinstall-$$"
- mkdir -p $TMPDIR 2>/dev/null || {
- showscriptinfo;
- logerror "Unable to create temporary directory $TMPDIR" 23;
- }
- logmsg "Using temporary directory $TMPDIR"
- trap "cleanup $TMPDIR" 1 2 3 15 EXIT
- #########################################################################
- # Extract the spec file only first, to get the list of package #
- # dependencies. #
- #########################################################################
- cd $TMPDIR 2>/dev/null || {
- showscriptinfo;
- logerror "Unable to change to temporary directory to spool software!" 11;
- }
- #########################################################################
- # Indicate that the package is not yet installed, and also keep a #
- # install_list of files that should be removed if we back-out. #
- #########################################################################
- $print "broken" > status 2>/dev/null || {
- showscriptinfo;
- logerror "Unable to update package database - aborting" 7;
- }
- xcmd="$(print $ARG_DEPOT $install_file "./spec" | $awk '
- $2 ~ /.*\.tarp$/ {printf("tar xf %s/%s %s",$1,$2,$3);}
- $2 ~ /.*\.tarp\.gz$/ {printf("gunzip -c %s/%s | tar xf - %s",$1,$2,$3);}
- $2 ~ /.*\.tarp\.bz2$/ {printf("bunzip2 -c %s/%s | tar xf - %s",$1,$2,$3);}
- $2 ~ /.*\.tarp\.Z$/ {printf("zcat < %s/%s | tar xf - %s",$1,$2,$3);}')"
- eval "$xcmd >/dev/null 2>&1"
- rc=$?
- [[ $rc != 0 ]] && {
- showscriptinfo;
- logerror "An error occurred whilst extract .spec file - please check archive!" 66;
- }
- [[ ! -f spec ]] && {
- showscriptinfo;
- logerror "Invalid package file found - aborting!" 24;
- }
- #########################################################################
- # We get the list of dependencies, and call the dependency checker #
- # which will show information as follows: #
- # I:software,current,minver - Specified package is currently #
- # installed at level required. #
- # U:software,current,minver - Specified software is installed, but #
- # version is below minimum required. #
- # N:software,minver - New installation required, at least #
- # of the version specified. #
- # #
- # Dependency handling for bundles #
- # =============================== #
- # [1] If an a bundle then the dependency name strips off any bundle #
- # name and prefixes the current bundle name. #
- # #
- # This will change in a later release to ensure that dependencies #
- # for a package in a bundle can be found elsewhere (when depot #
- # searching is implemented). #
- # #
- #########################################################################
- deps=$($awk -v FS=: '/^DEPENDENCIES:/ {print $2}' spec)
- if [[ -n "$deps" ]]
- then
- logmsg "Checking package dependencies..."
- deps="$($print "$deps" | tr "|" " ")"
- TMPDIR2=$TMPDIR.2
- mkdir -p $TMPDIR2 || {
- showscriptinfo;
- logerror "Unable to make temporary directory $TMPDIR2" 25;
- }
- package_deps=""
- for cdep in $deps
- do
- cpkg=$($print "$cdep" | $awk -v FS=, '{print $1}')
- cver=$($print "$cdep" | $awk -v FS=, '{print $2}')
- if [[ ! -f "$TARP_DB/$cpkg/spec" ]]
- then
- package_deps="N $cpkg $cver\n$package_deps"
- else
- pcver=$($awk -v FS=: '/^VERSION:/ {print $2}' $TARP_DB/$cpkg/spec)
- isnewer=$($print "" | $awk -v IV="$cver" -v NV=$pcver '
- function cmpver(v1,v2,x1,x2) {
- split(v1,x1,/\./); split(v2,x2,/\./);
- if(x1[1]>x2[1]) return 1;
- if(x1[1]<x2[1]) return -1;
- if(x1[2]>x2[2]) return 1;
- if(x1[2]<x2[2]) return -1;
- if(x1[3]>x2[3]) return 1;
- if(x1[3]<x2[3]) return -1;
- return 0;
- }
- {print cmpver(NV,IV);exit;}')
- if [[ $isnewer -eq -1 ]]
- then
- package_deps="U $cpkg $pcver $cver\n$package_deps"
- else
- package_deps="I $cpkg $pcver $cver\n$package_deps"
- fi
- fi
- done
- rm -rf $TMPDIR2
- #################################################################
- # Foreach line that is not a I, then we get the package #
- # requirements for them (tail recursion...). #
- #################################################################
- tdeps=""
- $print "$package_deps" | while read ac ac_pkg v1 v2
- do
- [[ -z "$ac" ]] && continue
- [[ "$ac" = "I" ]] &&
- tdeps="$ac $ac_pkg $v1 $v2\n$tdeps" &&
- continue
- logmsg "Getting dependencies for $ac_pkg..."
- these="$($_PRG2 -i -d $ARG_DEPOT -p $ac_pkg -l 2>/dev/null)"
- RC=$?
- [[ $RC -ne 0 ]] &&
- tdeps="X $ac_pkg $v1 $v2\n$tdeps" &&
- continue
- these2="$($print "$these" | $awk 'NR>1')"
- v2="$($print "$these" | $awk 'NR==1 {print $2}')"
- logmsg "$ac $ac_pkg $v1 $v2"
- tdeps="$these2\n$ac $ac_pkg $v1 $v2\n$tdeps"
- done
- package_deps="$tdeps"
- else
- logmsg "No dependencies required for package."
- fi
- if [[ $ARG_LISTDEPS -eq 1 ]]
- then
- $print "$package_deps" | while read ac ac_pkg v1 v2
- do
- [[ -z "$ac" ]] && continue
- $print "$ac:$ac_pkg,$v1,$v2"
- done
- exit 0
- fi
- typeset -i dep_errors=0
- typeset -i dep_count=0
- had_deps=0
- install_list=""
- $print "$package_deps" | while read ac ac_pkg v1 v2
- do
- [[ -z "$ac" ]] && continue
- [[ $had_deps -eq 0 ]] && {
- [[ -n "$ARG_INBUNDLE" ]] &&
- logmsg "Package dependencies (via bundle $ARG_INBUNDLE):" ||
- logmsg "Package dependencies:" && had_deps=1;
- }
- logmsg " $ac_pkg"
- [[ "$ac" = "I" ]] &&
- logmsg " - already installed; $v1 >= $v2"
- [[ "$ac" = "U" ]] &&
- logmsg " + already installed, upgrade required; $v1 < $v2" &&
- let dep_count=dep_count+1 &&
- install_list="$install_list\n$ac_pkg $v2"
- if [[ "$ac" = "N" ]]
- then
- isnewer=$($print "" | $awk -v IV="$v2" -v NV=$v1 '
- function cmpver(v1,v2,x1,x2) {
- split(v1,x1,/\./); split(v2,x2,/\./);
- if(x1[1]>x2[1]) return 1;
- if(x1[1]<x2[1]) return -1;
- if(x1[2]>x2[2]) return 1;
- if(x1[2]<x2[2]) return -1;
- if(x1[3]>x2[3]) return 1;
- if(x1[3]<x2[3]) return -1;
- return 0;
- }
- {print cmpver(NV,IV);exit;}')
- if [[ $isnewer -ne 1 ]]
- then
- logmsg " + new install required; asked for $v1, depot version $v2"
- install_list="$install_list\n$ac_pkg $v2"
- let dep_count=dep_count+1
- else
- logmsg " ! new install required; asked for $v1, depot version $v2"
- let dep_errors=dep_errors+1
- fi
- fi
- [[ "$ac" = "X" ]] &&
- logmsg " ? install/upgraded required; $v2+ not in depot" &&
- let dep_errors=dep_errors+1
- done
- [[ $dep_errors -gt 0 && $ARG_NDEPS -eq 0 ]] && {
- showscriptinfo;
- [[ $dep_errors -gt 1 ]] &&
- logerror "$dep_errors missing dependencies, aborting" 30;
- [[ $dep_errors -eq 1 ]] &&
- logerror "$dep_errors missing dependency, aborting" 30;
- }
- [[ $dep_errors -gt 0 && $ARG_NDEPS -eq 1 ]] && {
- showscriptinfo;
- [[ $dep_errors -gt 1 ]] && logwarn "$dep_errors missing dependencies, aborting" 30;
- [[ $dep_errors -eq 1 ]] && logwarn "$dep_errors missing dependency, aborting" 30;
- }
- logmsg "Number of dependencies to install: $dep_count"
- if [[ $ARG_PREVIEW -eq 1 ]]
- then
- exit 0
- fi
- if [[ $dep_count -gt 0 ]]
- then
- if [[ $ARG_NODEPS -eq 1 ]]
- then
- logwarn "-x flag used, required dependencies will not be installed!"
- else
- $print "$install_list" | while read pkg ver
- do
- [[ -z "$pkg" ]] && continue
- logmsg "Installing dependency $pkg (version $ver):"
- logfile="/tmp/tpinstall-$$.$pkg"
- cmd="$_PRG2 -i -d $ARG_DEPOT -p $pkg -v -r $ARG_ROOTDIR"
-
- [[ $ARG_NOCOMMIT -eq 1 ]] && cmd="$cmd -n"
- [[ $ARG_NOPERMS -eq 1 ]] && cmd="$cmd -s"
- [[ -n "$ARG_INBUNDLE" ]] && cmd="$cmd -B $ARG_INBUNDLE"
- logmsg "$cmd"
- eval "$cmd >$logfile 2>&1"
- RC=$?
- [[ $RC -ne 0 ]] && {
- showscriptinfo;
- logerror "Unable to install dependency $pkg - see $logfile for details" 31;
- }
- logmsg "Package $pkg successfully installed (log=$logfile)"
- done
- fi
- fi
- xcmd="$(print $ARG_DEPOT $install_file "" | $awk '
- $2 ~ /.*\.tarp$/ {printf("tar xf %s/%s %s",$1,$2,$3);}
- $2 ~ /.*\.tarp\.gz$/ {printf("gunzip -c %s/%s | tar xf - %s",$1,$2,$3);}
- $2 ~ /.*\.tarp\.bz2$/ {printf("bunzip2 -c %s/%s | tar xf - %s",$1,$2,$3);}
- $2 ~ /.*\.tarp\.Z$/ {printf("zcat < %s/%s | tar xf - %s",$1,$2,$3);}')"
- logmsg "Beginning package extract to $TMPDIR..."
- eval $xcmd >/tmp/tpxcmd.$$ 2>&1
- if [[ $? -ne 0 ]]
- then
- cd -
- showscriptinfo
- logerror "Unable to extract files to temporary directory:"
- logerrorfile /tmp/tpxcmd.$$
- exit 13
- fi
- rm -f /tmp/tpxcmd.$$
- #########################################################################
- # If a checkinstall script is present then we execute it - and if #
- # we do not get a zero return code then the installation of the #
- # package is quietly ignored. #
- #########################################################################
- [[ -f ./checkinstall ]] && chmod +x ./checkinstall 2>/dev/null
- if [[ -x ./checkinstall ]]
- then
- ./checkinstall >/dev/null 2>&1
- r=$?
- [[ $r -gt 0 ]] &&
- logmsg "Checkinstall - package not suitable" &&
- exit 77
- fi
- logmsg "Package extraction completed successfully."
- mkdir saved_files 2>/dev/null || {
- showscriptinfo;
- logerror "Unable to create temporary directory to spool software!" 14;
- }
- $print "$ARG_ROOTDIR" >rootdir 2>/dev/null || {
- showscriptinfo;
- logerror "Unable to write new root directory file" 32;
- }
- #########################################################################
- # If we have a preinstall script then run it now, setting the #
- # PACKAGE and VERSION environment variables first. #
- #########################################################################
- export BUNDLE=$ARG_INBUNDLE
- export PACKAGE=$ARG_PKG
- export VERSION
- prelogoutput=/tmp/tpinstall-pre-$ARG_PKG-$$.stdout
- prelogerror=/tmp/tpinstall-pre-$ARG_PKG-$$.stderr
- [[ -f ./preinstall ]] && chmod +x ./preinstall 2>/dev/null
- if [[ -x ./preinstall ]]
- then
- logmsg "Running pre-install script..."
- ./preinstall >$prelogoutput 2>$prelogerror
- r=$?
- [[ $r -gt 2 ]] && {
- showscriptinfo;
- logerror "Return code $r from pre-install script - aborting" 20;
- }
- [[ $r -eq 1 ]] && {
- [[ $ARG_FORCE -eq 1 ]] &&
- logwarn "Return code 1 from pre-install script." || {
- showscriptinfo;
- logerror "Return code 1 from pre-install script." 21;
- }
- }
- [[ $r -eq 0 ]] && logmsg "Pre-install script completed successfully."
- fi
- #########################################################################
- # Now create backup copies of all files that will be over-written. #
- #########################################################################
- logmsg "Saving files that will be overwritten..."
- typeset -i saved_count=0
- typeset -i saved_size=0
- xcmd="$(print $ARG_DEPOT $install_file "" | $awk '
- $2 ~ /.*\.tarp$/ {printf("tar tf %s/%s %s",$1,$2,$3);}
- $2 ~ /.*\.tarp\.gz$/ {printf("gunzip -c %s/%s | tar tf - %s",$1,$2,$3);}
- $2 ~ /.*\.tarp\.bz2$/ {printf("bunzip2 -c %s/%s | tar tf - %s",$1,$2,$3);}
- $2 ~ /.*\.tarp\.Z$/ {printf("zcat < %s/%s | tar tf - %s",$1,$2,$3);}')"
- #################################################################
- # Before doing anything really - double check the contents of #
- # the archive and abort if necessary. #
- #################################################################
- eval "$xcmd 2>/dev/null >/dev/null"
- rc=$?
- [[ $rc != 0 ]] && {
- showscriptinfo;
- logerror "An error occurred whilst scanning package contents - please check archive!" 66;
- }
- for fp in $(eval "$xcmd 2>/dev/null" |
- egrep -v '\./spec|\./postinstall|\./preinstall|\./checkinstall|\.preremove|\./postremove|\./postinstall\.perms' | $awk 'substr($0,length($0)) != "/" {print substr($0,2);}')
- do
- if [[ -f "$ARG_ROOTDIR$fp" ]]
- then
- (cd $ARG_ROOTDIR && tar cpf - .$fp 2>/dev/null ) |
- (cd saved_files && tar xpf - 2>/dev/null ) || {
- showscriptinfo;
- logerror "Out of space or permissions error whilst storing backup files" 15;
- }
- let saved_count=saved_count+1
- fi
- done
- if [[ $saved_count -gt 0 ]]
- then
- saved_size=$(du -sk saved_files | $awk '{print $1}')
- logmsg "Files Saved: $saved_count ($saved_size Kb)"
- else
- logmsg "No files required saving."
- fi
- #########################################################################
- # Now we actually move the real files into place, creating a cksums #
- # file once the files have been installed. #
- #########################################################################
- typeset -i installed_count=0
- typeset -i installed_size=0
- logmsg "Installing package files..."
- #########################################################################
- # Now we are about to overwrite files, we add a re-install call #
- # as part of the trap command. #
- #########################################################################
- $print "broken2" > status 2>/dev/null || {
- showscriptinfo;
- logerror "Unable to update package database - aborting" 7;
- }
- trap "cleanup $TMPDIR; logmsg 'Cleaning up directory $TMPDIR'; rm -rf $TMPDIR" EXIT
- cd $TMPDIR 2>/dev/null || logerror "Unable to change to spool directory" 33
- volatile_ext=$($awk -v FS=: '$1 == "VOLATILE_EXT" {gsub(/,/," ",$2); print $2}' spec)
- if [[ -n "$volatile_ext" ]]
- then
- logmsg "Volatile file extensions defined as : $volatile_ext"
- fi
- find . \( -name saved_files -prune \) -o \( -type f -print \) | egrep -v '\./spec|\./postinstall|\./preinstall|\./checkinstall|\.preremove|\./postremove|\./postinstall\.perms|\./rootdir|\./status' >/tmp/tpinstall-$$.2
- #########################################################################
- # Always copy files rather than use cpio now, since more compatible #
- # across different server types. #
- #########################################################################
- for f1 in $(cat /tmp/tpinstall-$$.2)
- do
- [[ ! -d $(basename $ARG_ROOTDIR/$f1) ]] && {
- mkdir -p $(dirname $ARG_ROOTDIR/$f1) || {
- logerror "Unable to perform the following operation:"
- logerror "mkdir -p $(dirname $ARG_ROOTDIR/$f1)"
- rm -f /tmp/tpinstall-$$.2 /tmp/tpinstall-$$
- exit 21;
- }
- }
- cp -f $f1 $ARG_ROOTDIR/$f1 2>>/tmp/tpinstall-$$ || {
- showscriptinfo
- logerror "Error occured whilst attempting to install $ARG_PKG"
- logerror "Unable to perform the following operation:"
- logerror "cp -f $f1 $ARG_ROOTDIR/$f1"
- rm -f /tmp/tpinstall-$$.2 /tmp/tpinstall-$$
- exit 16;
- }
- done
- c1=$(wc -l < /tmp/tpinstall-$$)
- c2=$(wc -l < /tmp/tpinstall-$$.2)
- installed_count=$(($c2 - $c1))
- rm -f /tmp/tpinstall-$$
- mv /tmp/tpinstall-$$.2 /tmp/tpinstall-$$
-
- [[ "$OS" = "Linux" ]] && cksum=md5sum || cksum=cksum
- for cfile in $(grep -vi blocks /tmp/tpinstall-$$)
- do
- if [[ -n "$volatile_ext" ]]
- then
- this_ext=${cfile##*.}
- if [[ "$this_ext" != "$cfile" ]]
- then
- found=0
- for cext in $volatile_ext
- do
- [[ "$cext" = "$this_ext" ]] && {
- $print "$cfile|V" >>cksums;
- found=1;
- break;
- }
- done
- [[ $found -eq 1 ]] && continue
- fi
- fi
- mc=$($cksum $cfile|$awk '{print $1}')
- $print "$cfile|$mc" >>cksums
- done
- [[ -f /tmp/tpinstall-$$ ]] && rm -f /tmp/tpinstall-$$
- logmsg "Files installed: $installed_count"
- #########################################################################
- # Now the files have been installed, and so we create the status #
- # file and remove an older copy of this package, if it exists, and #
- # finally rename this directory. #
- #########################################################################
- $print "installed" >status 2>/dev/null || {
- showscriptinfo;
- logerror "Unable go write to status file!";
- logerror "Command attempted: $print installed >$PWD/status" 17;
- }
- [[ -d $TARP_DB/$spec_dir ]] && {
- mv $TARP_DB/$spec_dir $TARP_DB/$spec_dir.tmp || {
- showscriptinfo;
- logerror "Unable to rename old package status directory";
- logerror "Command attempted: mv $TARP_DB/$spec_dir $TARP_DB/$spec_dir.tmp" 18;
- }
- }
- mv -f $TMPDIR $TARP_DB/$spec_dir
- [[ ! -d $TARP_DB/$spec_dir ]] && {
- showscriptinfo;
- logerror "Unable to rename temporary status directory" 19;
- }
- #########################################################################
- # If we have a postinstall script then run it now, setting the #
- # PACKAGE and VERSION environment variables first. #
- #########################################################################
- export PACKAGE=$ARG_PKG
- export VERSION
- cd $TARP_DB/$spec_dir
- if [[ $ARG_NOPERMS -eq 1 ]]
- then
- logwarn "Not setting package permissions."
- else
- [[ -f ./postinstall.perms ]] && chmod +x ./postinstall.perms 2>/dev/null
- if [[ -x ./postinstall.perms ]]
- then
- logmsg "Setting Correct package permissions + ownerships..."
- if [[ "$(id | $awk -v FS="[()]+" '{print $2}')" != root ]]
- then
- logwarn "Not changing owner/group info - not running as root."
- cd $ARG_ROOTDIR &&
- sed 's/chown.*//g' < $TARP_DB/$spec_dir/postinstall.perms | /bin/sh 2>/tmp/tpinstall-$$.3 2>&1
- else
- cd $ARG_ROOTDIR &&
- $TARP_DB/$spec_dir/postinstall.perms 2>/tmp/tpinstall-$$.3 2>&1
- fi
- #################################################################
- # Issue a warning if we've any output from attempting to set #
- # the permissions. #
- #################################################################
- if [[ -s /tmp/tpinstall-$$.3 ]]
- then
- logwarn "The following errors occured whilst setting permissions:"
- logwarnfile /tmp/tpinstall-$$.3
- fi
- rm -f /tmp/tpinstall-$$.3
- fi
- fi
- [[ -f ./postinstall ]] && chmod +x ./postinstall 2>/dev/null
- postlogoutput=/tmp/tpinstall-post-$ARG_PKG-$$.stdout
- postlogerror=/tmp/tpinstall-post-$ARG_PKG-$$.stderr
- cd $TARP_DB/$spec_dir
- if [[ -x ./postinstall ]]
- then
- logmsg "Running post-install script..."
- ./postinstall >$postlogoutput 2>$postlogerror
- r=$?
- [[ $r -gt 0 ]] && {
- logwarn "Return code $r from post-install script.";
- }
- logmsg "Post-install script completed successfully."
- fi
- #########################################################################
- # Now we remove everything from the directory that we do not expect #
- # to need. #
- #########################################################################
- logmsg "Removing spooled package files..."
- cd $TARP_DB/$spec_dir || {
- showscriptinfo;
- logerror "Unable to change to spool directory" 33;
- }
- for cfile in $(ls 2>/dev/null)
- do
- [[ "$x" = "." || "$x" = ".." ]] && continue
- [[ "$x" = "preinstall" || "$x" = "postinstall" ]] && continue
- [[ "$x" = "preremove" || "$x" = "postremove" ]] && continue
- [[ "$x" = "saved_files" || "$x" = "cksums" ]] && continue
- [[ "$x" = "spec" || "$x" = "status" ]] && continue
- [[ "$x" = "checkinstall" ]] && continue
- [[ "$x" = "postinstall.perms" || "$x" = "rootdir" ]] && continue
- rm -rf $x 2>/dev/null
- done
- #########################################################################
- # Indicate the package is installed, but not currently commited. #
- #########################################################################
- $print "installed" > /$TARP_DB/$spec_dir/status 2>/dev/null || {
- showscriptinfo
- logerror "Unable to update package database - aborting" 7;
- }
- logmsg "Package $ARG_PKG installed successfully."
- #########################################################################
- # We if have installed from a bundle then we copy across the #
- # bundle information to a directory BUNDLE:name and in the name we #
- # currently copy across the spec file contents... #
- #########################################################################
- if [[ -n "$ARG_INBUNDLE" ]]
- then
- if [[ ! -f "$ARG_DEPOT/spec" ]]
- then
- logwarn "Unable to copy bundle files - no bundle information"
- logwarn "will be included, though packages will be installed."
- else
- mkdir "$TARP_DB/BUNDLE:$ARG_INBUNDLE" 2>/dev/null
- cp -f $ARG_DEPOT/spec "$TARP_DB/BUNDLE:$ARG_INBUNDLE/spec" 2>/dev/null || {
- logwarn "Unable to copy bundle files - no bundle information";
- logwarn "will be included, though packages will be installed.";
- }
- fi
- fi
- [[ $ARG_NOCOMMIT -eq 1 ]] && {
- showscriptinfo; exit 0;
- }
- #########################################################################
- # Now removed the saved_files sub-directory if it exists. #
- #########################################################################
- if [[ -d "$TARP_DB/$spec_dir/saved_files" ]]
- then
- rm -rf "$TARP_DB/$spec_dir/saved_files"
- fi
- #################################################################
- # We now change the status to committed and remove the #
- # saved_files sub-directory. #
- #################################################################
- $print "committed" > /$TARP_DB/$spec_dir/status 2>/dev/null || {
- showscriptinfo;
- logerror "Unable to update package database - aborting" 7;
- }
- showscriptinfo;
- logmsg "Package $ARG_PKG successfully committed."
- exit 0