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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#!/bin/bash
set -e
. /usr/share/debconf/confmodule
if [ "$DPKG_DEBUG" = "developer" ]; then
set -x
fi
db_version 2.0
get_db_params () {
db_get "sitebar/db_host"
dbserver="$RET"
db_get "sitebar/db_name"
dbname="$RET"
db_get "sitebar/db_admin_user"
dbadmin="$RET"
db_get "sitebar/db_admin_pass"
dbadmpass="$RET"
db_get "sitebar/db_user"
dbuser="$RET"
db_get "sitebar/db_pass"
dbpass="$RET"
dbtype=mysql
}
# check to see if mysql is running, start if not
if [ -f /usr/sbin/mysqld ] ; then
mysqld_get_param() {
/usr/sbin/mysqld --print-defaults | tr " " "\n" | grep -- "--$1" | tail -n 1 | cut -d= -f2
}
pidfile=`mysqld_get_param pid-file`
ps_alive=0
if [ -f "$pidfile" ] && ps `cat $pidfile` >/dev/null 2>&1; then ps_alive=1; fi
if [ $ps_alive = 0 ]; then /usr/bin/mysqld_safe > /dev/null 2>&1 & fi
fi
case "$1" in
configure)
config="/etc/sitebar/config.inc.php"
template="/usr/share/sitebar/inc/config.inc.php.template"
db_get "sitebar/webserver"
webservers="$RET"
. /usr/share/wwwconfig-common/php.get
. /usr/share/wwwconfig-common/apache-run.get
# setup the webserver
for server in $webservers ; do
server=$(echo $server | sed 's/,$//')
servers="$server $servers"
if [ -d "/etc/${server}/conf.d" ] ; then
if ! [ -e "/etc/${server}/conf.d/sitebar.conf" ] ; then
ln -sf /etc/sitebar/apache.conf "/etc/${server}/conf.d/sitebar"
fi
else
includefile="/etc/sitebar/apache.conf"
. /usr/share/wwwconfig-common/apache-include_all.sh
fi
for index in index.php index.php3; do
. /usr/share/wwwconfig-common/apache-index_all.sh
done
done
db_get "sitebar/restart-webserver"
if [ "$RET" != "false" ]; then
restart="${servers}"
. /usr/share/wwwconfig-common/restart.sh
fi
# setup the db
if [ -f /usr/sbin/mysqld ] ; then
pidfile=`mysqld_get_param pid-file`
ps_alive=0
if [ -f "$pidfile" ] && ps `cat $pidfile` >/dev/null 2>&1; then ps_alive=1; fi
if [ $ps_alive = 1 ]; then
db_get "sitebar/db_initialized"
dbinitialized="$RET" || true
db_get "sitebar/skipdb"
skipdb="$RET"
if [ "$skipdb" != "true" ]; then
get_db_params
if [ "$db_initialized" != "true" ]; then
. /usr/share/wwwconfig-common/mysql-createdb.sh
. /usr/share/wwwconfig-common/mysql-createuser.sh
sqlfile=/usr/share/sitebar/sql/install.sql
. /usr/share/wwwconfig-common/mysql-exec.sh
# Expand our config file
varscript="s#{DB_USER}#${dbuser}#g;s#{DB_PASS}#${dbpass}#g;s#{DB_HOST}#${dbserver}#g;s#{DB_NAME}#${dbname}#g;";
sed $varscript < $template > $config
chown root:www-data $config
chmod 640 $config
db_set "sitebar/db_initialized" true
fi # $db_initialized
dbadmin=${dbuser}
dbadmpass=${dbpass}
. /usr/share/wwwconfig-common/mysql.get
# Check for upgrades in a loop
upgrade_complete="false"
while [ "$upgrade_complete" != "true" ]; do
# what version are we at?
sitebar_dbver=$(eval $mysqlcmd -D ${dbname} -e "'SELECT sitebar_config.release FROM sitebar_config;'" -s)
sqlfile="/usr/share/sitebar/sql/upgrade_${sitebar_dbver}.sql"
if [ -e "$sqlfile" ]; then
. /usr/share/wwwconfig-common/mysql-exec.sh
else
upgrade_complete="true"
fi
done
fi # $skipdb
fi
fi
# erase db admin password
if [ "$skipdb" != "true" ]; then
db_reset "sitebar/db_admin_pass"
fi
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 0
;;
esac
#DEBHELPER#
db_stop
exit 0
|