1476cf1f79a23b029c3134bab198af95a0f31626
[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: guest.init,v 1.12 2006/04/04 22:09:47 mlhuang Exp $
11 #
12
13 # Source function library and configuration
14 . /etc/plc.d/functions
15
16 # XXX Could make these configurable
17 KEY_TYPE_ROOT=rsa
18 KEY_LEN_ROOT=1024
19 KEY_TYPE_DEBUG=rsa
20 KEY_LEN_DEBUG=2048      
21
22 case "$1" in
23     start)
24         MESSAGE=$"Generating SSH keys"
25         dialog "$MESSAGE"
26
27         tmp=$(mktemp -d /tmp/ssh.XXXXXX)
28
29         # Generate root SSH key
30         if [ ! -f $PLC_ROOT_SSH_KEY_PUB -o ! -f $PLC_ROOT_SSH_KEY ] ; then
31             ssh-keygen -N "" -C "$PLC_NAME Central <$PLC_MAIL_SUPPORT_ADDRESS>" \
32                 -b $KEY_LEN_ROOT -t $KEY_TYPE_ROOT -f $tmp/root
33             check
34             install -D -m 600 $tmp/root $PLC_ROOT_SSH_KEY
35             install -D -m 644 $tmp/root.pub $PLC_ROOT_SSH_KEY_PUB
36         fi
37
38         # Generate debug SSH key
39         if [ ! -f $PLC_DEBUG_SSH_KEY_PUB -o ! -f $PLC_DEBUG_SSH_KEY ] ; then
40             ssh-keygen -N "" -C "$PLC_NAME Central <$PLC_MAIL_SUPPORT_ADDRESS>" \
41                 -b $KEY_LEN_DEBUG -t $KEY_TYPE_DEBUG -f $tmp/debug
42             check
43             install -D -m 600 $tmp/debug $PLC_DEBUG_SSH_KEY
44             install -D -m 644 $tmp/debug.pub $PLC_DEBUG_SSH_KEY_PUB
45         fi
46
47         rm -rf $tmp
48
49         result "$MESSAGE"
50         ;;
51 esac
52
53 exit $ERRORS