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