147 # stdout NOT connected to a terminal device, so be silent |
147 # stdout NOT connected to a terminal device, so be silent |
148 silent=1 |
148 silent=1 |
149 fi |
149 fi |
150 fi |
150 fi |
151 |
151 |
152 # extend run-time environment with local OpenPKG tools (shtool, rpmtool, etc) |
152 # extend runtime environment with local OpenPKG tools (shtool, rpmtool, etc) |
153 PATH_ORIG="$PATH" |
153 PATH_ORIG="$PATH" |
154 PATH="$prefix/lib/openpkg/fallback:$PATH" |
154 PATH="$prefix/lib/openpkg/fallback:$PATH" |
155 PATH="$prefix/bin:$PATH" |
155 PATH="$prefix/bin:$PATH" |
156 PATH="$prefix/sbin:$PATH" |
156 PATH="$prefix/sbin:$PATH" |
157 PATH="$prefix/lib/openpkg:$PATH" |
157 PATH="$prefix/lib/openpkg:$PATH" |
158 PATH="$prefix/lib/openpkg/override:$PATH" |
158 PATH="$prefix/lib/openpkg/override:$PATH" |
159 |
159 |
160 # handle --query option |
160 # handle --query option |
161 if [ ".$query" = .1 ]; then |
161 if [ ".$query" = .1 ]; then |
162 # suck in all %config sections of all scripts |
162 # suck in all %config sections of all scripts |
163 # (rc.openpkg is special: has to be first and requires pre-inclusion of rc.conf) |
163 # (rc.openpkg is special: has to be first and requires preinclusion of rc.conf) |
164 touch $tmpfile |
164 touch $tmpfile |
165 sed <$rcdir/rc.openpkg >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d' |
165 sed <$rcdir/rc.openpkg >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d' |
166 echo ". $rcconf" >>$tmpfile |
166 echo ". $rcconf" >>$tmpfile |
167 echo ". $deffile" >>$tmpfile |
167 echo ". $deffile" >>$tmpfile |
168 scripts=`/bin/ls $rcdir/rc.* | sed -e "s;^$rcdir/rc\.;;" | egrep -v '^openpkg$'` |
168 scripts=`/bin/ls $rcdir/rc.* | sed -e "s;^$rcdir/rc\.;;" | egrep -v '^openpkg$'` |
185 fi |
185 fi |
186 |
186 |
187 # handle --config option |
187 # handle --config option |
188 if [ ".$config" = .1 ]; then |
188 if [ ".$config" = .1 ]; then |
189 # suck in all %config sections of all scripts |
189 # suck in all %config sections of all scripts |
190 # (rc.openpkg is special: has to be first and requires pre-inclusion of rc.conf) |
190 # (rc.openpkg is special: has to be first and requires preinclusion of rc.conf) |
191 touch $tmpfile |
191 touch $tmpfile |
192 sed <$rcdir/rc.openpkg >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d' |
192 sed <$rcdir/rc.openpkg >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d' |
193 echo ". $rcconf" >>$tmpfile |
193 echo ". $rcconf" >>$tmpfile |
194 echo ". $deffile" >>$tmpfile |
194 echo ". $deffile" >>$tmpfile |
195 scripts=`/bin/ls $rcdir/rc.* | sed -e "s;^$rcdir/rc\.;;" | egrep -v '^openpkg$'` |
195 scripts=`/bin/ls $rcdir/rc.* | sed -e "s;^$rcdir/rc\.;;" | egrep -v '^openpkg$'` |
269 daily ) delay=900; timeout=7200 ;; # 15m / 2h |
269 daily ) delay=900; timeout=7200 ;; # 15m / 2h |
270 hourly ) delay=600; timeout=3600 ;; # 5m / 1h |
270 hourly ) delay=600; timeout=3600 ;; # 5m / 1h |
271 quarterly|* ) delay=30; timeout=900 ;; # 30s / 15m |
271 quarterly|* ) delay=30; timeout=900 ;; # 30s / 15m |
272 esac |
272 esac |
273 |
273 |
274 # apply random run-time delay |
274 # apply random runtime delay |
275 # (hint: $RANDOM is a random value 0..32767) |
275 # (hint: $RANDOM is a random value 0..32767) |
276 sleep $(( ($RANDOM * $delay) / 32767 )) |
276 sleep $(( ($RANDOM * $delay) / 32767 )) |
277 |
277 |
278 # wrap ourself for mutual exclusion run-time |
278 # wrap ourself for mutual exclusion runtime |
279 # and then perform the "all" command |
279 # and then perform the "all" command |
280 cleanup |
280 cleanup |
281 exec $prefix/lib/openpkg/mutex \ |
281 exec $prefix/lib/openpkg/mutex \ |
282 -t $timeout $prefix/RPM/TMP/openpkg-rc-cron.mutex \ |
282 -t $timeout $prefix/RPM/TMP/openpkg-rc-cron.mutex \ |
283 sh -c "exec $0 all $*" || exit $? |
283 sh -c "exec $0 all $*" || exit $? |
303 echo "openpkg:rc:ERROR: package \"$scripts\" not found" 1>&2 |
303 echo "openpkg:rc:ERROR: package \"$scripts\" not found" 1>&2 |
304 exit 1 |
304 exit 1 |
305 fi |
305 fi |
306 fi |
306 fi |
307 |
307 |
308 # determine current run-time user |
308 # determine current runtime user |
309 user=`(id -un) 2>/dev/null ||\ |
309 user=`(id -un) 2>/dev/null ||\ |
310 (id | sed -e 's;^[^(]*(\([^)]*\)).*;\1;') 2>/dev/null ||\ |
310 (id | sed -e 's;^[^(]*(\([^)]*\)).*;\1;') 2>/dev/null ||\ |
311 (whoami) 2>/dev/null ||\ |
311 (whoami) 2>/dev/null ||\ |
312 (who am i | cut "-d " -f1) 2>/dev/null ||\ |
312 (who am i | cut "-d " -f1) 2>/dev/null ||\ |
313 echo ${LOGNAME:-${USER}}` |
313 echo ${LOGNAME:-${USER}}` |
316 exit 1 |
316 exit 1 |
317 fi |
317 fi |
318 |
318 |
319 # Avoid handing control to OpenPKG binary logic until |
319 # Avoid handing control to OpenPKG binary logic until |
320 # the binary is is ready for prime time on all platforms. |
320 # the binary is is ready for prime time on all platforms. |
321 ## just call OpenPKG RPM to let it once perform the run-time integrity checks |
321 ## just call OpenPKG RPM to let it once perform the runtime integrity checks |
322 #$prefix/bin/openpkg rpm -q openpkg >/dev/null || exit $? |
322 #$prefix/bin/openpkg rpm -q openpkg >/dev/null || exit $? |
323 |
323 |
324 # iterate over the specified commands |
324 # iterate over the specified commands |
325 rv=0 |
325 rv=0 |
326 cmds="$*" |
326 cmds="$*" |
406 exit 1 |
406 exit 1 |
407 fi |
407 fi |
408 fi |
408 fi |
409 done |
409 done |
410 |
410 |
411 # if operating on all scripts, complain if a non-standard command |
411 # if operating on all scripts, complain if a nonstandard command |
412 # was used and it was not found in any(!) script at all. The |
412 # was used and it was not found in any(!) script at all. The |
413 # standard commands are accepted to perform no operation if no |
413 # standard commands are accepted to perform no operation if no |
414 # packages are currently installed which provide such commands. |
414 # packages are currently installed which provide such commands. |
415 if [ ".$list" = . -a ".$isall" = .1 ]; then |
415 if [ ".$list" = . -a ".$isall" = .1 ]; then |
416 case "$cmd" in |
416 case "$cmd" in |
435 # generate: optionally enable shell debugging |
435 # generate: optionally enable shell debugging |
436 if [ ".$debug" = .1 ]; then |
436 if [ ".$debug" = .1 ]; then |
437 echo "set -x" >>$tmpfile |
437 echo "set -x" >>$tmpfile |
438 fi |
438 fi |
439 |
439 |
440 # generate: inclusion of the run-command helper functions |
440 # generate: inclusion of the runcommand helper functions |
441 echo ". $rcfunc" >>$tmpfile |
441 echo ". $rcfunc" >>$tmpfile |
442 |
442 |
443 # generate: all %config sections of all(!) scripts. We cannot |
443 # generate: all %config sections of all(!) scripts. We cannot |
444 # just include those which have the current command in it |
444 # just include those which have the current command in it |
445 # because by design all command scripts see the %config |
445 # because by design all command scripts see the %config |
446 # section of all(!) scripts. Because of $openpkg_rc_def the |
446 # section of all(!) scripts. Because of $openpkg_rc_def the |
447 # variable, we place the %config section of "openpkg" to the front. |
447 # variable, we place the %config section of "openpkg" to the front. |
448 # And we have to extra pre-include the rc.conf to allow |
448 # And we have to extra preinclude the rc.conf to allow |
449 # rc.conf to override the default of $openpkg_rc_def, too. |
449 # rc.conf to override the default of $openpkg_rc_def, too. |
450 sed <$rcdir/rc.openpkg >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d' |
450 sed <$rcdir/rc.openpkg >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d' |
451 echo ". $rcconf" >>$tmpfile |
451 echo ". $rcconf" >>$tmpfile |
452 echo ". $deffile" >>$tmpfile |
452 echo ". $deffile" >>$tmpfile |
453 l_scripts=`/bin/ls $rcdir/rc.* | sed -e "s;^$rcdir/rc\.;;" | egrep -v '^openpkg$'` |
453 l_scripts=`/bin/ls $rcdir/rc.* | sed -e "s;^$rcdir/rc\.;;" | egrep -v '^openpkg$'` |
474 # was found in order to execute, print, or evaluate their scripts |
474 # was found in order to execute, print, or evaluate their scripts |
475 verbose_pos=0 |
475 verbose_pos=0 |
476 for entry in `echo $list | tr ',' '\012' | sort -n`; do |
476 for entry in `echo $list | tr ',' '\012' | sort -n`; do |
477 [ ".$entry" = . ] && continue |
477 [ ".$entry" = . ] && continue |
478 |
478 |
479 # re-determine the script name, script and whether to print output |
479 # redetermine the script name, script and whether to print output |
480 eval `echo $entry | sed -e 's%^[0-9]*:\(.*\):\(.*\):\(.*\)$%s_name="\1"; s_user="\2"; s_output="\3";%'` |
480 eval `echo $entry | sed -e 's%^[0-9]*:\(.*\):\(.*\):\(.*\)$%s_name="\1"; s_user="\2"; s_output="\3";%'` |
481 |
481 |
482 # display verbose progress message parts |
482 # display verbose progress message parts |
483 if [ ".$print" = .0 -a ".$eval" = .0 -a ".$silent" = .0 ]; then |
483 if [ ".$print" = .0 -a ".$eval" = .0 -a ".$silent" = .0 ]; then |
484 # line break if we already have output more than 70 |
484 # line break if we already have output more than 70 |
512 sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%$cmd/d" -e '/^%.*/,$d' |
512 sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%$cmd/d" -e '/^%.*/,$d' |
513 elif [ ".$eval" = .1 ]; then |
513 elif [ ".$eval" = .1 ]; then |
514 # special case: under --eval we just add the %common and |
514 # special case: under --eval we just add the %common and |
515 # command scripts to the generated output script and do |
515 # command scripts to the generated output script and do |
516 # not execute anything at this point. Additionally, we |
516 # not execute anything at this point. Additionally, we |
517 # emulate a real sub-shell environment. |
517 # emulate a real subshell environment. |
518 sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%common/d" -e '/^%.*/,$d' |
518 sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%common/d" -e '/^%.*/,$d' |
519 echo "while [ 1 ]; do" >>$tmpfile |
519 echo "while [ 1 ]; do" >>$tmpfile |
520 sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%$cmd/d" -e '/^%.*/,$d' \ |
520 sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%$cmd/d" -e '/^%.*/,$d' \ |
521 -e 's/^exit[^;]*/break 99/' -e 's/\([^a-zA-Z0-9_]\)exit[^;]*/\1break 99/g' \ |
521 -e 's/^exit[^;]*/break 99/' -e 's/\([^a-zA-Z0-9_]\)exit[^;]*/\1break 99/g' \ |
522 -e 's/^return[^;]*/break 99/' -e 's/\([^a-zA-Z0-9_]\)return[^;]*/\1break 99/g' |
522 -e 's/^return[^;]*/break 99/' -e 's/\([^a-zA-Z0-9_]\)return[^;]*/\1break 99/g' |
532 # generate: optionally enable shell debugging |
532 # generate: optionally enable shell debugging |
533 if [ ".$debug" = .1 ]; then |
533 if [ ".$debug" = .1 ]; then |
534 echo "set -x" >>$tmpfile |
534 echo "set -x" >>$tmpfile |
535 fi |
535 fi |
536 |
536 |
537 # generate: inclusion of the run-command helper functions |
537 # generate: inclusion of the runcommand helper functions |
538 echo ". $rcfunc" >>$tmpfile |
538 echo ". $rcfunc" >>$tmpfile |
539 |
539 |
540 # generate: all %config sections of all(!) scripts. We cannot |
540 # generate: all %config sections of all(!) scripts. We cannot |
541 # just include those which have the current command in it |
541 # just include those which have the current command in it |
542 # because by design all command scripts see the %config |
542 # because by design all command scripts see the %config |
543 # section of all(!) scripts. Because of $openpkg_rc_def the |
543 # section of all(!) scripts. Because of $openpkg_rc_def the |
544 # variable, we place the %config section of "openpkg" to the front. |
544 # variable, we place the %config section of "openpkg" to the front. |
545 # And we have to extra pre-include the rc.conf to allow |
545 # And we have to extra preinclude the rc.conf to allow |
546 # rc.conf to override the default of $openpkg_rc_def, too. |
546 # rc.conf to override the default of $openpkg_rc_def, too. |
547 sed <$rcdir/rc.openpkg >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d' |
547 sed <$rcdir/rc.openpkg >>$tmpfile -e "1,/^%config/d" -e '/^%.*/,$d' |
548 echo ". $rcconf" >>$tmpfile |
548 echo ". $rcconf" >>$tmpfile |
549 echo ". $deffile" >>$tmpfile |
549 echo ". $deffile" >>$tmpfile |
550 l_scripts=`/bin/ls $rcdir/rc.* | sed -e "s;^$rcdir/rc\.;;" | egrep -v '^openpkg$'` |
550 l_scripts=`/bin/ls $rcdir/rc.* | sed -e "s;^$rcdir/rc\.;;" | egrep -v '^openpkg$'` |
576 rc=$? |
576 rc=$? |
577 fi |
577 fi |
578 elif [ ".@l_susr@" != ".root" ]; then |
578 elif [ ".@l_susr@" != ".root" ]; then |
579 # do not complain if we would not have any chance |
579 # do not complain if we would not have any chance |
580 # at all to switch the user because we are running |
580 # at all to switch the user because we are running |
581 # in a non-privileged instance. Else we would just |
581 # in a unprivileged instance. Else we would just |
582 # trash the mailbox of the user receiving the |
582 # trash the mailbox of the user receiving the |
583 # output of periodic run-commands. |
583 # output of periodic runcommands. |
584 rc=0 |
584 rc=0 |
585 else |
585 else |
586 echo "openpkg:rc:WARNING: $prefix:$s_name:%$cmd: require root privileges to run as user \"$s_user\"" 1>&2 |
586 echo "openpkg:rc:WARNING: $prefix:$s_name:%$cmd: require root privileges to run as user \"$s_user\"" 1>&2 |
587 rc=1 |
587 rc=1 |
588 fi |
588 fi |
639 fi |
639 fi |
640 fi |
640 fi |
641 fi |
641 fi |
642 done |
642 done |
643 |
643 |
644 # post-processing for each command |
644 # postprocessing for each command |
645 if [ ".$print" = .1 ]; then |
645 if [ ".$print" = .1 ]; then |
646 # for --print just print the resulting script to stdout |
646 # for --print just print the resulting script to stdout |
647 cat $tmpfile |
647 cat $tmpfile |
648 elif [ ".$eval" = .1 ]; then |
648 elif [ ".$eval" = .1 ]; then |
649 # finish generation of temporary script by restoring stdout |
649 # finish generation of temporary script by restoring stdout |
696 $tmpfile >$outfile 2>/dev/null |
696 $tmpfile >$outfile 2>/dev/null |
697 fi |
697 fi |
698 cp $outfile $tmpfile |
698 cp $outfile $tmpfile |
699 |
699 |
700 # for --eval we cannot just print the resulting script because |
700 # for --eval we cannot just print the resulting script because |
701 # not all Bourne-Shell implementations like to "eval" large |
701 # not all Bourne Shell implementations like to "eval" large |
702 # multi-line outputs. Hence we output a little one-liner which |
702 # multiline outputs. Hence we output a little one liner which |
703 # "sources" the script instead and cleans up. |
703 # "sources" the script instead and cleans up. |
704 case $SHELL in |
704 case $SHELL in |
705 csh|*/csh|tcsh|*/tcsh ) |
705 csh|*/csh|tcsh|*/tcsh ) |
706 echo "source $tmpfile; rm -rf $tmpdir 2>/dev/null || true" |
706 echo "source $tmpfile; rm -rf $tmpdir 2>/dev/null || true" |
707 ;; |
707 ;; |