- don't source shell configuration in /etc/plc.d/functions, which is
[myplc.git] / plc.d / api
1 #!/bin/bash
2 #
3 # priority: 800
4 #
5 # Bootstrap the database
6 #
7 # Mark Huang <mlhuang@cs.princeton.edu>
8 # Copyright (C) 2006 The Trustees of Princeton University
9 #
10 # $Id: api,v 1.2 2006/04/10 16:00:47 mlhuang Exp $
11 #
12
13 # Source function library and configuration
14 . /etc/plc.d/functions
15 . /etc/planetlab/plc_config
16
17 # Export so that we do not have to specify -p to psql invocations
18 export PGPORT=$PLC_DB_PORT
19
20 case "$1" in
21     start)
22         if [ "$PLC_API_ENABLED" != "1" ] ; then
23             exit 0
24         fi
25
26         MESSAGE=$"Bootstrapping the database"
27         dialog "$MESSAGE"
28
29         # Update the maintenance account username. This can't be
30         # done through the api-config script since it uses the
31         # maintenance account to access the API. The maintenance
32         # account should be person_id 1 since it is created by the
33         # DB schema itself.
34         psql -U $PLC_DB_USER -c "UPDATE persons SET email='$PLC_API_MAINTENANCE_USER' WHERE person_id=1" $PLC_DB_NAME
35
36         # Bootstrap the DB
37         api-config
38         check
39
40         result "$MESSAGE"
41         ;;
42 esac
43
44 exit $ERRORS