bigbluebutton/bbb-post-install.sh

219 lines
4.4 KiB
Bash
Executable File

#!/usr/bin/env bash
cript_name="$(basename $(realpath $0))"
working_dir="$(dirname $(realpath $0))"
conf_file="${working_dir}/conf/${script_name%%.*}.conf"
LOCK_DIR="/tmp/$(basename $0).$$.LOCK"
log_file="${LOCK_DIR}/${script_name%%.*}.log"
DIST="ubuntu"
DIST_RELEASE="xenial"
FQDN_HOSTNAME="bbb.oopen.de"
HOSTNAME=" ${FQDN_HOSTNAME%%.*}"
# ----------
# Base Function(s)
# ----------
clean_up() {
# Perform program exit housekeeping
rm -rf "$LOCK_DIR"
blank_line
exit $1
}
echononl(){
if $terminal ; then
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
echo -e -n " $*\\c" 1>&2
else
echo -e -n " $*" 1>&2
fi
rm /tmp/shprompt$$
fi
}
fatal(){
echo ""
if $terminal ; then
echo -e " [ \033[31m\033[1mFatal\033[m ] $*"
else
echo -e " [ Fatal ] $*"
fi
echo ""
if $terminal ; then
echo -e " \033[1mScript terminated\033[m.."
else
echo -e " Script terminated.."
fi
echo ""
rm -rf $LOCK_DIR
exit 1
}
error (){
echo ""
if $terminal ; then
echo -e " [ \033[31m\033[1mError\033[m ] $*"
else
echo " [ Error ] $*"
fi
echo ""
}
info () {
if $terminal ; then
echo ""
echo -e " [ \033[32m\033[1minfo\033[m ] $*"
echo ""
fi
}
echo_ok() {
if $terminal ; then
echo -e "\033[85G[ \033[32mok\033[m ]"
fi
}
echo_failed(){
if $terminal ; then
echo -e "\033[85G[ \033[1;31mfailed\033[m ]"
fi
}
echo_skipped() {
if $terminal ; then
echo -e "\033[85G[ \033[33m\033[1mskipped\033[m ]"
fi
}
echo_wait(){
if $terminal ; then
echo -en "\033[85G[ \033[5m\033[1m..\033[m ]"
fi
}
trim() {
local var="$*"
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
echo -n "$var"
}
blank_line() {
if $terminal ; then
echo ""
fi
}
# ----------
# - Jobhandling
# ----------
# - Run 'clean_up' for signals SIGHUP SIGINT SIGTERM
# -
trap clean_up SIGHUP SIGINT SIGTERM
# - Create lock directory '$LOCK_DIR"
#
mkdir "$LOCK_DIR"
# ----------
# - Some checks ..
# ----------
# - Running in a terminal?
# -
if [[ -t 1 ]] ; then
terminal=true
else
fatal "Script must run in a terminal."
fi
# ==========
# - Begin Main Script
# ==========
# ----------
# - Headline
# ----------
if $terminal ; then
echo ""
echo -e "\033[1m----------\033[m"
echo -e "\033[32m\033[1mRunning script \033[m\033[1m$script_name\033[32m .. \033[m"
echo -e "\033[1m----------\033[m"
fi
# Make the HTML5 client default
#
if $terminal ; then
echo ""
echo -e " \033[1mMake the HTML5 client the default client\033[m (no longer load the Flash client)"
echo ""
fi
echononl "Set 'attendeesJoinViaHTML5Client=true'.."
if $(grep -q -E "^\s*attendeesJoinViaHTML5Client=true" \
/usr/share/bbb-web/WEB-INF/classes/bigbluebutton.properties 2> /dev/null) ; then
echo_skipped
else
perl -i -n -p -e "s/^(attendeesJoinViaHTML5Client=.*)/##!\1\nattendeesJoinViaHTML5Client=true/" \
/usr/share/bbb-web/WEB-INF/classes/bigbluebutton.properties > "$log_file" 2>&1
if [[ $? -ne 0 ]]; then
echo_failed
error "$(cat "$log_file")"
else
echo_ok
fi
fi
echononl "Set 'moderatorsJoinViaHTML5Client=true'.."
if $(grep -q -E "^\s*moderatorsJoinViaHTML5Client=true" \
/usr/share/bbb-web/WEB-INF/classes/bigbluebutton.properties 2> /dev/null) ; then
echo_skipped
else
perl -i -n -p -e "s/^(moderatorsJoinViaHTML5Client=.*)/##!\1\nmoderatorsJoinViaHTML5Client=true/" \
/usr/share/bbb-web/WEB-INF/classes/bigbluebutton.properties >> "$log_file" 2>&1
if [[ $? -ne 0 ]]; then
echo_failed
error "$(cat "$log_file")"
else
echo_ok
fi
fi
blank_line
# Assign the server a hostname
#
if $terminal ; then
echo ""
echo -e " \033[1mAssign the server a hostname '$FQDN_HOSTNAME'\033[m"
echo ""
fi
echononl "Trigger command 'bbb-conf --setip $FQDN_HOSTNAME'"
echo_wait
bbb-conf --setip $FQDN_HOSTNAME > "$log_file" 2>&1
if [[ $? -ne 0 ]]; then
echo_failed
error "$(cat "$log_file")"
else
echo_ok
echo -e "
\033[32m----------\033[m
\033[1mOutput from assigning a hostname 'bbb-conf --setip $FQDN_HOSTNAME' was:\033[m
$(cat "$log_file")
\033[32m----------\033[m
"
fi
clean_up 0