subscriberRegistry/debian/postinst

93 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
# postinst script for test
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
configure()
{
DB_LOC=/etc/OpenBTS/sipauthserve.db
DATE=$(date +'%Y-%m-%d.%H:%M:%S')
CONFIG_BACKUP=$DB_LOC.dump-$DATE
if [ ! -e $CONFIG_BACKUP ]; then
sqlite3 $DB_LOC ".dump" > $CONFIG_BACKUP
fi
sqlite3 $DB_LOC ".read /etc/OpenBTS/subscriberRegistry.example.sql" > /dev/null 2>&1
SR_DIR=/var/lib/asterisk/sqlite3dir
SRPATH=$SR_DIR/sqlite3.db
SR_CONFIG_BACKUP=$SRPATH.dump-$DATE
if [ ! -d $SR_DIR ]; then
mkdir -p $SR_DIR
fi
chown -R root:www-data $SR_DIR
chmod 775 $SR_DIR
if [[ -e $SRPATH && "`sqlite3 $SRPATH "PRAGMA table_info(sip_buddies)"`" != "" ]]; then
if [ ! -e $SR_CONFIG_BACKUP ]; then
sqlite3 $SRPATH ".dump" > $SR_CONFIG_BACKUP
fi
HASPREPAID=`sqlite3 $SRPATH "PRAGMA table_info(sip_buddies)" | grep prepaid`
if [ "$HASPREPAID" = "" ]; then
sqlite3 $SRPATH "alter table sip_buddies add prepaid int(1) DEFAULT 0 not null"
fi
HASBALANCE=`sqlite3 $SRPATH "PRAGMA table_info(sip_buddies)" | grep account_balance`
if [ "$HASBALANCE" = "" ]; then
sqlite3 $SRPATH "alter table sip_buddies add column account_balance int(9) default 0"
fi
sqlite3 $SRPATH "create table if not exists rates (service varchar(30) unique not null, rate integer not null)"
sqlite3 $SRPATH "insert or ignore into 'rates' values ('in-network-SMS', 10)"
sqlite3 $SRPATH "insert or ignore into 'rates' values ('out-of-network-SMS', 20)"
sqlite3 $SRPATH "insert or ignore into 'rates' values ('in-network-call', 1)"
sqlite3 $SRPATH "insert or ignore into 'rates' values ('out-of-network-call', 1)"
fi
# set up permissions for webui, temporary fix until ui is replumbed to use json
# directory permissions
if [ -e $SRPATH ]; then
chmod 664 $SR_DIR/sqlite3*
fi
}
case "$1" in
configure)
configure
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0