Merge pull request #5 from dmulder/master
[ddiss/rapido.git] / dropbear_autorun.sh
1 #!/bin/bash
2 #
3 # Copyright (C) SUSE LINUX GmbH 2016, all rights reserved.
4 #
5 # This library is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as published
7 # by the Free Software Foundation; either version 2.1 of the License, or
8 # (at your option) version 3.
9 #
10 # This library is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
13 # License for more details.
14
15 if [ ! -f /vm_autorun.env ]; then
16         echo "Error: autorun scripts must be run from within an initramfs VM"
17         exit 1
18 fi
19
20 . /vm_autorun.env
21
22 # block ssh client shells from triggering the dracut autorun script
23 if [ -n "$SSH_CLIENT" ]; then
24         export PS1="dropbear:\${PWD}# "
25         return
26 fi
27
28 set -x
29
30 cat /proc/mounts | grep debugfs &> /dev/null
31 if [ $? -ne 0 ]; then
32         mount -t debugfs debugfs /sys/kernel/debug/
33 fi
34
35 cat /proc/mounts | grep configfs &> /dev/null
36 if [ $? -ne 0 ]; then
37         mount -t configfs configfs /sys/kernel/config/
38 fi
39
40 for i in $DYN_DEBUG_MODULES; do
41         echo "module $i +pf" > /sys/kernel/debug/dynamic_debug/control || _fatal
42 done
43 for i in $DYN_DEBUG_FILES; do
44         echo "file $i +pf" > /sys/kernel/debug/dynamic_debug/control || _fatal
45 done
46
47 mkdir --mode=0700 -p /etc/dropbear/ || _fatal
48 if [ -n "$SSH_AUTHORIZED_KEY" ]; then
49         auth_keys_dir="/root/.ssh"
50         mkdir --mode=0700 -p $auth_keys_dir || _fatal
51         echo "$SSH_AUTHORIZED_KEY" >> ${auth_keys_dir}/authorized_keys
52         chmod 0600 ${auth_keys_dir}/authorized_keys || _fatal
53 fi
54
55 dropbear -Rs
56
57 set +x