forked from chilek/lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbinfo_version_bump.sh
executable file
·34 lines (26 loc) · 1.02 KB
/
dbinfo_version_bump.sh
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
#!/bin/bash
PATH="/bin:/sbin:/usr/bin:/usr/sbin"
if [ $# -ne 1 ]; then
echo "Target db schema version is required!"
exit 1
fi
if ! echo $1 |grep -q "^[0-9]\{10\}$" 2>/dev/null; then
echo "Invalid db schema version format!"
exit 2
fi
CWD="`dirname $(readlink -f $0)`"
LMSDIR="${CWD}/.."
schemafile=${LMSDIR}/doc/lms.pgsql
currentversion=`grep "INSERT INTO dbinfo" $schemafile |sed -e "s/^.\+'\([0-9]\+\)'.\+$/\1/g"`
if [ $1 -le $currentversion ]; then
echo "Target db schema version should be greater than current db schema version!"
echo "Current db schema version: $currentversion"
exit 3
fi
sed -i -e "s/^INSERT INTO dbinfo\(.\+\)'\([0-9]\+\)'\(.\+\)$/INSERT INTO dbinfo\1'$1'\3/g" ${LMSDIR}/doc/lms.{mysql,pgsql}
sed -i -e "s/^define('DBVERSION', '\([0-9]\+\)');/define('DBVERSION', '$1');/g" ${LMSDIR}/lib/LMSDB_common.class.php
for dbdriver in mysql postgres; do
if [ ! -f "${LMSDIR}/lib/upgradedb/${dbdriver}.$1.php" ]; then
sed -e "s/%version%/$1/g" ${CWD}/upgradedb.php >${LMSDIR}/lib/upgradedb/${dbdriver}.$1.php
fi
done