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