diff options
author | Dieter Plaetinck <dieter@plaetinck.be> | 2009-03-29 18:16:42 +0200 |
---|---|---|
committer | Dieter Plaetinck <dieter@plaetinck.be> | 2009-03-29 18:16:42 +0200 |
commit | ef2290b0e31c285267bba9dde3634b628df0ebf0 (patch) | |
tree | de627bb47c87f535ad7eea5d7b3da9bc2cbef3c7 /src/core/libs/lib-misc.sh | |
parent | 71f5510aaaa20ae5ae9c773dca12028bd96aafdf (diff) | |
parent | ff1bc0cd6060d0a23911f1ef25633f706a9af619 (diff) |
Merge branch 'experimental'2009.03.29
Diffstat (limited to 'src/core/libs/lib-misc.sh')
-rw-r--r-- | src/core/libs/lib-misc.sh | 86 |
1 files changed, 70 insertions, 16 deletions
diff --git a/src/core/libs/lib-misc.sh b/src/core/libs/lib-misc.sh index 01c291f..1acebac 100644 --- a/src/core/libs/lib-misc.sh +++ b/src/core/libs/lib-misc.sh @@ -1,9 +1,38 @@ #!/bin/bash +# runs a process and makes sure the output is shown to the user. sets the exit state of the executed program ($<identifier>_exitcode) so the caller can show a concluding message. +# when in dia mode, we will run the program and a dialog instance in the background (cause that's just how it works with dia) +# when in cli mode, the program will just run in the foreground. technically it can be run backgrounded but then we need tail -f (cli_follow_progress), and we miss the beginning of the output if it goes too fast, not to mention because of the sleep in run_background +# $1 identifier +# $2 command (will be eval'ed) +# $3 logfile +# $4 title to show while process is running +run_controlled () +{ + [ -z "$1" ] && die_error "run_controlled: please specify an identifier to keep track of the command!" + [ -z "$2" ] && die_error "run_controlled needs a command to execute!" + [ -z "$3" ] && die_error "run_controlled needs a logfile to redirect output to!" + [ -z "$4" ] && die_error "run_controlled needs a title to show while your process is running!" + + if [ "$var_UI_TYPE" = dia ] + then + run_background $1 "$2" $3 + follow_progress " $4 " $3 $BACKGROUND_PID # dia mode ignores the pid. cli uses it to know how long it must do tail -f + wait_for $1 $FOLLOW_PID + else + notify "$4" + var_exit=${1}_exitcode + eval "$2" >>$3 2>&1 + read $var_exit <<< $? + fi +} + + # run a process in the background, and log it's stdout and stderr to a specific logfile # returncode is stored in $<identifier>_exitcode -# $1 identifier +# pid of the backgrounded wrapper process is stored in BACKGROUND_PID (this is _not_ the pid of $2) +# $1 identifier -> WARNING: do never ever use -'s or other fancy characters here. only numbers, letters and _ please. (because $<identifier>_exitcode must be a valid bash variable!) # $2 command (will be eval'ed) # $3 logfile run_background () @@ -12,47 +41,50 @@ run_background () [ -z "$2" ] && die_error "run_background needs a command to execute!" [ -z "$3" ] && die_error "run_background needs a logfile to redirect output to!" - debug "run_background called. identifier: $1, command: $2, logfile: $3" + debug 'MISC' "run_background called. identifier: $1, command: $2, logfile: $3" ( \ - touch $RUNTIME_DIR/.$1-running - debug "run_background starting $1: $2 >>$3 2>&1" + touch $RUNTIME_DIR/aif-$1-running + debug 'MISC' "run_background starting $1: $2 >>$3 2>&1" [ -f $3 ] && echo -e "\n\n\n" >>$3 echo "STARTING $1 . Executing $2 >>$3 2>&1\n" >> $3; var_exit=${1}_exitcode eval "$2" >>$3 2>&1 - read $var_exit <<< $? #TODO: bash complains about 'not a valid identifier' - debug "run_background done with $1: exitcode (\$$1_exitcode): "${!var_exit}" .Logfile $3" #TODO ${!var_exit} doesn't show anything --> maybe fixed now + read $var_exit <<< $? + debug 'MISC' "run_background done with $1: exitcode (\$$1_exitcode): ${!var_exit} .Logfile $3" echo >> $3 - rm -f $RUNTIME_DIR/.$1-running + rm -f $RUNTIME_DIR/aif-$1-running ) & + BACKGROUND_PID=$! sleep 2 } # wait until a process is done -# $1 identifier +# $1 identifier. WARNING! see above +# $2 pid of a process to kill when done (optional). useful for dialog --no-kill --tailboxbg's pid. wait_for () { [ -z "$1" ] && die_error "wait_for needs an identifier to known on which command to wait!" - while [ -f $RUNTIME_DIR/.$1-running ] + while [ -f $RUNTIME_DIR/aif-$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 + [ -n "$2" ] && kill $2 } -# $1 set (array) haystack -# $2 needle +# $1 needle +# $2 set (array) haystack check_is_in () { - [ -z "$1" ] && debug "check_is_in $1 $2" && die_error "check_is_in needs a non-empty needle as \$2 and a haystack as \$1!" # haystack can be empty though + [ -z "$1" ] && die_error "check_is_in needs a non-empty needle as \$1 and a haystack as \$2!(got: check_is_in '$1' '$2'" # haystack can be empty though + NEEDLE=$1 + HAYSTACK=$2 - local pattern="$1" element + local pattern="$NEEDLE" element shift for element do @@ -66,5 +98,27 @@ check_is_in () cleanup_runtime () { mkdir -p $RUNTIME_DIR || die_error "Cannot create $RUNTIME_DIR" - rm -rf $RUNTIME_DIR/.dia* &>/dev/null + rm -rf $RUNTIME_DIR/aif-dia* &>/dev/null +} + + +dohwclock() { + infofy "Syncing hardwareclock to systemclock ..." + if [ "$HARDWARECLOCK" = "UTC" ]; then + HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc" + else + HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime" + fi + + [ ! -d /var/lib/hwclock ] && mkdir -p /var/lib/hwclock + if [ ! -f /var/lib/hwclock/adjtime ]; then + echo "0.0 0 0.0" > /var/lib/hwclock/adjtime # what the hell is this for??? + fi + hwclock $HWCLOCK_PARAMS #tpowa does it without, but i would add --noadjtime here } + +target_configure_initial_keymap_font () +{ + [ -n "$var_KEYMAP" ] && sed -i "s/^KEYMAP=.*/KEYMAP=\"$var_KEYMAP\"/" ${var_TARGET_DIR}/etc/rc.conf + [ -n "$var_CONSOLEFONT" ] && sed -i "s/^CONSOLEFONT=.*/CONSOLEFONT=\"$var_CONSOLEFONT\"/" ${var_TARGET_DIR}/etc/rc.conf +}
\ No newline at end of file |