base-files: allow users to delect debug level during boot
[openwrt.git] / package / base-files / files / lib / preinit / 30_failsafe_wait
index 3c5ece9..5225659 100644 (file)
@@ -5,7 +5,7 @@
 fs_wait_for_key () {
     local timeout=$3
     local timer
-    local do_failsafe
+    local do_keypress
     local keypress_true="$(mktemp)"
     local keypress_wait="$(mktemp)"
     local keypress_sec="$(mktemp)"
@@ -40,6 +40,7 @@ fs_wait_for_key () {
     } &
 
     echo "Press the [$1] key and hit [enter] $2"
+    echo "Press the [1], [2], [3] or [4] key and hit [enter] to select the debug level"
     # if we're on the console we wait for input
     { 
        while [ -r $keypress_wait ]; do
@@ -48,14 +49,22 @@ fs_wait_for_key () {
            [ -n "$timer" ] || timer=1
            timer="${timer%%\ *}"
            [ $timer -ge 1 ] || timer=1
-           do_failsafe=""
+           do_keypress=""
            {
-               read -t "$timer" do_failsafe
-               if [ "$do_failsafe" = "$1" ]; then
-                   echo "true" >$keypress_true
-                   lock -u $keypress_wait
-                   rm -f $keypress_wait
-               fi
+               read -t "$timer" do_keypress
+               case "$do_keypress" in
+               $1)
+                       echo "true" >$keypress_true
+                       ;;
+               1 | 2 | 3 | 4)
+                       echo "$do_keypress" >/tmp/debug_level
+                       ;;
+               *)
+                       continue;
+                       ;;
+               esac
+               lock -u $keypress_wait
+               rm -f $keypress_wait
            }
        done
     }
@@ -79,7 +88,7 @@ failsafe_wait() {
       preinit_net_echo "Please press button now to enter failsafe"
       pi_failsafe_net_message=false
       fs_wait_for_key f 'to enter failsafe mode' $fs_failsafe_wait_timeout && FAILSAFE=true
-      [ -f "/tmp/failsafe_button" ] && FAILSAFE=true
+      [ -f "/tmp/failsafe_button" ] && FAILSAFE=true && echo "- failsafe button "`cat /tmp/failsafe_button`" was pressed -"
       [ "$FAILSAFE" = "true" ] && export FAILSAFE && touch /tmp/failsafe
     fi
 }