diff options
author | Dieter Plaetinck <dieter@plaetinck.be> | 2008-11-01 13:31:08 +0100 |
---|---|---|
committer | Dieter Plaetinck <dieter@plaetinck.be> | 2008-11-01 13:31:08 +0100 |
commit | 6abc6238510e06734c2e3377d273970667d38c54 (patch) | |
tree | 311cbdb4563b44c37aa50c410c4b3624c37439b1 /src/lib/lib-misc.sh | |
parent | 166ddfab7fe5d507d84e6d434c1b92f5b2091db4 (diff) |
cleaned up mkinitcpio code. abstracted run_background, follow_progress, wait_for etc. implemented warning messages. + some fixes
Diffstat (limited to 'src/lib/lib-misc.sh')
-rw-r--r-- | src/lib/lib-misc.sh | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/lib/lib-misc.sh b/src/lib/lib-misc.sh new file mode 100644 index 0000000..bc9b150 --- /dev/null +++ b/src/lib/lib-misc.sh @@ -0,0 +1,42 @@ +#!/bin/sh + + +# run a process in the background, and log it's stdout and stderr to a specific logfile +# $1 identifier +# $2 command (will be eval'ed) +# $3 logfile +run_background () +{ + [ -z "$1" ] && die_error "run_background: please specify an identifier to keep track of the command!" + [ -z "$2" ] && die_error "run_background needs a command to execute!" + [ -z "$3" ] && die_error "run_background needs a logfile to redirect output to!" + + ( \ + touch /tmp/$1-running + echo "$1 progress ..." > $3; \ + echo >> $3; \ + eval "$1" >>$3 2>&1 + echo $? > /tmp/.$1-retcode + echo >> $3 + rm -f /tmp/$1-running + ) & + + sleep 2 +} + + +# wait untill a process is done +# $1 identifier +wait_for () +{ + [ -z "$1" ] && die_error "wait_for needs an identifier to known on which command to wait!" + + while [ -f /tmp/$1-running ] + do + #TODO: follow_progress dialog mode = nonblocking (so check and sleep is good), cli mode (tail -f )= blocking? (so check is probably not needed as it will be done) + sleep 1 + done + + kill $(cat $ANSWER) #TODO: this may not work when mode = cli +} + |