aboutsummaryrefslogtreecommitdiff
path: root/debian/boca-db.postinst
blob: 8a36f555279157b67ad896e0510ad37a8e1e0141 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash

set -e

. /usr/share/debconf/confmodule

priority=high

case "$1" in
  configure|reconfigure)

    #Assume DBHOST will be localhost, since this is the package that
    #provides postgresql
    #XXX future work make it work as a backup DB server
    DBHOST=localhost

    db_get boca-common/dbpassword || true
    PASSWORD="$RET"

    #If we don't have a password from boca-common 2 things could be
    #happened
    #1) dpkg cleaned the password already
    #2) The user did not provide a password
    #So we will ask for a password
    if [[ "x$PASSWORD" == "x" ]]; then
      db_input critical boca-db/dbpassword || true
      db_go || true
      db_get boca-db/dbpassword || true
      PASSWORD="$RET"
      db_reset boca-db/dbpassword
    else
      db_reset boca-common/dbpassword
    fi

    if [[ "x$PASSWORD" == "x" ]]; then
      printf "Generating password with makepasswd"
      PASSWORD="$(makepasswd --chars 20)"
      echo .
      echo "Your DB password is '$PASSWORD' take care of it."
    fi
    export PASSWD="$PASSWORD"
    boca-config-dbhost $DBHOST
    unset PASSWD
    postgresuser=postgres
    su - $postgresuser -c "echo drop user bocauser | psql -d template1 >/dev/null 2>/dev/null"
    su - $postgresuser -c "echo create user bocauser createdb password \'$PASSWORD\'| psql -d template1"
    su - $postgresuser -c "echo alter user bocauser createdb password \'$PASSWORD\'| psql -d template1"

    db_input critical boca-db/createdb || true
    db_go || true

    db_get boca-db/createdb || true

    if  [[ "$RET" == "Yes" ]]; then
      echo YES |php /var/www/boca/src/private/createdb.php
    fi
    db_reset boca-db/createdb

    ;;
  *)
    ;;
esac

service postgresql restart || true

exit 0