- split up guest.init (/etc/init.d/plc inside the chroot) into
[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: 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 case "$1" in
17     start)
18         # Generate GPG keyrings
19         if [ ! -f $PLC_ROOT_GPG_KEY_PUB -o ! -f $PLC_ROOT_GPG_KEY ] ; then
20             MESSAGE=$"Generating GPG keys"
21             dialog "$MESSAGE"
22
23             mkdir -p $(dirname $PLC_ROOT_GPG_KEY_PUB)
24             mkdir -p $(dirname $PLC_ROOT_GPG_KEY)
25
26             # Temporarily replace /dev/random with /dev/urandom to
27             # avoid running out of entropy.
28             rm -f /dev/random
29             mknod /dev/random c 1 9
30             gpg --homedir=/root --batch --gen-key <<EOF
31 Key-Type: DSA
32 Key-Length: 1024
33 Subkey-Type: ELG-E
34 Subkey-Length: 1024
35 Name-Real: $PLC_NAME Central
36 Name-Comment: http://$PLC_WWW_HOST/
37 Name-Email: $PLC_MAIL_SUPPORT_ADDRESS
38 Expire-Date: 0
39 %pubring $PLC_ROOT_GPG_KEY_PUB
40 %secring $PLC_ROOT_GPG_KEY
41 %commit
42 EOF
43             check
44             rm -f /dev/random
45             mknod /dev/random c 1 8
46             chmod 600 $PLC_ROOT_GPG_KEY_PUB $PLC_ROOT_GPG_KEY
47
48             result "$MESSAGE"
49         fi
50         ;;
51 esac
52
53 exit $ERRORS