File: bootstrap-latest.sh

package info (click to toggle)
gnumed-server 21.11-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 45,408 kB
  • ctags: 3,891
  • sloc: sql: 1,210,640; python: 13,526; sh: 1,476; makefile: 19
file content (92 lines) | stat: -rwxr-xr-x 2,388 bytes parent folder | download
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash

# - should be run as root
# - command line options:
#   - "quiet"

VERSIONS_TO_DROP="2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19"
PREV_VER="20"
VER="21"
QUIET="$1"


if test ! -n "${GM_LOG_BASE}" ; then
	GM_LOG_BASE="."
fi ;


# if you need to adjust the port you want to use to
# connect to PostgreSQL you can use the environment
# variable below (this may be necessary if your PostgreSQL
# server is running on a port different from the default 5432)
#export GM_DB_PORT="5433"


# tell libpq-based tools about the non-default port, if any
if test -n "${GM_DB_PORT}" ; then
	PORT_DEF="-p ${GM_DB_PORT}"
	export PGPORT="${GM_DB_PORT}"
else
	PORT_DEF=""
fi ;


function echo_msg () {
	if test "$QUIET" == "quiet"; then
		return
	fi ;
	echo $1 ;
}


echo_msg "==========================================================="
echo_msg "Bootstrapping latest GNUmed database."
echo_msg ""
echo_msg "This will set up a GNUmed database of version v${VER}"
echo_msg "with the name \"gnumed_v${VER}\"."


# better safe than sorry
ALL_PREV_VERS="${VERSIONS_TO_DROP} ${PREV_VER} ${VER}"
for DB_VER in ${ALL_PREV_VERS} ; do
	VER_EXISTS=`su -c "psql -l ${PORT_DEF}" -l postgres | grep gnumed_v${DB_VER}`
	if test "${VER_EXISTS}" != "" ; then
		echo ""
		echo "------------------------------------------------"
		echo "The database \"gnumed_v${DB_VER}\" already exists."

		echo "Note that during bootstrapping this"
		echo "database will be OVERWRITTEN !"
		echo ""
		echo "Do you really intend to bootstrap or did you"
		echo "rather want to *upgrade* from v${PREV_VER} to v${VER} ?"
		echo ""
		echo "(For upgrading you should run the"
		echo " upgrade script instead.)"
		echo ""
		echo "Continue bootstrapping (deletes databases) ? "
		echo ""
		read -e -p "[yes / NO]: "
		if test "${REPLY}" != "yes" ; then
			echo "Bootstrapping aborted by user."
			exit 1
		fi
	fi
done


LOG="${GM_LOG_BASE}/bootstrap-latest.log"
CONF="bootstrap-latest.conf"
./bootstrap_gm_db_system.py --log-file=${LOG} --conf-file=${CONF} --${QUIET}
if test "$?" != "0" ; then
	echo "Bootstrapping \"gnumed_v${VER}\" did not finish successfully. Aborting."
	read
	exit 1
fi


for DB_VER in ${VERSIONS_TO_DROP} ; do
	echo_msg "Dropping obsoleted staging database gnumed_v${DB_VER} ..."
	echo_msg " (you may need to provide the password for ${USER})"
	su -c "dropdb ${PORT_DEF} gnumed_v${DB_VER}" -l postgres
done