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