Created
May 15, 2014 16:14
-
-
Save dz0ny/fcb55e6d04f283a1948c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
# postinst script for bbb | |
# | |
# see: dh_installdeb(1) | |
# | |
# 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> | |
# * <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 | |
# | |
# quoting from the policy: | |
# Any necessary prompting should almost always be confined to the | |
# post-installation script, and should be protected with a conditional | |
# so that unnecessary prompting doesn't happen if a package's | |
# installation fails and the `postinst' is called with `abort-upgrade', | |
# `abort-remove' or `abort-deconfigure'. | |
# escape_quotes borrowed originally from Ubuntu mythtv package | |
#set -x | |
escape_quotes() { | |
cat <<EOF | sed -e "s/'/\\\\'/g" | |
$1 | |
EOF | |
} | |
# DoSQL borrowed originally from Ubuntu mythtv package | |
DoMySQL() { | |
dbtype="$1" | |
host="$2" | |
admin_username="$3" | |
admin_password="$4" | |
database="$5" | |
statement="`escape_quotes \"$6\"`" | |
tmp=`tempfile -m 600` | |
cat <<EOF >$tmp | |
$admin_password | |
EOF | |
perl -e " | |
use DBI; | |
chomp(\$password=<>); | |
@statements=split(/;/, '$statement'); | |
if (\$password eq "xxxx1111") { \$password =\"\"; } | |
\$db = DBI->connect('dbi:mysql:host=$host;database=$database', | |
'$admin_username', \$password, | |
{ PrintError => 0 }) || die 'Failed to connect to database: ' . \$DBI::errstr; | |
for \$s (@statements) { \$db->do(\$s) || die 'Failed to execute SQL: ' . \$s . '\n' . \$DBI::errstr; } | |
" < $tmp | |
ret=$? | |
rm -f $tmp | |
return $ret | |
} | |
check_myinstalled() { | |
test -x /usr/sbin/mysqld || return 1 | |
type mysql >/dev/null 2>&1 || return 1 | |
return 0 | |
} | |
get_config_xx() { | |
db_host="localhost" | |
db_type="mysql" | |
db_port=3306 | |
dba_name="root" | |
db_name="bigbluebutton_dev" | |
dbu_name="bbb" | |
dbu_password="secret" | |
# | |
# Get the webapps context | |
# | |
DEPLOY_DIR=/var/lib/tomcat6/webapps | |
if [ -f /etc/init.d/cloud ]; then | |
if [ -d /var/www/cloud/webapps ]; then | |
DEPLOY_DIR=/var/www/cloud/webapps | |
fi | |
fi | |
# | |
# check if there the root password is null | |
# | |
set +e | |
if [ -f /usr/bin/mysqladmin ]; then | |
mysqladmin -u root flush-privileges >/dev/null 2>&1 | |
if [ $? -eq 0 ] && [ -z "$DEBCONF_RECONFIGURE" ]; then | |
dba_password="xxxx1111" | |
return | |
fi | |
fi | |
set -e | |
# | |
# Get the password from debconf | |
# | |
db_get bbb/dba_password || true | |
dba_password="$RET" | |
# | |
# Test that this now works | |
# | |
set +e | |
if [ -f /usr/bin/mysqladmin ]; then | |
mysqladmin -u root -p$dba_password flush-privileges >/dev/null 2>&1 | |
if [ $? -eq 0 ] && [ -z "$DEBCONF_RECONFIGURE" ]; then | |
return | |
fi | |
fi | |
set -e | |
# | |
# Password is not accepted | |
# | |
db_fset bbb/dba_password seen false | |
db_fset bbb/dba_confirm seen false | |
db_get bbb/dba_password || true | |
db_stop | |
# | |
# Test once more if the password is correct | |
# | |
set +e | |
if [ -f /usr/bin/mysqladmin ]; then | |
mysqladmin -u root -p$dba_password flush-privileges >/dev/null 2>&1 | |
if [ ! $? -eq 0 ]; then | |
echo "# Failed to connect to the mysql database as root to configure BigBlueButton." | |
echo "# To try again type: sudo apt-get remove bbb-web" | |
echo "# To try again type: sudo apt-get install bbb-web" | |
exit 1 | |
fi | |
fi | |
dba_password="$RET" | |
} | |
bbb_new_properties() { | |
IP=$(ifconfig | grep -v '127.0.0.1' | grep -E "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | head -1 | cut -d: -f2 | awk '{ print $1}') | |
# | |
# Setup bigbluebutton.properties for bbb-web | |
# | |
sed -i "s/bigbluebutton.web.serverURL=http:\/\/.*/bigbluebutton.web.serverURL=http:\/\/$IP/g" \ | |
/tmp/bigbluebutton/WEB-INF/classes/bigbluebutton.properties | |
#sed -i "s/redisHost=.*/redisHost=$IP/g" \ | |
# /tmp/bigbluebutton/WEB-INF/classes/bigbluebutton.properties | |
# | |
# Setup bbb_api.jsp | |
# | |
#sed -i "s/BigBlueButtonURL = \"http:\/\/\([^\"\/]*\)\([\"\/]\)/BigBlueButtonURL = \"http:\/\/$IP\2/g" \ | |
# /tmp/bigbluebutton/demo/bbb_api_conf.jsp | |
} | |
bbb_config() { | |
# | |
# We need for Tomcat to deploy the web app | |
# | |
# | |
# At this point. /var/tmp/bigbluebutton.war holds the newer version of BigBlueButton-web | |
# but it's not deployed yet | |
# | |
DEPLOY_DIR=/var/lib/tomcat6/webapps | |
rm -rf /tmp/bigbluebutton | |
unzip /var/bigbluebutton.war -d /tmp/bigbluebutton > /dev/null | |
#echo " | |
#<%! | |
#// This is the security salt that must match the value set in the BigBlueButton server | |
#String salt = \"salt\"; | |
#// This is the URL for the BigBlueButton server | |
#String BigBlueButtonURL = \"http://url/bigbluebutton/\"; | |
#%> | |
#" > /tmp/bigbluebutton/demo/bbb_api_conf.jsp | |
if [ -f $DEPLOY_DIR/bigbluebutton/WEB-INF/classes/bigbluebutton.properties ]; then | |
if grep http:\/\/localhost $DEPLOY_DIR/bigbluebutton/WEB-INF/classes/bigbluebutton.properties; then | |
bbb_new_properties | |
else | |
# echo "Restoring previous /var/lib/tomcat6/webapps/bigbluebutton/WEB-INF/classes/bigbluebutton.properties" | |
VARS=$(cat $DEPLOY_DIR/bigbluebutton/WEB-INF/classes/bigbluebutton.properties | grep = | grep -v \# | sed -e "s/ //g" -e "s/=.*/ /g" | tr -d '\n') | |
for v in $VARS ; do | |
old_val=$(cat $DEPLOY_DIR/bigbluebutton/WEB-INF/classes/bigbluebutton.properties | tr -d '\r' | sed -n "/^${v}[# ]*=[ ]*/{s/${v}[ ]*=[ ]*//;p}" ) | |
# Let's update the older messages | |
if [ "$v" = "defaultWelcomeMessageFooter" ]; then | |
md5=$(echo $old_val | md5sum | cut -f1 -d" ") | |
#echo " #$v# #$old_val# #$md5" | |
if [ "$md5" = "c7374cbb57a99e747629104d3263a3d4" ] || [ "$md5" = "bd9301e498334260650a5077276f2784" ] || [ "$md5" = "348d7494fbfe6b8b18f56da072fdb061" ] || [ "$md5" = "788e73424a377da8119de129e12a0610" ] || [ "$md5" = "c31ba6d944c51ae2812a6ac331f48d5a" ] || [ "$md5" = "af84c5d8bc412141b2959cb2b5a8e756" ] || [ "$md5" = "4ec59572f6297c42b1b4807987553f98" ] || [ "$md5" = "c4aee4866ce1f5ccf2f7f11cd8b720fa" ] || [ "$md5" = "57e4d7b6967b85781a97d2e5610aafd5" ] || [ "$md5" = "66a1507fe03efe487649615cd5311e44" ] || [ "$md5" = "f174d61d4f9119b56032833b4bc0a21a" ]; then | |
#echo "## SKIP" | |
continue | |
fi | |
fi | |
sed -i "s|^$v=.*|$v=$old_val|" /tmp/bigbluebutton/WEB-INF/classes/bigbluebutton.properties | |
done | |
fi | |
else | |
bbb_new_properties | |
fi | |
# | |
# Now update the API examples | |
# | |
HASH="$RANDOM$(date +%s)$$$RANDOM" | |
SALT=$(echo $HASH | md5sum | md5sum | sed 's/ -//') | |
#HOST=$(cat /tmp/bigbluebutton/WEB-INF/classes/bigbluebutton.properties | grep -v \# | sed -n '/bigbluebutton.web.serverURL/{s/.*\///;p}') | |
HOST=$(cat /tmp/bigbluebutton/WEB-INF/classes/bigbluebutton.properties | sed -n '/^bigbluebutton.web.serverURL/{s/.*\///;p}') | |
if [ -f $DEPLOY_DIR/bigbluebutton/WEB-INF/classes/bigbluebutton.properties ]; then | |
if grep -q securitySalt $DEPLOY_DIR/bigbluebutton/WEB-INF/classes/bigbluebutton.properties; then | |
# echo "#Using existing salt in bigbluebutton.properties" | |
SALT=$(cat $DEPLOY_DIR/bigbluebutton/WEB-INF/classes/bigbluebutton.properties | tr -d '\r' | sed -n '/securitySalt/{s/.*=//;p}') | |
fi | |
fi | |
sed -i "s/securitySalt=.*/securitySalt=$SALT/g" \ | |
/tmp/bigbluebutton/WEB-INF/classes/bigbluebutton.properties | |
# sed -i "s/String salt = \".*/String salt = \"$SALT\";/g" /tmp/bigbluebutton/demo/bbb_api_conf.jsp | |
# Added for 0.8 | |
sed -i "s/^apiVersion=.*$/apiVersion=0.81/g" \ | |
/tmp/bigbluebutton/WEB-INF/classes/bigbluebutton.properties | |
#sed -i "s/BigBlueButtonURL = \"http:\/\/\([^\"\/]*\)\([\"\/]\)/BigBlueButtonURL = \"http:\/\/$HOST\2/g" \ | |
# /tmp/bigbluebutton/demo/bbb_api_conf.jsp | |
# | |
# Added for 0.8 to update welcome message if still using the old message | |
# | |
sed -i 's%defaultWelcomeMessage=<br>Welcome to this BigBlueButton Demo Server.<br><br>For help using BigBlueButton <a href="event:http://www.bigbluebutton.org/content/videos"><u>check out these videos</u></a>.<br><br>%defaultWelcomeMessage=<br>Welcome to <b>\%\%CONFNAME\%\%</b>!<br><br>To understand how BigBlueButton works see our <a href="event:http://www.bigbluebutton.org/content/videos"><u>tutorial videos</u></a>.<br><br>To join the audio bridge click the headset icon (upper-left hand corner). <b>Please use a headset to avoid causing echo for others.</b>%g' \ | |
/tmp/bigbluebutton/WEB-INF/classes/bigbluebutton.properties | |
# | |
# We're ready to bigbluebutton.war in tomcat6 | |
# | |
if [ -f /etc/init.d/tomcat6 ]; then | |
/etc/init.d/tomcat6 stop | |
# | |
# Need this here because tomcat6 would have been installed by dependency | |
# on bbb-web | |
# | |
# XXX Can probably remove tis | |
# | |
if grep \#TOMCAT6_SECURITY=yes /etc/default/tomcat6 > /dev/null | |
then | |
# | |
# BigBlueButton-web currently needs tomcat security disabled | |
# | |
# echo "# bbb-web.postinst: Updating /etc/default/tomcat6" | |
sed -i "s/\#TOMCAT6_SECURITY=yes/TOMCAT6_SECURITY=no/g" /etc/default/tomcat6 > /dev/null | |
fi | |
# | |
# Set the appropriate permissions in the /var/log/bigbluebutton | |
# | |
chown -R tomcat6:tomcat6 /var/log/bigbluebutton | |
chmod 755 /var/log/bigbluebutton | |
tmp_dir=$(pwd) | |
cd /tmp/bigbluebutton | |
zip -r bigbluebutton * > /dev/null | |
mv -f bigbluebutton.zip $DEPLOY_DIR/bigbluebutton.war | |
rm -rf $DEPLOY_DIR/bigbluebutton | |
# | |
# Give bbb-web an empty properties file | |
# | |
mkdir -p /usr/share/tomcat6/.grails | |
touch /usr/share/tomcat6/.grails/bigbluebutton-config.properties | |
fi | |
# | |
# Support for Intalio VM | |
# | |
if [ -f /etc/init.d/cloud ]; then | |
# /etc/init.d/cloud stop | |
cat << END > /var/www/cloud/contexts/bigbluebutton.xml | |
<?xml version="1.0"?> | |
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd"> | |
<!-- This context file makes sure that bigbluebutton starts before the other webapps. see CL-112 --> | |
<Configure class="org.eclipse.jetty.webapp.WebAppContext"> | |
<Set name="contextPath">/bigbluebutton</Set> | |
<Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/webapps/bigbluebutton</Set> | |
</Configure> | |
END | |
chown -R cloud /var/log/bigbluebutton | |
chmod 755 /var/log/bigbluebutton | |
chown -R cloud /var/bigbluebutton | |
rm -rf $DEPLOY_DIR/bigbluebutton | |
mv -f /tmp/bigbluebutton $DEPLOY_DIR | |
# | |
# Give bbb-web an empty properties file | |
# | |
mkdir -p /home/cloud/.grails | |
touch /home/cloud/.grails/bigbluebutton-config.properties | |
fi | |
cd $tmp_dir | |
# | |
# Restart tomcat6and deploy the new version | |
# | |
if [ -f /etc/init.d/tomcat6 ]; then | |
/etc/init.d/tomcat6 start | |
fi | |
# | |
# Restart jetty and load the new version | |
# | |
if [ -f /etc/init.d/cloud ]; then | |
echo "" | |
#/etc/init.d/cloud start | |
fi | |
} | |
case "$1" in | |
configure) | |
# | |
# Commented out the need for mysql, but leaving the code here just inc ase | |
# | |
#. /usr/share/debconf/confmodule | |
#db_version 2.0 | |
# Read debconf and edit the config file accordingly | |
#get_config | |
#db_stop | |
# care about the database creation | |
case "$db_type" in | |
x_mysql) | |
if [ "$db_create" = "false" ]; then | |
echo "Remember that you have elected to create your MySQL database manually." >&2 | |
else | |
if ! check_myinstalled; then | |
echo 'Error - You have specified that you wish to use a mysql' >&2 | |
echo 'database, but either mysql-server or mysql-client is ' >&2 | |
echo 'not installed. You must install mysql-server and mysql-client' >&2 | |
echo 'and then reconfigure bbb.' >&2 | |
exit 0 | |
fi | |
if ! DoMySQL "$db_server" "$db_host" "$dba_name" "$dba_password" "$db_name" "SELECT NULL" 2>/dev/null; then | |
if ! DoMySQL "$db_server" "$db_host" "$dba_name" "$dba_password" "" \ | |
"CREATE DATABASE $db_name"; then | |
echo "Failed to create database (incorrect admin username/password?)" >&2 | |
echo "It's also possible that mysql-server wasn't running. After install" >&2 | |
echo "is completed, you will need to make sure mysql-server is running" >&2 | |
echo "and that you supplied correct information. Try:" >&2 | |
echo "sudo dpkg-reconfigure bbb" >&2 | |
exit 0 | |
fi | |
fi | |
DoMySQL "$db_server" "$db_host" "$dba_name" "$dba_password" "$db_name" \ | |
"GRANT ALL PRIVILEGES ON $db_name.* TO $dbu_name@localhost IDENTIFIED BY '$dbu_password'" | |
fi | |
;; | |
esac | |
bbb_config | |
;; | |
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. | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment