52f6aed4fcfcb028717815cd85711ea84183ce35
[myplc.git] / plc.d / gpg
1 #!/bin/bash
2 #
3 # priority: 500
4 #
5 # Generate GPG keys
6 #
7 # Mark Huang <mlhuang@cs.princeton.edu>
8 # Copyright (C) 2006 The Trustees of Princeton University
9 #
10 # $Id: gpg,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 case "$1" in
18     start)
19         # Generate GPG keyrings
20         if [ ! -f $PLC_ROOT_GPG_KEY_PUB -o ! -f $PLC_ROOT_GPG_KEY ] ; then
21             MESSAGE=$"Generating GPG keys"
22             dialog "$MESSAGE"
23
24             mkdir -p $(dirname $PLC_ROOT_GPG_KEY_PUB)
25             mkdir -p $(dirname $PLC_ROOT_GPG_KEY)
26
27             # Temporarily replace /dev/random with /dev/urandom to
28             # avoid running out of entropy.
29             rm -f /dev/random
30             mknod /dev/random c 1 9
31             gpg --homedir=/root --batch --gen-key <<EOF
32 Key-Type: DSA
33 Key-Length: 1024
34 Subkey-Type: ELG-E
35 Subkey-Length: 1024
36 Name-Real: $PLC_NAME Central
37 Name-Comment: http://$PLC_WWW_HOST/
38 Name-Email: $PLC_MAIL_SUPPORT_ADDRESS
39 Expire-Date: 0
40 %pubring $PLC_ROOT_GPG_KEY_PUB
41 %secring $PLC_ROOT_GPG_KEY
42 %commit
43 EOF
44             check
45             rm -f /dev/random
46             mknod /dev/random c 1 8
47             chmod 600 $PLC_ROOT_GPG_KEY_PUB $PLC_ROOT_GPG_KEY
48
49             result "$MESSAGE"
50         fi
51         ;;
52 esac
53
54 exit $ERRORS