Revert to keep the root ssh key around.
[myplc.git] / plc.d / ssh
1 #!/bin/bash
2 # $Id$
3 # $URL$
4 #
5 # priority: 600
6 #
7 # Generate SSH keys
8 #
9 # Mark Huang <mlhuang@cs.princeton.edu>
10 # Copyright (C) 2006 The Trustees of Princeton University
11 #
12 # $Id$
13 #
14
15 # Source function library and configuration
16 . /etc/plc.d/functions
17 . /etc/planetlab/plc_config
18
19 # Be verbose
20 set -x
21
22 # XXX Could make these configurable
23 KEY_TYPE_ROOT=rsa
24 KEY_LEN_ROOT=1024
25 KEY_TYPE_DEBUG=rsa
26 KEY_LEN_DEBUG=2048      
27
28 case "$1" in
29     start)
30         MESSAGE=$"Generating SSH keys"
31         dialog "$MESSAGE"
32
33         tmp=$(mktemp -d /tmp/ssh.XXXXXX)
34
35         # Generate root SSH key
36         if [ ! -f $PLC_ROOT_SSH_KEY_PUB -o ! -f $PLC_ROOT_SSH_KEY ] ; then
37             ssh-keygen -N "" -C "$PLC_NAME Central <$PLC_MAIL_SUPPORT_ADDRESS>" \
38                 -b $KEY_LEN_ROOT -t $KEY_TYPE_ROOT -f $tmp/root
39             check
40             install -D -m 600 $tmp/root $PLC_ROOT_SSH_KEY
41             install -D -m 644 $tmp/root.pub $PLC_ROOT_SSH_KEY_PUB
42         fi
43
44         # Generate debug SSH key
45         if [ ! -f $PLC_DEBUG_SSH_KEY_PUB -o ! -f $PLC_DEBUG_SSH_KEY ] ; then
46             ssh-keygen -N "" -C "$PLC_NAME Central <$PLC_MAIL_SUPPORT_ADDRESS>" \
47                 -b $KEY_LEN_DEBUG -t $KEY_TYPE_DEBUG -f $tmp/debug
48             check
49             install -D -m 600 $tmp/debug $PLC_DEBUG_SSH_KEY
50             install -D -m 644 $tmp/debug.pub $PLC_DEBUG_SSH_KEY_PUB
51         fi
52
53         rm -rf $tmp
54
55         result "$MESSAGE"
56         ;;
57 esac
58
59 exit $ERRORS