File: initialize_db.sh

package info (click to toggle)
tryton-server 7.0.30-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 7,756 kB
  • sloc: python: 53,218; xml: 5,194; sh: 802; sql: 217; makefile: 28
file content (41 lines) | stat: -rwxr-xr-x 1,250 bytes parent folder | download | duplicates (2)
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
#!/bin/sh

. /usr/share/debconf/confmodule

admin_password=$(cat /dev/urandom | tr -dc "[:print:]" | head -c 32)
admin_email="root@localhost"
dbc_name="tryton"

# get database settings from dbconfig-common
if [ -f /etc/dbconfig-common/tryton-server-postgresql.conf ]; then
    . /etc/dbconfig-common/tryton-server-postgresql.conf
fi

db_get tryton-server-postgresql/db-admin-password
if [ ! -z "$RET" ]; then
    admin_password="$RET"
fi
db_get tryton-server-postgresql/db-admin-email
if [ ! -z "$RET" ]; then
    admin_email="$RET"
fi

TRYTONPASSFILE=`mktemp`
export TRYTONPASSFILE
echo "$admin_password" > "$TRYTONPASSFILE"
unset admin_password

# The new configuration file is not yet in place, we construct the database url and use that
uri="postgresql://$dbc_dbuser:$dbc_dbpass@$dbc_dbserver"
if [ ! -z "$dbc_dbport" ]; then
    uri="$uri:$dbc_dbport"
fi
uri="$uri"/
export TRYTOND_DATABASE_URI="$uri"

#/usr/bin/trytond-admin -c /etc/tryton/trytond.conf -d "$dbc_name"  --password --email "$admin_email" --all
/usr/bin/trytond-admin -d "$dbc_name" --password --email "$admin_email" --all

# cleanup sensible data
[ "$TRYTONPASSFILE" ] && rm -f "$TRYTONPASSFILE"
#echo UNREGISTER db-admin-password | debconf-communicate tryton-server-postgresql