postrun revision 12025
12373N/A#!/bin/ksh
12373N/A#
12373N/A# Script for starting a postponed post-installation command in
12586N/A# a Live-Upgrade-safe environment
12586N/A#
12586N/A# CDDL HEADER START
12373N/A#
15170N/A# The contents of this file are subject to the terms of the
12586N/A# Common Development and Distribution License, Version 1.0 only
12586N/A# (the "License"). You may not use this file except in compliance
15153N/A# with the License.
12373N/A#
12373N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
12373N/A# or http://www.opensolaris.org/os/licensing.
14471N/A# See the License for the specific language governing permissions
12373N/A# and limitations under the License.
12373N/A#
12373N/A# When distributing Covered Code, include this CDDL HEADER in each
12373N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
14471N/A# If applicable, add the following below this CDDL HEADER, with the
12773N/A# fields enclosed by brackets "[]" replaced with your own identifying
13320N/A# information: Portions Copyright [yyyy] [name of copyright owner]
15153N/A#
12773N/A# CDDL HEADER END
13062N/A#
13091N/A#
13350N/A# Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
13350N/A# Use is subject to license terms.
13062N/A#
13091N/A
13350N/Aexport PATH=/usr/bin
13350N/ALC_ALL=C
13350N/Aexport LC_ALL
13350N/AMYDIR=$(cd $(dirname $0); pwd)
13091N/ASPOOLDIR="$MYDIR/../../spool/postrun"
13001N/ALOCKFILE="/var/run/postrun.lock"
13062N/ALOGFILE="$MYDIR/../../log/postrun.log"
12374N/ASEQFILE="$SPOOLDIR/.seq"
14413N/A
14345N/Aid | grep " euid=" && \
14275N/A myuid=`id | sed -e 's/.* euid=\([0-9][0-9]*\).*$/\1/'` || \
14275N/A myuid=`id | sed -e 's/uid=\([0-9][0-9]*\).*/\1/'`
14413N/A
14413N/Aif [ "$myuid" != 0 ]; then
15220N/A echo "postrun: error: run this script as root"
15213N/A exit 1
12373N/Afi
12373N/A
12373N/Aumask 0133
12373N/A
12373N/Ausage() {
12373N/A echo 'Usage: postrun [options]'
12373N/A echo
12373N/A echo 'Options:'
12373N/A echo ' -u, --uniq'
12373N/A echo ' If the same command is requested multiple times, the command'
12373N/A echo ' is only run once. If it is safe to execute the command'
12373N/A echo ' immediately, it will be delayed by 5 minutes, or as set'
12373N/A echo ' using the --timeout option'
12373N/A echo
12373N/A echo ' -t <n>, --timeout <n>'
12373N/A echo ' Delay the execution of uniq commands by <n> minutes.'
12373N/A echo
12373N/A echo ' -b, --bg'
12373N/A echo ' Run the command in the background and return control'
12373N/A echo ' immediately'
12373N/A echo
12373N/A echo ' -f <file>'
12373N/A echo ' Read the commands from <file> instead of the standard'
12373N/A echo ' input.'
12373N/A echo
12373N/A echo ' -c <class>'
12373N/A echo ' Assign this job to class <class>. Useful for querying'
12373N/A echo ' jobs with postrun-query'
12373N/A echo
12373N/A echo ' -i'
12373N/A echo ' Ignore this job if it cannot be executed immediately.'
12373N/A echo
12373N/A echo ' -h, -?, --help'
12373N/A echo ' Display this help'
12373N/A exit 1
12373N/A}
12373N/A
12373N/A# Solaris 9 doesn't have mktemp, need a substitute in order to be
12373N/A# Live Upgrade compliant
12373N/A# Note: only creating tmp files is implemented, directories are not
12373N/Apostrun_mktemp () {
12373N/A test -x /usr/bin/mktemp && {
12373N/A /usr/bin/mktemp $1
12373N/A return
12373N/A }
12373N/A tempname="$1.$$.`date +%H%M%S`"
12373N/A while [ -f $tempname ]; do
12373N/A tempname="$tempname.`date +%S`"
12373N/A done
12373N/A touch $tempname && chmod 700 $tempname || exit 1
12373N/A echo $tempname
12373N/A}
15153N/A
15153N/A#LOCK_UNLOCK_FUNCTIONS_START
15153N/Apostrun_debug() {
15153N/A if [ "x$POSTRUN_DEBUG" = xyes ]; then
15153N/A for msg in "${@}"; do
12373N/A echo '<POSTRUN_DEBUG>' "[$$]" "$msg" 1>&2
12374N/A done
13320N/A fi
13810N/A}
13320N/A
12373N/Ais_number() {
12373N/A echo "$1" | egrep -vs '^[0-9]+$' && return 1
14345N/A echo "$1" | egrep -s '^[0-9]+$' || return 1
14021N/A return 0
14413N/A}
15213N/A
12373N/A# lock the postrun spool or log file
12373N/A# if $1 is 'log' then lock the log file, otherwise log the spool
12373N/Apostrun_lock() {
12373N/A typeset this_lock=$LOCKFILE
12373N/A if [ "x$1" = xlog ]; then
12373N/A this_lock=${LOCKFILE}.log
12373N/A fi
12373N/A postrun_debug "Taking lock on $this_lock"
12373N/A
12373N/A while true ; do
12373N/A # Try to take the lock
12373N/A ln -s $$ $this_lock 2>/dev/null
12373N/A if [ $? = 0 ] ; then
12420N/A postrun_debug "Lock on $this_lock taken"
12420N/A return
13307N/A fi
13307N/A
12773N/A # Read who has the lock. If this process has the lock return
12773N/A typeset pid=$(ls -ld $this_lock \
12773N/A | nawk -F' -> ' '$1 ~ /^l/ && NF == 2 { print $NF }')
12773N/A if [ "$pid" = $$ ] ; then
12773N/A postrun_debug "Lock on $this_lock already held by this pid ($$)"
12373N/A return
13307N/A fi
12373N/A
12373N/A # check to be sure the process that holds the lock is still running
12783N/A # if so, wait for it to be freed. If the lock is stale, remove it
12373N/A # so that the next iteration of the loop can take the lock.
12373N/A if is_number "$pid" && kill -0 "$pid" 2>/dev/null ; then
12373N/A postrun_debug "Waiting for $pid to release $this_lock"
12373N/A sleep 1
12422N/A else
12422N/A postrun_debug "Stale lock $this_lock from $pid being released"
12373N/A rm -f $this_lock
12373N/A fi
12373N/A done
12373N/A postrun_debug "postrun_lock escaped the loop - should not b here"
12373N/A
13085N/A}
13085N/A
12373N/A# release the lock
12373N/A# unlock the log file if $1 == 'log', unlock the spool otherwise
12373N/Apostrun_unlock() {
12373N/A typeset this_lock=$LOCKFILE
12373N/A if [ "x$1" = xlog ]; then
12373N/A this_lock=${LOCKFILE}.log
12373N/A fi
12373N/A postrun_debug "Releasing lock on $this_lock"
12373N/A
12373N/A typeset pid=$(ls -ld $this_lock \
12373N/A | nawk -F' -> ' '$1 ~ /^l/ && NF == 2 { print $NF }')
12373N/A
12373N/A if ! rm -f $this_lock; then
12373N/A echo "postrun: error: cannot remove lock file $this_lock" 1>&2
12373N/A exit 1
12373N/A fi
12373N/A postrun_debug "Released lock on $this_lock taken by pid $pid"
12373N/A}
12373N/A#LOCK_UNLOCK_FUNCTIONS_END
12373N/A
12373N/A# get the next job id
12373N/Apostrun_get_seq() {
12373N/A postrun_lock
12373N/A seq=`cat $SEQFILE 2>/dev/null`
12373N/A next_seq=$(($seq + 1))
12373N/A echo $next_seq > $SEQFILE
15220N/A postrun_unlock
15220N/A echo $next_seq
15213N/A}
15213N/A
15153N/Apostrun_spool_command() {
15153N/A if [ $postrun_no_spool = yes ]; then
14471N/A postrun_debug "Ignoring job, because -i was used and it's not possible to run it now"
14471N/A return 1
14413N/A fi
14413N/A cd $SPOOLDIR
14413N/A # check if there's already a spooled job for the same command
14345N/A new_job=0
14345N/A uniq_job_nr=
14275N/A job_seq=`postrun_get_seq`
14275N/A IFS=' '
14275N/A postrun_lock
14093N/A for f in *.cmd; do
14093N/A test -f "$f" || continue
14093N/A cmp -s $postrun_command_file $f && {
14093N/A if [ $postrun_is_uniq = yes ]; then
13810N/A uniq_job_nr=`basename $f .cmd`
13810N/A break
13810N/A fi
13810N/A egrep -s '^uniq_command: yes' `basename $f .cmd`.ctrl && {
13810N/A uniq_job_nr=`basename $f .cmd`
13794N/A break
13794N/A }
13493N/A }
13493N/A done
13493N/A if [ "x$uniq_job_nr" != x ]; then
13350N/A postrun_debug "matching spooled uniq job (#${uniq_job_nr}) found"
13350N/A # we found a matching spooled uniq job
13320N/A # we need to update the uniq time and make sure it's
13320N/A # flagged as a uniq job
13320N/A
13320N/A new_job=1
13307N/A
13320N/A #
13320N/A # FIXME: shouldn't use sed for this, safer to simply append
13320N/A # and process the duplicate entries when reading the file
13307N/A #
13307N/A sed -e 's/^uniq_command: .*/uniq_command: yes/' \
13085N/A -e 's/^\(pkginst: .*\)/\1, '$PKGINST'/' \
13085N/A -e 's/^uniq_time: /resubmit_time: /' \
13085N/A -e 's/^uniq_timeout: .*/uniq_timeout: '"$postrun_uniq_timeout"'/' \
13062N/A $uniq_job_nr.ctrl > $uniq_job_nr.ctrl.new
13062N/A echo 'uniq_time: '`date +%Y.%m.%d.%H.%M.%S` >> $uniq_job_nr.ctrl.new
13062N/A grep "^class: $postrun_job_class$" $uniq_job_nr.ctrl.new \
13001N/A >/dev/null || \
13001N/A echo "class: $postrun_job_class" >> $uniq_job_nr.ctrl.new
12783N/A #
12783N/A # FIXME: add the user name to the control file
12783N/A #
12783N/A
12783N/A # Use a new job id so that the job moves to the end of the queue.
12704N/A # Need to do this such a whay that if this process is interrupted at
12704N/A # any stage, the job is not lost and is not in the queue twice:
12704N/A
12666N/A # Step 1: copy the job to the new id:
12666N/A cp $uniq_job_nr.cmd $job_seq.cmd
12666N/A
12666N/A # Step 2: move the original job ctrl file to the new id:
12611N/A mv $uniq_job_nr.ctrl $job_seq.ctrl
12611N/A
12611N/A # Step 3: replace the original job ctrl file with the updated one:
12586N/A mv $uniq_job_nr.ctrl.new $job_seq.ctrl
12586N/A
12514N/A # Step 4: delete the original cmd file
12514N/A rm -f $uniq_job_nr.cmd
12420N/A else
12420N/A postrun_debug "spooling command as job #${job_seq}"
12422N/A user_name=${EMAIL:-root}
12400N/A ctrl_file="$SPOOLDIR/$job_seq.ctrl"
12400N/A cmd_file="$SPOOLDIR/$job_seq.cmd"
12400N/A cat $postrun_command_file > $cmd_file
12400N/A cat /dev/null > $ctrl_file
12400N/A echo "pkginst: $PKGINST" >> $ctrl_file
12400N/A echo "submit_time: `date +%Y.%m.%d.%H.%M.%S`" >> $ctrl_file
12400N/A echo "uniq_command: $postrun_is_uniq" >> $ctrl_file
12400N/A echo "uniq_time: `date +%Y.%m.%d.%H.%M.%S`" >> $ctrl_file
12374N/A echo "uniq_timeout: $postrun_uniq_timeout" >> $ctrl_file
12374N/A echo "background: $postrun_bg_job" >> $ctrl_file
12374N/A echo "user: $user_name" >> $ctrl_file
12374N/A echo "class: $postrun_job_class" >> $ctrl_file
12374N/A fi
12373N/A postrun_unlock
12373N/A
12373N/A return $new_job
12373N/A}
12373N/A
12373N/Apostrun_run_command() {
12373N/A cmdout=`mktemp /tmp/postrun.out.XXXX`
12373N/A # create a background jobs script that executes the commands
12373N/A # then locks the spool/log file and appends the output to the
12373N/A # log file and finally unlocks
12373N/A cmdfile=`mktemp /tmp/postrun.job.XXXX`
12373N/A cat /dev/null > $cmdfile
12373N/A cat /dev/null > $cmdout
12373N/A echo '#!/bin/ksh' >> $cmdfile
12373N/A # copy the postrun_lock and postrun_unlock commands from
12373N/A # this script to the background job script
12373N/A echo "LOCKFILE=$LOCKFILE" >> $cmdfile
12373N/A sed -e '1,/#LOCK_UNLOCK_FUNCTIONS_START/d' \
12373N/A -e '/#LOCK_UNLOCK_FUNCTIONS_END/,$d' $0 >> $cmdfile
12373N/A # save the stdout file description
12373N/A echo 'exec 3<&1' >> $cmdfile
12373N/A echo "exec >> $cmdout 2>&1" >> $cmdfile
12373N/A echo 'PATH=/usr/bin; export PATH' >> $cmdfile
12373N/A echo 'echo Starting postrun job at `LC_ALL=C date`' >> $cmdfile
12373N/A if [ "x$postrun_submit_time" != x ]; then
12373N/A if [ $postrun_bg_job = yes ]; then
12373N/A echo "echo 'This is a spooled background job (#${postrun_job_number})'" >> $cmdfile
12373N/A else
12373N/A echo "echo 'This is a spooled foreground job (#${postrun_job_number})'" >> $cmdfile
12373N/A fi
12373N/A echo "echo Job submitted by $postrun_pkginst at $postrun_submit_time" \
12373N/A >> $cmdfile
12373N/A else
12373N/A if [ $postrun_bg_job = yes ]; then
12373N/A echo 'echo This is an immediate background job' >> $cmdfile
12373N/A else
12373N/A echo 'echo This is an immediate foreground job' >> $cmdfile
12373N/A fi
12373N/A echo "echo Job submitted by $postrun_pkginst"\
12373N/A >> $cmdfile
12373N/A fi
12373N/A echo 'echo Running commands:' >> $cmdfile
12373N/A echo "echo '>>>' commands follow:" >> $cmdfile
12373N/A cat $postrun_command_file | \
12373N/A sed -e "s/'/'\"'\"'/g" | \
12373N/A sed -e "s/^/echo '/" \
12373N/A -e "s/\$/'/" >> $cmdfile
12373N/A echo "echo '<<<' commands end" >> $cmdfile
12373N/A echo "echo '>>>' Command output follows:" >> $cmdfile
12373N/A echo "chmod 700 $postrun_command_file" >> $cmdfile
12373N/A echo "$postrun_command_file" >> $cmdfile
12373N/A
12373N/A #
12373N/A # FIXME: send email to $postrun_user if the command failed
12373N/A #
12373N/A
12373N/A echo "echo '<<<' Command completed with exit status \$?" \
12373N/A >> $cmdfile
12373N/A echo 'echo Job finished at `LC_ALL=C date`' >> $cmdfile
12373N/A echo 'echo --' >> $cmdfile
12373N/A # restore PATH in case the command changed it
12373N/A echo 'PATH=/usr/bin; export PATH' >> $cmdfile
12373N/A # restore stdout
12373N/A echo 'exec 1<&3' >> $cmdfile
12373N/A # close file descriptor 3
12373N/A echo 'exec 3<&-' >> $cmdfile
12373N/A echo 'exec 2>&1' >> $cmdfile
12373N/A # append the messages to the real log file
12373N/A # need to lock the log file to avoid 2 postrun commands
12373N/A # writing at the same time and messing up the log
12373N/A echo 'postrun_lock log' >> $cmdfile
echo "cat $cmdout >> $LOGFILE" >> $cmdfile
echo 'postrun_unlock log' >> $cmdfile
echo "rm -f $cmdout" >> $cmdfile
echo "rm -f $cmdfile" >> $cmdfile
echo "rm -f $postrun_command_file" >> $cmdfile
chmod 700 $cmdfile
if [ $postrun_bg_job = yes ]; then
$cmdfile &
else
$cmdfile
fi
exitval=$?
}
username=${EMAIL:-root}
postrun_defaults() {
# default settings
postrun_pkginst="$PKGINST"
postrun_submit_time=''
postrun_uniq_time=''
postrun_is_uniq=no
postrun_uniq_timeout=5
postrun_bg_job=no
postrun_command_file=''
postrun_user=${username}
postrun_job_number='???'
postrun_alt_root_okay=no
postrun_job_class=other
postrun_no_spool=no
}
# usage: is_leap_year yyyy
is_leap_year() {
cal 02 $1 | egrep -s 29 && return 0
return 1
}
# get_abstime yy mm dd hh mm ss
#
# prints the elapsed time in seconds since 1970.01.01.00.00.00
#Length of the months:
# JA FE MA AP MY JN JL AU SE OC NO DE
set -A MONTH 0 31 28 31 30 31 30 31 31 30 31 30 31
get_abstime() {
# the absolute time since 1970...
t=0
# number of years
t=$(($t + ($1 - 1970) * 31536000))
# add 1 day for each leap year
y=1972
end_y=$1
if [ $2 -lt 2 ]; then
end_y=$(($1 - 1))
fi
while [ $y -le $end_y ]; do
is_leap_year $y && t=$(($t + 86400))
y=$(($y + 4))
done
# number of months
m=1
while [ $m -lt $2 ]; do
t=$(($t + ${MONTH[$m]} * 86400))
m=$(($m + 1))
done
# number of days, hours, minutes and seconds:
echo $(($t + ($3 - 1) * 86400 + $4 * 3600 + $5 * 60 + $6))
}
# get_timediff: prints the difference in seconds between 2 time strings
# the time strings should be of the following format:
# YYYY.MM.DD.HH.MM.SS as printed by date +%Y.%m.%d.%H.%M.%S
#
# Works for dates after 1970.01.01.00.00.00
#
get_timediff() {
year1=$(expr "$1" : "^\([^.]*\)\..*")
month1=$(expr "$1" : "^[^.]*\.\([^.]*\)\..*")
day1=$(expr "$1" : "^[^.]*\.[^.]*\.\([^.]*\)\..*")
hour1=$(expr "$1" : "^[^.]*\.[^.]*\.[^.]*\.\([^.]*\)\..*")
min1=$(expr "$1" : "^[^.]*\.[^.]*\.[^.]*\.[^.]*\.\([^.]*\)\..*")
sec1=$(expr "$1" : "^[^.]*\.[^.]*\.[^.]*\.[^.]*\.[^.]*\.\([^.]*\)")
year2=$(expr "$2" : "^\([^.]*\)\..*")
month2=$(expr "$2" : "^[^.]*\.\([^.]*\)\..*")
day2=$(expr "$2" : "^[^.]*\.[^.]*\.\([^.]*\)\..*")
hour2=$(expr "$2" : "^[^.]*\.[^.]*\.[^.]*\.\([^.]*\)\..*")
min2=$(expr "$2" : "^[^.]*\.[^.]*\.[^.]*\.[^.]*\.\([^.]*\)\..*")
sec2=$(expr "$2" : "^[^.]*\.[^.]*\.[^.]*\.[^.]*\.[^.]*\.\([^.]*\)")
# calculate seconds since 1970.01.01.00.00.00
t1=`get_abstime $year1 $month1 $day1 $hour1 $min1 $sec1`
t2=`get_abstime $year2 $month2 $day2 $hour2 $min2 $sec2`
# print difference
expr $t1 - $t2
}
postrun_runq() {
cd $SPOOLDIR
IFS='
'
timeleft=0
postrun_lock
all_jobs=`/bin/ls -1 *.ctrl | /bin/sort -n`
for job in $all_jobs; do
test -f "$job" || continue
postrun_defaults
while read var val; do
case "$var" in
pkginst: )
postrun_pkginst="$val"
;;
submit_time: )
postrun_submit_time="$val"
;;
resubmit_time: )
;;
uniq_command: )
postrun_is_uniq="$val"
;;
uniq_time: )
postrun_uniq_time="$val"
;;
uniq_timeout: )
postrun_uniq_timeout="$val"
;;
background: )
postrun_bg_job="$val"
;;
user: )
postrun_user="$val"
;;
class: )
postrun_job_class="$val"
;;
* )
echo "postrun: WARNING: invalid setting in $job: $var"
;;
esac
done < $job
postrun_command_file=$SPOOLDIR/`basename $job .ctrl`.cmd
postrun_job_number=`basename $job .ctrl`
if [ $postrun_ignore_timeout = no ]; then
# if it's a uniq job, check if it timed out
if [ "x$postrun_is_uniq" = xyes ]; then
# calculate time difference (seconds)
tdiff=$(get_timediff $(date +%Y.%m.%d.%H.%M.%S) \
$postrun_uniq_time)
timeout_sec=$((postrun_uniq_timeout * 60))
if [ $tdiff -ge $timeout_sec ]; then
postrun_run_command
rm -f $job
else
# try again in at least $tdiff sec time
tl=$(($tdiff / 60 + 1))
if [ $tl -gt $timeleft ]; then
timeleft=$tl
fi
fi
else
postrun_run_command
rm -f $job
fi
else
# ignore timeout, just run the job
postrun_run_command
rm -f $job
fi
done
if [ $timeleft -gt 0 ]; then
echo "$MYDIR/postrun -q" |
at now "+${timeleft}minutes" \
> /dev/null 2>&1
fi
postrun_unlock
exit 0
}
postrun_defaults
exitval=0
postrun_ignore_timeout=no
if [ $# = 1 -a "x$1" = 'x-qf' ]; then
# postrun-runq mode (ignore timeout for uniq jobs, since this is
# expected to be run at system boot)
postrun_ignore_timeout=yes
postrun_runq
exit 1
fi
if [ $# = 1 -a "x$1" = 'x-q' ]; then
# postrun-runq mode, to be run from at(1)
postrun_runq
exit 1
fi
# process the command line
while [ $# -gt 0 ]; do
case "$1" in
-h|-\?|--help)
usage
;;
-u|--uniq)
postrun_is_uniq=yes
;;
-b|--bg)
postrun_bg_job=yes
;;
-t|--timeout)
opt="$1"
if [ $# == 0 ]; then
echo "postrun: error: argument expected after $opt"
exit 1
fi
shift
timeout=$1
if ! is_number "$timeout"; then
echo "postrun: error: interger number expected after $opt (found \"$timeout\")"
exit 1
fi
postrun_uniq_timeout=$timeout
;;
-i|--ignore)
postrun_no_spool=yes
;;
-f)
opt="$1"
if [ $# == 0 ]; then
echo "postrun: error: argument expected after $opt"
exit 1
fi
shift
postrun_command_file="$1"
;;
-c)
opt="$1"
if [ $# == 0 ]; then
echo "postrun: error: argument expected after $opt"
exit 1
fi
shift
postrun_job_class="$1"
;;
-a)
postrun_alt_root_okay=yes
;;
--)
break
;;
*)
echo "postrun: error: invalid argument: $1"
exit 1
;;
esac
shift
done
check_alt_root_okay () {
if [ "x$PKG_INSTALL_ROOT" = x -o "x$PKG_INSTALL_ROOT" = x/ \
-o "x$postrun_alt_root_okay" = xno ]; then
return 1
fi
# need to verify if the architecture and Solaris minor version
# of / is equal to that of $PKG_INSTALL_ROOT, otherwise
# running the script is not okay
pkginfo -q SUNWsolnm || return 1
this_solnm_pkginfo="`pkginfo -R / -l SUNWsolnm 2>/dev/null`"
alt_root_solnm_pkginfo="`pkginfo -R $PKG_INSTALL_ROOT -l SUNWsolnm 2>/dev/null`"
this_sol_minor=`echo "$this_solnm_pkginfo" |grep VERSION| sed -e 's/^.*VERSION: *\([0-9]*\),REV=.*/\1/'`
alt_root_sol_minor=`echo "$alt_root_solnm_pkginfo" |grep VERSION| sed -e 's/^.*VERSION: *\([0-9]*\),REV=.*/\1/'`
if [ "x$this_sol_minor" != "x$alt_root_sol_minor" ]; then
postrun_debug "/ is Solaris $this_sol_minor, $PKG_INSTALL_ROOT is Solaris $alt_root_sol_minor"
return 1
fi
this_sol_arch=`echo "$this_solnm_pkginfo" |grep ARCH|sed -e 's/^.*ARCH: *\([a-z0-9]*\).*/\1/'`
alt_root_sol_arch=`echo "$alt_root_solnm_pkginfo" |grep ARCH|sed -e 's/^.*ARCH: *\([a-z0-9]*\).*/\1/'`
if [ "x$this_sol_arch" != "x$alt_root_sol_arch" ]; then
postrun_debug "/ is $this_sol_arch, $PKG_INSTALL_ROOT is $alt_root_sol_arch"
return 1
fi
return 0
}
check_alt_root_okay || postrun_alt_root_okay=no
if [ "x$postrun_command_file" = x ]; then
# save the standard input in a temporary file
tmp_cmd_file=`postrun_mktemp /tmp/postrun.cmd.XXXX`
cat > $tmp_cmd_file
postrun_command_file=$tmp_cmd_file
fi
if [ "$LUBIN" != "" ]; then
#
# Live Upgrade. Unsafe to run the command now.
# Put into spool and defer to next boot.
#
postrun_spool_command "${@}"
elif [ "$PKG_INSTALL_ROOT" != "" -a "$PKG_INSTALL_ROOT" != "/" -a \
"x$postrun_alt_root_okay" != xyes ]; then
#
# Installation to an alternate root directory
# Put command into spool and defer to next boot.
#
postrun_spool_command "${@}"
else
#
# Local package install. Everything's shiny happy,
# safe to run the command right now
#
# Note: for alt_root_okay jobs, -u only applies to the case
# when we have to spool the job
if [ x$postrun_is_uniq = xyes -a x$postrun_alt_root_okay != xyes ]; then
# don't run the command yet in case the same command is requested
# within the next postrun_uniq_timeout minutes
postrun_spool_command "${@}" && {
echo "$MYDIR/postrun -q" | \
at now "+${postrun_uniq_timeout}minutes" > /dev/null 2>&1
}
else
postrun_debug "Executing commands immediately"
postrun_run_command "${@}"
# do not delete the tmp_cmd_file because it's the only copy of the
# commands (since the job is not spooled)
tmp_cmd_file=''
fi
fi
if [ "x$tmp_cmd_file" != x ]; then
rm -f $tmp_cmd_file
fi
exit $exitval