summaryrefslogtreecommitdiffstats
path: root/rescue/startssh
diff options
context:
space:
mode:
authorMaarten Vanraes <alien@mageia.org>2012-02-25 20:52:44 +0000
committerMaarten Vanraes <alien@mageia.org>2012-02-25 20:52:44 +0000
commitac0671924c327f3d0435842757d01a2e3a2bee25 (patch)
treeb52528c86675b4889df3a25274e2b9e3bdf2a3a5 /rescue/startssh
parent843d674af78b9e781c941ecd8f8a8b128a69281a (diff)
downloaddrakx-ac0671924c327f3d0435842757d01a2e3a2bee25.tar
drakx-ac0671924c327f3d0435842757d01a2e3a2bee25.tar.gz
drakx-ac0671924c327f3d0435842757d01a2e3a2bee25.tar.bz2
drakx-ac0671924c327f3d0435842757d01a2e3a2bee25.tar.xz
drakx-ac0671924c327f3d0435842757d01a2e3a2bee25.zip
add some tests and error handling in startssh
Diffstat (limited to 'rescue/startssh')
-rwxr-xr-xrescue/startssh25
1 files changed, 16 insertions, 9 deletions
diff --git a/rescue/startssh b/rescue/startssh
index 48bba7cbc..0a88820de 100755
--- a/rescue/startssh
+++ b/rescue/startssh
@@ -1,20 +1,27 @@
#!/bin/bash
-passwd=`genpasswd`
+# test for an up interface != lo
+if test "x"`ifconfig | cut -d ' ' -f 1 | grep -v '^$' | grep -v lo` = "x"; then
+ echo "There is no up interface, you can try to execute 'drvinst' to find drivers and 'dhcp-client' to configure your interface for DHCP." >&2
+ exit 5
+fi
+
+# generate host keys
+mkdir -p /etc/dropbear
+[[ -f /etc/dropbear/dropbear_dss_host_key ]] || dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key >/dev/null || { echo "Can't generate dsa host key" >&2 ; exit 4 }
+[[ -f /etc/dropbear/dropbear_rsa_host_key ]] || dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key >/dev/null || { echo "Can't generate rsa host key" >&2 ; exit 3 }
+# set a password
+passwd=`genpasswd`
if (( $? != 0 )); then
reset
exit $?
fi
+sed -E -i -e 's/^root:[^:]*:/root:'"$passwd"':/' /etc/passwd || { echo "Can't set password" >&2 ; exit 2 }
-# change passwd file
-sed -E -i -e 's/^root:[^:]*:/root:'"$passwd"':/' /etc/passwd
-
-# generate host keys
-mkdir -p /etc/dropbear
-[[ -f /etc/dropbear/dropbear_dss_host_key ]] || dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key >/dev/null
-[[ -f /etc/dropbear/dropbear_rsa_host_key ]] || dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key >/dev/null
+# test for /dev/pts
+grep '^devpts /dev/pts devpts ' /proc/mounts >/dev/null 2>/dev/null || mount -t devpts devpts /dev/pts
echo ""
echo -n "Starting ssh daemon... "
-dropbear -E 2>/var/log/dropbear.log && echo "OK"
+dropbear -E 2>/var/log/dropbear.log && echo "OK" || { echo "Failed" ; exit 1 }