base-files: add support for staged sysupgrades from failsafe mode
[openwrt/openwrt.git] / package / base-files / files / lib / preinit / 99_10_failsafe_login
1 #!/bin/sh
2 # Copyright (C) 2006-2015 OpenWrt.org
3 # Copyright (C) 2010 Vertical Communications
4
5 failsafe_netlogin () {
6 dropbearkey -t rsa -s 1024 -f /tmp/dropbear_failsafe_host_key
7 dropbear -r /tmp/dropbear_failsafe_host_key <> /dev/null 2>&1
8 }
9
10 failsafe_shell() {
11 local console="$(sed -e 's/ /\n/g' /proc/cmdline | grep '^console=' | head -1 | sed -e 's/^console=//' -e 's/,.*//')"
12 [ -n "$console" ] || console=console
13 [ -c "/dev/$console" ] || return 0
14 while true; do
15 ash --login <"/dev/$console" >"/dev/$console" 2>"/dev/$console"
16 sleep 1
17 done &
18 }
19
20 boot_hook_add failsafe failsafe_netlogin
21 boot_hook_add failsafe failsafe_shell