]> dev.renevier.net Git - syj.git/blob - scripts/reset.postgres.sh
version 0.1
[syj.git] / scripts / reset.postgres.sh
1 #!/bin/sh
2 set -e
3
4 . ${0%/*}/db_auth.sh
5
6
7 ##
8 # Script for creating and loading database
9 ##
10
11 usage() {
12     echo Usage: ${0##*/} [options]
13     echo
14     echo Options:
15     echo "  " -h display this help message
16     echo "  " -w load database with sample data
17     echo "  " -g resets geographic informations \(geoip and geonames\)
18     echo "  " -s be more silent \(show only warnings\)
19 }
20
21 # getopt
22 WITHDATA=""
23 SILENT=""
24 GEODATA=""
25 args=`getopt -o hwgs -l help,withdata,geo,silent -- "$@"`
26 eval set -- "$args"
27 while true; do
28     case "$1" in
29         -h|--help) usage; exit 0 ;;
30         -w|--withdata) WITHDATA="1"; shift ;;
31         -g|--geo) GEODATA="1"; shift ;;
32         -s|--silent) SILENT="1"; shift ;;
33         --) shift; break ;;
34         *) echo "Invalid option: $1"; exit 1 ;;
35     esac
36 done
37
38 if [ ${#SILENT} -ne 0 ]; then
39     # we won't see all the index creation notices when creating tables
40     export PGOPTIONS='--client_min_messages=warning'
41 fi
42
43 # load schema
44 psql --set "ON_ERROR_STOP=1" -f ${0%/*}/schema.postgres.sql
45
46 # optionally load sample data
47 if [ ${#WITHDATA} -ne 0 ]; then
48     psql --set "ON_ERROR_STOP=1" -f ${0%/*}/data.postgres.sql
49 fi
50
51 if [ ${#GEODATA} -ne 0 ]; then
52     sh ${0%/*}/updategeoip.sh "${@}"
53     sh ${0%/*}/updategeonames.sh "${@}"
54 fi