Debian Codegraph @

scripts/kxc-add-key

raw symbols SCIP
1 #!/bin/bash
2 #
3 # Add a new key to kxc's configuration (initializing it if necessary).
4 #
5 # If /etc/kxc is missing, this script creates it, as well as the required
6 # client certificates.
7 #
8 # Then, it adds configuration for fetching a given key.
9
10 set -e
11
12 SERVER="$1"
13 KEYNAME="$2"
14
15 if [ "$SERVER" = "" ] || [ "$KEYNAME" = "" ]; then
16 echo "
17 Usage: kxc-add-key <server hostname> <key name>
18
19 This command adds a new key to kxc's configuration, initializing it if
20 necessary.
21 "
22 exit 1
23 fi
24
25
26 # Create the base configuration directory.
27 echo "Creating directories (/etc/kxc/)"
28 mkdir -p /etc/kxc/
29
30 # Create a private key for the client.
31 if ! [ -e /etc/kxc/key.pem ]; then
32 kxgencert \
33 -organization "kxc@$HOSTNAME" \
34 -key /etc/kxc/key.pem \
35 -cert /etc/kxc/cert.pem
36 chmod 400 /etc/kxc/key.pem
37 else
38 echo "Private key already exists (/etc/kxc/key.pem)"
39 fi
40
41 echo "Setting URL to kxd://$SERVER/$HOSTNAME/$KEYNAME"
42 echo "kxd://$SERVER/$HOSTNAME/$KEYNAME" > "/etc/kxc/${KEYNAME}.url"
43
44 echo
45 echo
46 echo "YOU need to copy the server certificate to"
47 echo "/etc/kxc/${KEYNAME}.server_cert.pem. For example, using:"
48 echo
49 echo " $ scp $SERVER:/etc/kxd/cert.pem /etc/kxc/${KEYNAME}.server_cert.pem"
50 echo