diff -r 71503088f51b -r f880f219c566 openpkg/rc
--- a/openpkg/rc Tue Jul 31 12:12:54 2012 +0200
+++ b/openpkg/rc Tue Jul 31 12:23:42 2012 +0200
@@ -1,15 +1,14 @@
#!@l_prefix@/lib/openpkg/bash --noprofile
##
-## rc -- OpenPKG Runcommand Processor
-## Copyright (c) 2000-2007 OpenPKG Foundation e.V.
-## Copyright (c) 2000-2007 Ralf S. Engelschall
+## rc -- OpenPKG Run-Command Processor
+## Copyright (c) 2000-2012 OpenPKG GmbH
##
-## Permission to use, copy, modify, and distribute this software for
-## any purpose with or without fee is hereby granted, provided that
-## the above copyright notice and this permission notice appear in all
-## copies.
+## This software is property of the OpenPKG GmbH, DE MUC HRB 160208.
+## All rights reserved. Licenses which grant limited permission to use,
+## copy, modify and distribute this software are available from the
+## OpenPKG GmbH.
##
-## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+## THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
@@ -29,8 +28,8 @@
# program name, version and date
progname="rc"
-progvers="1.2.0"
-progdate="28-Jul-2003"
+progvers="1.2.1"
+progdate="2007-12-27"
# path to OpenPKG instance
prefix="@l_prefix@"
@@ -49,6 +48,42 @@
"
##
+## temporary file handling
+##
+
+# establish secure temporary directory
+i=0
+while [ $i -lt 10 ]; do
+ tmpdir="/tmp/rc-`date '+%Y%m%d%H%M%S'`-$$"
+ (umask 022; mkdir $tmpdir >/dev/null 2>&1) && break
+ i=$(($i + 1))
+ sleep 1
+done
+if [ $i -eq 10 ]; then
+ echo "openpkg:rc:ERROR: unable to establish secure temporary directory" 1>&2
+ exit 1
+fi
+declare -r tmpdir
+cleanup () {
+ if [ ".$tmpdir" != . ]; then
+ if [ -d $tmpdir ]; then
+ rm -rf $tmpdir >/dev/null 2>&1 || true
+ fi
+ fi
+}
+trap "cleanup; trap - EXIT INT ABRT QUIT TERM" EXIT INT ABRT QUIT TERM
+
+# determine reasonable temporary files
+tmpfile="$tmpdir/rc.tmp"
+outfile="$tmpdir/rc.out"
+errfile="$tmpdir/rc.err"
+allfile="$tmpdir/rc.all"
+deffile="$tmpdir/rc.def"
+
+# initialize files
+cp /dev/null $deffile
+
+##
## command line option parsing
##
@@ -65,12 +100,7 @@
# iterate over argument line
while [ $# -gt 0 ]; do
- opt=$1
- case $opt in
- -*=*) arg=${opt/-*=/} ;;
- *) arg='' ;;
- esac
- case $opt in
+ case "$1" in
-s|--silent ) silent=1 ;;
-v|--verbose ) verbose=1 ;;
-d|--debug ) debug=1 ;;
@@ -80,8 +110,12 @@
-e|--eval ) eval=1 ;;
-c|--config ) config=1 ;;
-q|--query ) query=1 ;;
- -* ) help="Invalid option \`$opt'"; break ;;
- * ) break ;;
+ -D|--define ) echo "@$2" | \
+ sed -e "s;';\\\\';g" | \
+ sed -e "s;^@\\([a-z][a-zA-Z0-9_]*\\)=\\(.*\\)\$;\1='\2';" \
+ -e "s;^@.*;;" >>$deffile; shift ;;
+ -* ) help="Invalid option \`$1'"; break ;;
+ * ) break ;;
esac
shift
done
@@ -92,7 +126,7 @@
echo "$progname:ERROR: $help" 1>&2
fi
echo "Usage: $progname [-s|--silent] [-v|--verbose] [-d|--debug] [-k|--keep] [-h|--help]" 1>&2
- echo " [-p|--print] [-e|--eval] [-c|--config] [-q|--query]" 1>&2
+ echo " [-p|--print] [-e|--eval] [-c|--config] [-q|--query] [-D|--define =]" 1>&2
echo " [ ...]" 1>&2
if [ ".$help" != ".Usage" ]; then
exit 1
@@ -117,30 +151,11 @@
# extend run-time environment with local OpenPKG tools (shtool, rpmtool, etc)
PATH_ORIG="$PATH"
+PATH="$prefix/lib/openpkg/fallback:$PATH"
PATH="$prefix/bin:$PATH"
PATH="$prefix/sbin:$PATH"
PATH="$prefix/lib/openpkg:$PATH"
-
-# establish secure temporary directory
-i=0
-while [ $i -lt 10 ]; do
- tmpdir="/tmp/rc-`date '+%Y%m%d%H%M%S'`-$$"
- (umask 022; mkdir $tmpdir >/dev/null 2>&1) && break
- i=$(($i + 1))
- sleep 1
-done
-if [ $i -eq 10 ]; then
- echo "openpkg:rc:ERROR: unable to establish secure temporary directory" 1>&2
- exit 1
-fi
-declare -r tmpdir
-trap "trap - EXIT INT ABRT QUIT TERM; rm -rf $tmpdir >/dev/null 2>&1 || true" EXIT INT ABRT QUIT TERM
-
-# determine reasonable temporary files
-tmpfile="$tmpdir/rc.tmp"
-outfile="$tmpdir/rc.out"
-errfile="$tmpdir/rc.err"
-allfile="$tmpdir/rc.all"
+PATH="$prefix/lib/openpkg/override:$PATH"
# handle --query option
if [ ".$query" = .1 ]; then
@@ -149,6 +164,7 @@
touch $tmpfile
sed <$rcdir/rc.openpkg >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d'
echo ". $rcconf" >>$tmpfile
+ echo ". $deffile" >>$tmpfile
scripts=`/bin/ls $rcdir/rc.* | sed -e "s;^$rcdir/rc\.;;" | egrep -v '^openpkg$'`
for s_name in $scripts; do
sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d'
@@ -157,6 +173,7 @@
# apply override values to get effective values
. $rcconf
+ . $deffile
# display variable value
for var in $*; do
@@ -174,6 +191,7 @@
touch $tmpfile
sed <$rcdir/rc.openpkg >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d'
echo ". $rcconf" >>$tmpfile
+ echo ". $deffile" >>$tmpfile
scripts=`/bin/ls $rcdir/rc.* | sed -e "s;^$rcdir/rc\.;;" | egrep -v '^openpkg$'`
for s_name in $scripts; do
sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d'
@@ -192,6 +210,7 @@
# apply override values to get effective values
. $rcconf
+ . $deffile
# determine how to print in bold mode in case output
# is connected to a terminal device
@@ -237,20 +256,48 @@
scripts="${1/*rc./}"
shift
isall=0
+if [ ".$scripts" = ".cron" ]; then
+ # "cron" is an "all" with a random delay (to ensure that multiple
+ # OpenPKG instances do not all startup at exactly the same time)
+ # plus a mutex lock to ensure that multiple OpenPKG cron tasks of
+ # the same OpenPKG instance do not stumble over each other).
+
+ # determine delay range and timeout
+ case "${1-quarterly}" in
+ monthly ) delay=1800; timeout=28800 ;; # 30m / 8h
+ weekly ) delay=1800; timeout=14400 ;; # 30m / 4h
+ daily ) delay=900; timeout=7200 ;; # 15m / 2h
+ hourly ) delay=600; timeout=3600 ;; # 5m / 1h
+ quarterly|* ) delay=30; timeout=900 ;; # 30s / 15m
+ esac
+
+ # apply random run-time delay
+ # (hint: $RANDOM is a random value 0..32767)
+ sleep $(( ($RANDOM * $delay) / 32767 ))
+
+ # wrap ourself for mutual exclusion run-time
+ # and then perform the "all" command
+ cleanup
+ exec $prefix/lib/openpkg/mutex \
+ -t $timeout $prefix/RPM/TMP/openpkg-rc-cron.mutex \
+ sh -c "exec $0 all $*" || exit $?
+fi
if [ ".$scripts" = ".all" ]; then
isall=1
. $rcconf
- if [ ".$openpkg_runall" != . ]; then
- # backward compatibility only
- echo "openpkg:rc:WARNING: variable \"openpkg_runall\" was renamed to \"openpkg_rc_all\"." 1>&2
- echo "openpkg:rc:WARNING: value of deprecated variable \"openpkg_runall\" taken over for compatibility." 1>&2
- echo "openpkg:rc:WARNING: please update your local configuration in \"$rcconf\"." 1>&2
- openpkg_rc_all="$openpkg_runall"
- fi
+ . $deffile
case "$openpkg_rc_all" in
[Nn][Oo] | [Ff][Aa][Ll][Ss][Ee] | [Oo][Ff][Ff] | 0 ) exit 0 ;;
esac
scripts=`/bin/ls $rcdir/rc.* | sed -e "s;^$rcdir/rc\.;;"`
+
+ # the "all" target is usually called from system startup scripts,
+ # and we really want to ensure that no potentially corrupt
+ # (because of an unclean shutdown of the system) RPM DB journal
+ # files are staying around and preventing the startup of the
+ # OpenPKG instance. When called manually it also doesn't hurt to
+ # cleanup.
+ rm -f $prefix/RPM/DB/__db.* >/dev/null 2>&1 || true
else
if [ ! -f "$rcdir/rc.$scripts" ]; then
echo "openpkg:rc:ERROR: package \"$scripts\" not found" 1>&2
@@ -269,6 +316,9 @@
exit 1
fi
+# just call OpenPKG RPM to let it once perform the run-time integrity checks
+$prefix/bin/openpkg rpm -q openpkg >/dev/null || exit $?
+
# iterate over the specified commands
rv=0
cmds="$*"
@@ -397,6 +447,7 @@
# rc.conf to override the default of $openpkg_rc_def, too.
sed <$rcdir/rc.openpkg >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d'
echo ". $rcconf" >>$tmpfile
+ echo ". $deffile" >>$tmpfile
l_scripts=`/bin/ls $rcdir/rc.* | sed -e "s;^$rcdir/rc\.;;" | egrep -v '^openpkg$'`
for l_name in $l_scripts; do
sed <$rcdir/rc.$l_name >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d'
@@ -404,6 +455,7 @@
# generate: inclusion of the application of override variables
echo ". $rcconf" >>$tmpfile
+ echo ". $deffile" >>$tmpfile
# for --eval redirect stderr and stdout (but remember stdout)
# (let stderr pass unfiltered in case of debug mode)
@@ -492,6 +544,7 @@
# rc.conf to override the default of $openpkg_rc_def, too.
sed <$rcdir/rc.openpkg >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d'
echo ". $rcconf" >>$tmpfile
+ echo ". $deffile" >>$tmpfile
l_scripts=`/bin/ls $rcdir/rc.* | sed -e "s;^$rcdir/rc\.;;" | egrep -v '^openpkg$'`
for l_name in $l_scripts; do
sed <$rcdir/rc.$l_name >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d'
@@ -499,6 +552,7 @@
# generate: inclusion of the application of override variables
echo ". $rcconf" >>$tmpfile
+ echo ". $deffile" >>$tmpfile
# generate: %common section and particular command section
sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%common/d" -e '/^%.*/,$d'