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