9e413320ae414afb849bfb03f4ef9abd018802ff
[myplc.git] / plc.d / db
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: db,v 1.2 2006/10/27 20:27:04 mlhuang Exp $
11 #
12
13 # Source function library and configuration
14 . /etc/plc.d/functions
15 . /etc/planetlab/plc_config
16
17 # Be verbose
18 set -x
19
20 # Export so that we do not have to specify -p to psql invocations
21 export PGPORT=$PLC_DB_PORT
22
23 case "$1" in
24     start)
25         if [ "$PLC_DB_ENABLED" != "1" ] ; then
26             exit 0
27         fi
28
29         MESSAGE=$"Bootstrapping the database"
30         dialog "$MESSAGE"
31
32         # Update the maintenance account username. This can't be
33         # done through the api-config script since it uses the
34         # maintenance account to access the API. The maintenance
35         # account should be person_id 1 since it is created by the
36         # DB schema itself.
37         psql -U $PLC_DB_USER -c "UPDATE persons SET email='$PLC_API_MAINTENANCE_USER' WHERE person_id=1" $PLC_DB_NAME
38
39         # Update the Drupal site_name variable
40         psql -U $PLC_DB_USER drupal <<EOF
41 DELETE FROM variable WHERE name = 'site_name';
42 INSERT INTO variable (name, value) VALUES ('site_name', 's:${#PLC_NAME}:"$PLC_NAME";');
43 EOF
44
45         result "$MESSAGE"
46         ;;
47 esac
48
49 exit $ERRORS