also sprach Jakub Wilk uba...@users.sf.net [2009.06.26.1250 +0200]:
https://trac.madduck.net/pub/browser/bin/base/phoenix/
The link is defunct...
It's attached.
--
.''`. martin f. krafft madd...@d.o Related projects:
: :' : proud Debian developer http://debiansystem.info
`. `'` http://people.debian.org/~madduckhttp://vcs-pkg.org
`- Debian - when you have better things to do than fixing systems
a woman is like your shadow;
follow her, she flies;
fly from her, she follows.
-- sébastien-roch-nicolas chamfort
#!/bin/sh -eu
#
# phoenix -- respawns a process unless the user really wants to quit
#
# Copyright © martin f. krafft madd...@madduck.net
# Released under the terms of the Artistic Licence 2.0
#
# Latest version:
# http://svn.madduck.net/pub/bin/base/phoenix
#
# Revision: $Id: phoenix 318 2006-10-25 07:32:04Z madduck $
#
PROGNAME=${0##*/}
about()
{
echo $PROGNAME -- respawn a process unless the user really wants to quit
echo '$Id: phoenix 318 2006-10-25 07:32:04Z madduck $'
echo Copyright © martin f. krafft madd...@madduck.net
echo Released under the terms of the Artistic Licence 2.0
}
usage()
{
about
echo
echo Usage: $PROGNAME [options] [--] [command [arguments]]
echo
echo Valid options are:
cat -_eof | column -s\ -t
-m|--max set maximum number of respawns.
-q|--quiet suppress informational messages.
-h|--help show this output.
-V|--version show version information.
_eof
}
exit_with_error()
{
local ret=1
case $1 in
*[!0-9-]*) :;;
*-|-|?-*) :;;
*)
ret=$1;
[ $ret -lt 0 ] ret=$((256 + $ret)) || :
shift;;
esac
echo E: $PROGNAME: $@ 2
exit $ret
}
info()
{
[ ${quiet:-0} -eq 0 ] || return 0
echo I: $PROGNAME: $@ 2
}
cmd=''
quiet=0
skiprest=0
max=-1
for i in $@; do
if [ $skiprest -eq 0 ]; then
case ${getopt:-} in
max) max=$i; unset getopt; continue;;
esac
case $i in
-q|--quiet) quiet=1; continue;;
--max=*[!0-9]*) exit_with_error 1 invalid argument: $i;;
--max=[0-9]*) max=${i#--max=}; continue;;
-m*[!0-9]*) exit_with_error 1 invalid argument: $i;;
-m[0-9]*) max=${i#-m}; continue;;
-m|--max) getopt=max; continue;;
-h|--help) usage; exit 0;;
-V|--version) about; exit 0;;
*) skiprest=1;;
esac
fi
cmd=${cmd:+$cmd }$i
done
[ $max -eq 0 ] exit 0
eval set -- $cmd
case $(readlink $(command -v $1))$(command -v $1) in
*/dash|dash|dash/bin/sh)
exit_with_error -1 mysteriously, $PROGNAME does not work with dash
(#381878). Sorry.
;;
esac
# require a terminal
test -t 0 -a -t 1 -a -t 2 || exit_with_error 2 'not connected to a terminal.'
ret=0
info Running '$@'... 2
while :; do
max=$(($max - 1))
eval $@ || ret=$?
[ $max -eq 0 ] break
echo -n 'The command finished. Please enter yes if you want to exit: '
read ans || echo
[ $ans = yes ] break
if [ $max -lt 0 ]; then
info Respawning '$@'... 2
continue
elif [ $max -eq 1 ]; then
info Respawning '$@' for the last time... 2
else
info Respawning '$@' $max more times... 2
fi
done
exit $ret
digital_signature_gpg.asc
Description: Digital signature (see http://martin-krafft.net/gpg/)