Fix version output when missing.
[plcapi.git] / plc.d / api
1 #!/bin/bash
2 # $Id$
3 # $URL$
4 #
5 # priority: 800
6 #
7 # Configure the API. Must be done after SSL certificates are generated
8 # and before the API web server is brought up.
9 #
10 # Mark Huang <mlhuang@cs.princeton.edu>
11 # Copyright (C) 2006 The Trustees of Princeton University
12 #
13
14 # Source function library and configuration
15 . /etc/plc.d/functions
16 . /etc/planetlab/plc_config
17 local_config=/etc/planetlab/configs/site.xml
18
19 # Be verbose
20 set -x
21
22 case "$1" in
23     start)
24         if [ "$PLC_API_ENABLED" != "1" ] ; then
25             exit 0
26         fi
27
28         MESSAGE=$"Configuring the API"
29         dialog "$MESSAGE"
30
31         # Make sure that the API maintenance account is protected by a
32         # password.
33         if [ -z "$PLC_API_MAINTENANCE_PASSWORD" ] ; then
34             PLC_API_MAINTENANCE_PASSWORD=$(uuidgen)
35             plc-config --category=plc_api --variable=maintenance_password --value="$PLC_API_MAINTENANCE_PASSWORD" --save=$local_config $local_config
36             service plc reload
37         fi
38
39         # Make sure that all PLC servers are allowed to access the API
40         # through the maintenance account.
41         PLC_API_MAINTENANCE_SOURCES=($((
42             for ip in $PLC_API_MAINTENANCE_SOURCES ; do
43                 echo $ip
44             done
45             for server in API BOOT WWW ; do
46                 hostname=PLC_${server}_HOST
47                 gethostbyname ${!hostname}
48             done
49         ) | sort -u))
50         PLC_API_MAINTENANCE_SOURCES=${PLC_API_MAINTENANCE_SOURCES[*]}
51         plc-config --category=plc_api --variable=maintenance_sources --value="$PLC_API_MAINTENANCE_SOURCES" --save=$local_config $local_config
52         service plc reload
53
54         result "$MESSAGE"
55         ;;
56 esac
57
58 exit $ERRORS