davical/davical-setup.sh

Mon, 28 Jan 2013 17:37:18 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Mon, 28 Jan 2013 17:37:18 +0100
changeset 758
a2c6460cfb16
parent 298
e2eb036d448f
permissions
-rw-r--r--

Correct socket error reporting improvement with IPv6 portable code,
after helpful recommendation by Saúl Ibarra Corretgé on OSips devlist.

     1 #!/bin/sh
     2 ##
     3 ##  davical-setup
     4 ##
     6 #   command line argument sanity check
     7 prg="$0"
     8 if [ $# -eq 0 ]; then
     9     echo "$prg:ERROR: invalid command line" 1>&2
    10     echo "$prg:USAGE: $prg install [<admin-password>]" 1>&2
    11     echo "$prg:USAGE: $prg uninstall" 1>&2
    12     echo "$prg:USAGE: $prg edit" 1>&2
    13     exit 1
    14 fi
    16 #   database configuration
    17 db_dir="@l_prefix@/var/davical/db"
    18 db_name="davical"
    19 db_user="davical"
    20 db_pass="davical"
    21 db_sname=`grep "^superuser_database" @l_prefix@/var/postgresql/db/pg_superuser.conf |\
    22           sed -e 's;^ *superuser_database="\(.*\)".*;\1;'`
    23 db_suser=`grep "^superuser_username" @l_prefix@/var/postgresql/db/pg_superuser.conf |\
    24           sed -e 's;^ *superuser_username="\(.*\)".*;\1;'`
    25 db_spass=`grep "^superuser_password" @l_prefix@/var/postgresql/db/pg_superuser.conf |\
    26           sed -e 's;^ *superuser_password="\(.*\)".*;\1;'`
    28 #   dispatch operation
    29 cmd="${1:-"install"}"
    30 shift
    31 case "$cmd" in
    32     install )
    33         #   determine admin password
    34         admin_password="$1"
    35         if [ ".$admin_password" = . ]; then
    36             admin_password="`@l_prefix@/bin/apg -Mncl -a1 -m12 -n1`"
    37             echo "ATTENTION: using generated \"admin\" password: \"$admin_password\"" 1>&2
    38         fi
    40         #   create database
    41         ( echo "CREATE ROLE $db_user LOGIN ENCRYPTED PASSWORD '$db_pass' NOCREATEDB NOCREATEUSER;"
    42           echo "CREATE TABLESPACE $db_name OWNER $db_user LOCATION '$db_dir';"
    43           echo "CREATE DATABASE $db_name OWNER $db_user TABLESPACE $db_name TEMPLATE template0 ENCODING 'UTF8';"
    44         ) | PGPASSWORD="$db_spass" @l_prefix@/bin/psql -q -U "$db_suser" -d "$db_sname" -f-
    46         #   ensure PL/PgSQL language is available
    47         PGPASSWORD="$db_pass" @l_prefix@/bin/psql -q -U "$db_user" -d "$db_name" \
    48             -c "CREATE LANGUAGE plpgsql;"
    50         #   create schema 1/2 (from original "create_database" script)
    51         PGPASSWORD="$db_pass" @l_prefix@/bin/psql -q -U "$db_user" -d "$db_name" -A -t \
    52             -f "@l_prefix@/lib/davical/awl/dba/awl-tables.sql" 2>&1 | grep -v NOTICE
    53         PGPASSWORD="$db_pass" @l_prefix@/bin/psql -q -U "$db_user" -d "$db_name" -A -t \
    54             -f "@l_prefix@/lib/davical/awl/dba/schema-management.sql" 2>&1 | grep -v NOTICE
    55         PGPASSWORD="$db_pass" @l_prefix@/bin/psql -q -U "$db_user" -d "$db_name" -A -t \
    56             -f "@l_prefix@/lib/davical/davical/dba/davical.sql" 2>&1 | grep -v NOTICE
    57         PGPASSWORD="$db_pass" @l_prefix@/bin/psql -q -U "$db_user" -d "$db_name" -A -t \
    58             -f "@l_prefix@/lib/davical/davical/dba/base-data.sql" 2>&1 | grep -v NOTICE
    60         #   create schema 2/3 (from nowhere, but required by appuser_permissions.txt below)
    61         PGPASSWORD="$db_pass" @l_prefix@/bin/psql -q -U "$db_user" -d "$db_name" -A -t \
    62             -f "@l_prefix@/lib/davical/davical/dba/views/dav_principal.sql" 2>&1 | grep -v NOTICE
    64         #   create schema 3/3 (from original "update-davical-database" script)
    65         PGPASSWORD="$db_pass" @l_prefix@/bin/psql -q -U "$db_user" -d "$db_name" -A -t \
    66             -f "@l_prefix@/lib/davical/davical/dba/supported_locales.sql" 2>&1 | grep -v NOTICE
    67         PGPASSWORD="$db_pass" @l_prefix@/bin/psql -q -U "$db_user" -d "$db_name" -A -t \
    68             -f "@l_prefix@/lib/davical/davical/dba/caldav_functions.sql" 2>&1 | egrep -v '(NOTICE|ERROR)'
    69         PGPASSWORD="$db_pass" @l_prefix@/bin/psql -q -U "$db_user" -d "$db_name" -A -t \
    70             -f "@l_prefix@/lib/davical/davical/dba/rrule_functions.sql" 2>&1 | egrep -v '(NOTICE|ERROR)'
    71         PGPASSWORD="$db_spass" @l_prefix@/bin/psql -q -U "$db_suser" -d "$db_name" -A -t \
    72             -f "@l_prefix@/lib/davical/davical/dba/appuser_permissions.txt" 2>&1 | grep -v NOTICE
    74         #   set admin password
    75         PGPASSWORD="$db_pass" @l_prefix@/bin/psql -q -U "$db_user" -d "$db_name" \
    76             -c "UPDATE usr SET password = '**$admin_password' WHERE user_no = 1;"
    77         ;;
    79     uninstall )
    80         #   destroy PL/PgSQL language
    81         PGPASSWORD="$db_pass" @l_prefix@/bin/psql -q -U "$db_user" -d "$db_name" \
    82             -c "DROP LANGUAGE plpgsql CASCADE;" 2>&1 | grep -v NOTICE
    84         #   destroy database
    85         ( echo "DROP DATABASE $db_name;"
    86           echo "DROP TABLESPACE $db_name;"
    87           echo "DROP ROLE $db_user;"
    88         ) | PGPASSWORD="$db_spass" @l_prefix@/bin/psql -q -U "$db_suser" -d "$db_sname" -f-
    89         ;;
    91     edit )
    92         #   edit database
    93         PGPASSWORD="$db_spass" @l_prefix@/bin/psql -U "$db_suser" -d "$db_name"
    94         ;;
    95 esac

mercurial