#!/bin/sh -e # # $FreeBSD$ # # Script variables SCRIPT="$(basename $0)" BACKUP=".$(date "+%Y.%m.%d_%H:%M:%S")" # System path PREFIX="%%PREFIX%%" RED5_HOME="%%RED5_HOME%%" RED5_LOGS="%%RED5_LOGS%%" RED5_USER="%%RED5_USER%%" RED5_GROUP="%%RED5_GROUP%%" TOMCAT_HOME="%%TOMCAT_HOME%%" TOMCAT_LOGS="%%TOMCAT_LOGS%%" TOMCAT_USER="%%TOMCAT_USER%%" TOMCAT_GROUP="%%TOMCAT_GROUP%%" FREESWITCH_USER="%%FREESWITCH_USER%%" FREESWITCH_GROUP="%%FREESWITCH_GROUP%%" WWWROOT="%%WWWROOT%%" WWWDIR="%%WWWDIR%%" ASTERISK_ETC="$PREFIX/etc/asterisk" FREESWITCH_ETC="$PREFIX/etc/freeswitch" NGINX_ETC="$PREFIX/etc/nginx" # System commands INSTALL_CMD="install -B $BACKUP" # BBB security salt BBB_SALT="" # BBB common BBB_SHAREDIR="%%DATADIR%%" BBB_PRESENTATIONDIR="/var/spool/%%PORTNAME%%" BBB_SRV_LIST="" BBB_INSTALL_CONF="$BBB_PRESENTATIONDIR/conf.txt" # BBB JDBC properties BBB_DATABASE_TYPE="mysql" BBB_DATABASE_HOST="" BBB_DATABASE_NAME="%%PORTNAME%%" BBB_DATABASE_URL="" BBB_DATABASE_DRIVER="com.mysql.jdbc.Driver" BBB_DATABASE_USERNAME="%%PORTNAME%%" BBB_DATABASE_PASSWORD="" # Conference module and type BBB_CONFERENCE_MODULE="" BBB_CONFERENCE_TYPE="" # FreeSWITCH Event Socket Library (ESL) BBB_ESL_HOST="" BBB_ESL_PORT="8021" BBB_ESL_PASSWORD="" # Asterisk Management Interface (AMI) BBB_AMI_HOST="" BBB_AMI_PORT="5038" BBB_AMI_USERNAME="bbb" BBB_AMI_PASSWORD="" # SIP BBB_SIP_HOST="" BBB_SIP_PORT="5070" BBB_SIP_USERNAME="bbbuser" BBB_SIP_PASSWORD="" # All vars list BBB_VAR_LIST="PREFIX WWWROOT WWWDIR \ RED5_HOME RED5_LOGS RED5_USER RED5_GROUP \ TOMCAT_HOME TOMCAT_LOGS TOMCAT_USER TOMCAT_GROUP \ ASTERISK_ETC NGINX_ETC BBB_HOSTNAME BBB_IP_ADDRESS BBB_SALT \ BBB_SHAREDIR BBB_PRESENTATIONDIR BBB_SRV_LIST BBB_INSTALL_CONF \ BBB_DATABASE_TYPE BBB_DATABASE_HOST BBB_DATABASE_NAME BBB_DATABASE_URL \ BBB_DATABASE_DRIVER BBB_DATABASE_USERNAME BBB_DATABASE_PASSWORD \ BBB_CONFERENCE_MODULE BBB_CONFERENCE_TYPE \ BBB_NO_KONFERENCE BBB_NO_MEETME \ BBB_ESL_HOST BBB_ESL_PORT BBB_ESL_PASSWORD \ BBB_AMI_HOST BBB_AMI_PORT BBB_AMI_USERNAME BBB_AMI_PASSWORD \ BBB_SIP_HOST BBB_SIP_PORT BBB_SIP_USERNAME BBB_SIP_PASSWORD" bbb_usage() { cat <<-EOF $1 Install initial configuration: $SCRIPT install -h -c Start all BigBlueButton services: $SCRIPT start Stop all BigBlueButton services: $SCRIPT stop Restart all bbb services: $SCRIPT restart EOF exit 1 } bbb_random() { openssl rand -base64 48 | sed -E 's|[^A-Za-z0-9]||g' | cut -c 1-$1 } bbb_install() { CHECK_PKGS="swftools ImageMagick mysql-server activemq nginx tomcat" CHECK_PKGS="$CHECK_PKGS red5" CHECK_DIRS="RED5_HOME TOMCAT_HOME WWWROOT WWWDIR NGINX_ETC BBB_SHAREDIR" case "$BBB_CONFERENCE_MODULE" in konference|meetme) CHECK_PKGS="$CHECK_PKGS asterisk" CHECK_DIRS="$CHECK_DIRS ASTERISK_ETC" ;; freeswitch) CHECK_PKGS="$CHECK_PKGS freeswitch" CHECK_DIRS="$CHECK_DIRS FREESWITCH_ETC" ;; esac for pkg in $CHECK_PKGS; do echo -n "Check package $pkg: " pkg_info -E ${pkg}\* || usage "$SCRIPT required $pkg package" done for var in $CHECK_DIRS; do eval val=\$$var echo -n "Check $var = '$val': " if [ -n "$val" -a -d "$val" ]; then echo "ok" else echo "not found" exit 2 fi done BBB_SALT="$(bbb_random 32)" BBB_DATABASE_PASSWORD="$(bbb_random 16)" BBB_ESL_PASSWORD="$(bbb_random 16)" BBB_AMI_PASSWORD="$(bbb_random 16)" BBB_SIP_PASSWORD="$(bbb_random 16)" BBB_IP_ADDRESS="$(getent hosts "$BBB_HOSTNAME" | awk '{print $1}')" BBB_DATABASE_HOST="$BBB_IP_ADDRESS" BBB_DATABASE_URL="jdbc:$BBB_DATABASE_TYPE://$BBB_DATABASE_HOST/$BBB_DATABASE_NAME" BBB_ESL_HOST="$BBB_IP_ADDRESS" BBB_AMI_HOST="$BBB_IP_ADDRESS" BBB_SIP_HOST="$BBB_IP_ADDRESS" for var in $BBB_VAR_LIST; do eval val=\$$var BBB_REPLACE="$BBB_REPLACE -e s|%%$var%%|$val|g" done $INSTALL_CMD -d -m 0777 $BBB_PRESENTATIONDIR mkdir -p /etc/rc.conf.d echo "Configure activemq: rc.conf" BBB_SRV_LIST="activemq" cat >/etc/rc.conf.d/activemq <<-EOF activemq_enable="YES" EOF echo -n "Configure $BBB_DATABASE_TYPE: drop/create/grant" (/usr/local/etc/rc.d/mysql-server onestatus || /usr/local/etc/rc.d/mysql-server onestart) >/dev/null 2>&1 mysql -u root >/dev/null <<-EOF drop database if exists $BBB_DATABASE_NAME; create database $BBB_DATABASE_NAME; grant all on $BBB_DATABASE_NAME.* to '$BBB_DATABASE_USERNAME'@'$BBB_DATABASE_HOST' identified by '$BBB_DATABASE_PASSWORD'; commit; EOF echo " rc.conf" BBB_SRV_LIST="$BBB_SRV_LIST mysql-server" cat >/etc/rc.conf.d/mysql <<-EOF mysql_enable="YES" EOF /usr/local/etc/rc.d/mysql-server stop >/dev/null 2>&1 echo -n "Configure $BBB_CONFERENCE_TYPE:" case "$BBB_CONFERENCE_MODULE" in konference|meetme) cd $ASTERISK_ETC for i in extensions sip; do echo -n " bbb_$i.conf" $INSTALL_CMD -m 0600 $BBB_SHAREDIR/asterisk/bbb_$i.conf-dist bbb_$i.conf sed -i '' $BBB_REPLACE bbb_$i.conf done for i in $(jot - 3000 3029); do cat <<-EOF [$i] type=friend username=$i insecure=very qualify=yes nat=yes host=dynamic canreinvite=no context=bbb-voip disallow=all allow=ulaw EOF done >>bbb_sip.conf echo -n " extensions.conf" $INSTALL_CMD -m 0600 extensions.conf-dist extensions.conf cat >>extensions.conf <<-EOF #include "bbb_extensions.conf" EOF echo -n " sip.conf" $INSTALL_CMD -m 0600 sip.conf-dist sip.conf cat >>sip.conf <<-EOF #include "bbb_sip.conf" EOF echo -n " modules.conf" $INSTALL_CMD -m 0600 modules.conf-dist modules.conf case "$BBB_CONFERENCE_MODULE" in konference) cat >>modules.conf <<-EOF noload => codec_dahdi.so noload => app_meetme.so load => app_konference.so EOF ;; meetme) $INSTALL_CMD $PREFIX/etc/zaptel.conf.sample \ $PREFIX/etc/zaptel.conf cat >>modules.conf <<-EOF noload => codec_dahdi.so load => app_meetme.so noload => app_konference.so EOF BBB_SRV_LIST="$BBB_SRV_LIST zaptel" cat >/etc/rc.conf.d/zaptel <<-EOF zaptel_enable="YES" zaptel_kmod_load="zaptel.ko ztdummy.ko" EOF ;; esac echo -n " manager.conf" $INSTALL_CMD -m 0600 manager.conf-dist manager.conf sed -i '' 's|^enabled.*$|enabled = yes|' manager.conf cat >>manager.conf <<-EOF [$BBB_AMI_USERNAME] secret = $BBB_AMI_PASSWORD permit = 0.0.0.0/0.0.0.0 read = system,call,log,verbose,command,agent,user write = system,call,log,verbose,command,agent,user EOF echo " rc.conf" BBB_SRV_LIST="$BBB_SRV_LIST asterisk" cat >/etc/rc.conf.d/asterisk <<-EOF asterisk_enable="YES" EOF ;; freeswitch) cd $FREESWITCH_ETC echo -n " backup" mv conf conf$BACKUP echo -n " extract" (cd $BBB_SHAREDIR/freeswitch && tar cf - conf) | tar xf - chown -R $FREESWITCH_USER:$FREESWITCH_GROUP conf cd conf echo -n " event_socket.conf.xml" $INSTALL_CMD -m 0600 -o $FREESWITCH_USER -g $FREESWITCH_GROUP \ autoload_configs/event_socket.conf.xml-dist \ autoload_configs/event_socket.conf.xml sed -i '' $BBB_REPLACE autoload_configs/event_socket.conf.xml echo -n " acl.conf.xml" $INSTALL_CMD -m 0600 -o $FREESWITCH_USER -g $FREESWITCH_GROUP \ autoload_configs/acl.conf.xml-dist \ autoload_configs/acl.conf.xml sed -i '' $BBB_REPLACE autoload_configs/acl.conf.xml echo -n " $BBB_SIP_USERNAME.xml" $INSTALL_CMD -m 0600 -o $FREESWITCH_USER -g $FREESWITCH_GROUP \ directory/default/bbbuser.xml-dist \ directory/default/$BBB_SIP_USERNAME.xml sed -i '' $BBB_REPLACE directory/default/$BBB_SIP_USERNAME.xml echo " rc.conf" BBB_SRV_LIST="$BBB_SRV_LIST freeswitch" cat >/etc/rc.conf.d/freeswitch <<-EOF freeswitch_enable="YES" freeswitch_flags="-ncwait -waste -nonat" EOF ;; esac echo "Configure openoffice: rc.conf" BBB_SRV_LIST="$BBB_SRV_LIST openoffice" cat >/etc/rc.conf.d/openoffice <<-EOF openoffice_enable="YES" EOF echo -n "Configure tomcat:" chown -R $TOMCAT_USER:$TOMCAT_GROUP $TOMCAT_LOGS cd $TOMCAT_HOME/webapps/bigbluebutton echo -n " bbb_api_conf.jsp" $INSTALL_CMD -m 0600 -o $TOMCAT_USER -g $TOMCAT_GROUP \ demo/bbb_api_conf.jsp-dist \ demo/bbb_api_conf.jsp echo -n " bigbluebutton.properties" $INSTALL_CMD -m 0600 -o $TOMCAT_USER -g $TOMCAT_GROUP \ WEB-INF/classes/bigbluebutton.properties-dist \ WEB-INF/classes/bigbluebutton.properties echo -n " log4j.properties" $INSTALL_CMD -m 0600 -o $TOMCAT_USER -g $TOMCAT_GROUP \ WEB-INF/classes/log4j.properties-dist \ WEB-INF/classes/log4j.properties sed -i '' $BBB_REPLACE demo/bbb_api_conf.jsp \ WEB-INF/classes/bigbluebutton.properties \ WEB-INF/classes/log4j.properties echo " rc.conf" BBB_SRV_LIST="$BBB_SRV_LIST tomcat6" cat >/etc/rc.conf.d/tomcat60 <<-EOF tomcat60_enable="YES" tomcat60_stop_timeout="30" EOF echo -n "Configure red5:" if grep -q '127\.0\.0\.1' $RED5_HOME/conf/red5.properties; then echo -n " red5.properties" sed -i $BACKUP 's|127\.0\.0\.1|0.0.0.0|g' $RED5_HOME/conf/red5.properties fi cd $RED5_HOME/webapps/bigbluebutton/WEB-INF echo -n " red5-web.xml" $INSTALL_CMD -m 0600 -o $RED5_USER -g $RED5_GROUP \ red5-web.xml-dist \ red5-web.xml sed -i '' $BBB_REPLACE red5-web.xml echo -n " bigbluebutton.properties" $INSTALL_CMD -m 0600 -o $RED5_USER -g $RED5_GROUP \ bigbluebutton.properties-dist \ bigbluebutton.properties sed -i '' $BBB_REPLACE bigbluebutton.properties cd $RED5_HOME/webapps/sip/WEB-INF echo -n " bigbluebutton-sip.properties" $INSTALL_CMD -m 0600 -o $RED5_USER -g $RED5_GROUP \ bigbluebutton-sip.properties-dist \ bigbluebutton-sip.properties sed -i '' $BBB_REPLACE bigbluebutton-sip.properties echo " rc.conf" BBB_SRV_LIST="$BBB_SRV_LIST red5" RED5_RMI_PORT=$(awk -F= '/^jmx.rmi.port.registry/{print $2}' $RED5_HOME/conf/red5.properties) RED5_RMI_USER=$(awk '/^[^#].+readwrite$/{print $1}' $RED5_HOME/conf/access.properties | head -1) RED5_RMI_PASSWD=$(awk '/^'$RED5_RMI_USER'[\ \t]+/{print $2}' $RED5_HOME/conf/password.properties) cat >/etc/rc.conf.d/red5 <<-EOF red5_enable="YES" red5_stop_timeout="30" red5_stop_class_opts="$RED5_RMI_PORT $RED5_RMI_USER $RED5_RMI_PASSWD" EOF echo -n "Configure nginx:" cd $NGINX_ETC mkdir -p sites-available sites-enabled echo -n " nginx.conf" $INSTALL_CMD $BBB_SHAREDIR/nginx/nginx.conf-dist nginx.conf echo -n " bigbluebutton.conf" $INSTALL_CMD $BBB_SHAREDIR/nginx/nginx-bigbluebutton.conf-dist \ sites-available/bigbluebutton.conf sed -i '' $BBB_REPLACE nginx.conf sites-available/bigbluebutton.conf cd sites-enabled rm -f bigbluebutton.conf ln -s ../sites-available/bigbluebutton.conf \ bigbluebutton.conf cd $WWWDIR/client/conf echo -n " config.xml" $INSTALL_CMD config.xml-dist config.xml sed -i '' $BBB_REPLACE config.xml echo " rc.conf" BBB_SRV_LIST="$BBB_SRV_LIST nginx" cat >/etc/rc.conf.d/nginx <<-EOF nginx_enable="YES" EOF echo -n "Save config:" $INSTALL_CMD -m 0600 /dev/null $BBB_INSTALL_CONF cat >$BBB_INSTALL_CONF <<-EOF # # ${BACKUP#.} # EOF for var in $BBB_VAR_LIST; do eval val=\$$var cat >>$BBB_INSTALL_CONF <<-EOF $var="$val" EOF done echo " $BBB_INSTALL_CONF" } bbb_start() { for i in $BBB_SRV_LIST; do $PREFIX/etc/rc.d/$i start || true done } bbb_stop() { for i in $BBB_SRV_LIST; do REVERSE_SRV_LIST="$i $REVERSE_SRV_LIST" done for i in $REVERSE_SRV_LIST; do $PREFIX/etc/rc.d/$i stop || true done } bbb_restart() { bbb_stop bbb_start } if [ "`/usr/bin/id -u`" != "0" ]; then bbb_usage "$SCRIPT must be run as root" fi if [ $# -eq 0 ]; then bbb_usage "$SCRIPT [options]" fi BBB_ACTION="$1" shift while getopts :h:c: OPT; do case "$OPT" in h) BBB_HOSTNAME="$OPTARG" ;; c) BBB_CONFERENCE_MODULE="$OPTARG" ;; *) bbb_usage "Error: '$OPTARG' is not a valid option" ;; esac done case "$BBB_ACTION" in install) if [ -z "$BBB_HOSTNAME" ]; then bbb_usage "Error: 'install' action required '-h' option" else if ! getent hosts "$BBB_HOSTNAME" >/dev/null 2>&1; then bbb_usage "Error: hostname '$BBB_HOSTNAME' not found by getent command" fi fi if [ -z "$BBB_CONFERENCE_MODULE" ]; then bbb_usage "Error: 'install' action required '-c' option" else case "$BBB_CONFERENCE_MODULE" in konference) test -f $PREFIX/lib/asterisk/modules/app_konference.so || bbb_usage "Error: app_konference.so not found. Please reinstall %%PORTNAME%% with KONFERENCE option" BBB_CONFERENCE_TYPE="asterisk" BBB_NO_KONFERENCE="" BBB_NO_MEETME=";" ;; meetme) test -f $PREFIX/lib/asterisk/modules/app_meetme.so || bbb_usage "Error: app_meetme.so not found. Please reinstall %%PORTNAME%% with MEETME option" BBB_CONFERENCE_TYPE="asterisk" BBB_NO_KONFERENCE=";" BBB_NO_MEETME="" ;; freeswitch) test -f $PREFIX/bin/freeswitch || bbb_usage "Error: freeswitch not found. Please reinstall %%PORTNAME%% with FREESWITCH option" BBB_CONFERENCE_TYPE="freeswitch" ;; *) bbb_usage "Error: unknown conference module '$BBB_CONFERENCE_TYPE'" ;; esac fi bbb_install ;; start|stop|restart) if [ -n "$BBB_HOSTNAME" -o -n "$BBB_CONFERENCE_MODULE" ]; then bbb_usage "Error: '$BBB_ACTION' action do not allow any options" fi if [ -s "$BBB_INSTALL_CONF" ]; then . $BBB_INSTALL_CONF else bbb_usage "Error: '$BBB_ACTION' action allow only after install" fi eval bbb_$BBB_ACTION ;; *) bbb_usage "Error: '$BBB_ACTION' is not valid action" ;; esac exit 0