diff options
author | Felix Fietkau <nbd@openwrt.org> | 2010-01-25 17:11:17 +0000 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2010-01-25 17:11:17 +0000 |
commit | 56bc02a305ae8d8a7e927622d924cdab56d4f012 (patch) | |
tree | 079702f93a3ad4420b99f31bc99c1b9b2b9a8a08 /package/base-files/files/lib/preinit/30_failsafe_wait | |
parent | 35170c48928e99dda69d46274c2749bc9bff972d (diff) | |
download | mtk-20170518-56bc02a305ae8d8a7e927622d924cdab56d4f012.zip mtk-20170518-56bc02a305ae8d8a7e927622d924cdab56d4f012.tar.gz mtk-20170518-56bc02a305ae8d8a7e927622d924cdab56d4f012.tar.bz2 |
add preinit modularization work by Daniel Dickinson (cshore)
SVN-Revision: 19331
Diffstat (limited to 'package/base-files/files/lib/preinit/30_failsafe_wait')
-rw-r--r-- | package/base-files/files/lib/preinit/30_failsafe_wait | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/package/base-files/files/lib/preinit/30_failsafe_wait b/package/base-files/files/lib/preinit/30_failsafe_wait new file mode 100644 index 0000000..084f994 --- /dev/null +++ b/package/base-files/files/lib/preinit/30_failsafe_wait @@ -0,0 +1,86 @@ +#!/bin/sh +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +fs_wait_for_key () { + local timeout=$3 + local timer + local do_failsafe + local keypress_true="$(mktemp)" + local keypress_wait="$(mktemp)" + local keypress_sec="$(mktemp)" + if [ -z "$keypress_wait" ]; then + keypress_wait=/tmp/.keypress_wait + touch $keypress_wait + fi + if [ -z "$keypress_true" ]; then + keypress_true=/tmp/.keypress_true + touch $keypress_true + fi + if [ -z "$keypress_sec" ]; then + keypress_sec=/tmp/.keypress_sec + touch $keypress_sec + fi + + trap "echo 'true' >$keypress_true; lock -u $keypress_wait ; rm -f $keypress_wait" INT + trap "echo 'true' >$keypress_true; lock -u $keypress_wait ; rm -f $keypress_wait" USR1 + + [ -n "$timeout" ] || timeout=1 + [ $timeout -ge 1 ] || timeout=1 + timer=$timeout + lock $keypress_wait + { + while [ $timer -gt 0 ]; do + echo "$timer" >$keypress_sec + timer=$(($timer - 1)) + sleep 1 + done + lock -u $keypress_wait + rm -f $keypress_wait + } & + + echo "Press $1<ENTER> $2" + # if we're on the console we wait for input + { + while [ -r $keypress_wait ]; do + timer="$(cat $keypress_sec)" + + [ -n "$timer" ] || timer=1 + timer="${timer%%\ *}" + [ $timer -ge 1 ] || timer=1 + do_failsafe="" + { + read -t "$timer" do_failsafe + if [ "$do_failsafe" = "$1" ]; then + echo "true" >$keypress_true + lock -u $keypress_wait + rm -f $keypress_wait + fi + } + done + } + lock -w $keypress_wait + + trap - INT + trap - USR1 + + keypressed=1 + [ "$(cat $keypress_true)" = "true" ] && keypressed=0 + rm -f $keypress_true + rm -f $keypress_wait + rm -f $keypress_sec + + return $keypressed +} + +failsafe_wait() { + FAILSAFE= + pi_failsafe_net_message=true + preinit_net_echo "Please press button now to enter failsafe" + pi_failsafe_net_message=false + echo -n "Press CTRL-C or " + fs_wait_for_key f 'to enter failsafe mode' $fs_failsafe_wait_timeout && FAILSAFE=true && export FAILSAFE +} + +boot_hook_add preinit_main failsafe_wait + |