500 lines
10 KiB
Bash
Executable File
500 lines
10 KiB
Bash
Executable File
#!/usr/bin/env bash
|
||
|
||
script_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"
|
||
|
||
|
||
# ----------
|
||
# 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 ""
|
||
}
|
||
|
||
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
|
||
|
||
FQDN_HOSTNAME=
|
||
echo ""
|
||
echo -e "\033[32m--\033[m"
|
||
echo ""
|
||
echo "Insert full qualified hostname for BigBlueButton Service"
|
||
echo ""
|
||
if [[ -n "$_FQDN_HOSTNAME" ]]; then
|
||
echononl "Full qualified hostname [${_FQDN_HOSTNAME}]: "
|
||
read FQDN_HOSTNAME
|
||
if [[ "X${FQDN_HOSTNAME}" = "X" ]]; then
|
||
FQDN_HOSTNAME=$_FQDN_HOSTNAME
|
||
fi
|
||
else
|
||
while [[ "X${FQDN_HOSTNAME}" = "X" ]]; do
|
||
echononl "Full qualified hostname: "
|
||
read FQDN_HOSTNAME
|
||
if [[ "X${FQDN_HOSTNAME}" = "X" ]]; then
|
||
echo -e "\n\t\033[33m\033[1mFull qualified hostname is reqired\033[m\n"
|
||
fi
|
||
done
|
||
fi
|
||
|
||
HOSTNAME="${FQDN_HOSTNAME%%.*}"
|
||
|
||
echo ""
|
||
echo ""
|
||
echo -e "\t\033[32mStart pre-install script for BigBlueButton Service with the following parameters\033[m"
|
||
echo ""
|
||
echo -e "\tFull qualified Hostname..: $FQDN_HOSTNAME"
|
||
echo -e "\tHostname.................: $HOSTNAME"
|
||
echo ""
|
||
echononl "einverstanden (yes/no): "
|
||
read OK
|
||
OK=${OK,,}
|
||
while [ "X$OK" != "Xyes" -a "X$OK" != "Xno" ]; do
|
||
echononl "Wrong entry! [yes/no]: "
|
||
read OK
|
||
OK=${OK,,}
|
||
done
|
||
[ $OK = "yes" ] || fatal Repeat with other settings..
|
||
|
||
echo ""
|
||
echo ""
|
||
|
||
|
||
|
||
|
||
# /etc/resolf.conf
|
||
#
|
||
#echononl "Remove symlink '/etc/resolv.conf'.."
|
||
#if [[ -h "/etc/resolv.conf" ]]; then
|
||
# rm /etc/resolv.conf > $log_file 2>&1
|
||
# if [[ $? -ne 0 ]]; then
|
||
# echo_failed
|
||
# error "$(cat "$log_file")"
|
||
# else
|
||
# echo_ok
|
||
# fi
|
||
#else
|
||
# echo_skipped
|
||
#fi
|
||
#
|
||
#echononl "Create new file '/etc/resolv.conf'.."
|
||
#cat <<EOF > /etc/resolv.conf 2> $log_file
|
||
#### Hetzner Online GmbH installimage
|
||
## nameserver config
|
||
#nameserver 213.133.100.100
|
||
#nameserver 213.133.98.98
|
||
#nameserver 213.133.99.99
|
||
#nameserver 2a01:4f8:0:1::add:9898
|
||
#nameserver 2a01:4f8:0:1::add:1010
|
||
#nameserver 2a01:4f8:0:1::add:9999
|
||
#EOF
|
||
#if [[ $? -ne 0 ]]; then
|
||
# echo_failed
|
||
# error "$(cat "$log_file")"
|
||
#else
|
||
# echo_ok
|
||
#fi
|
||
|
||
|
||
echononl "Set FQDN hostname (IPv4).."
|
||
perl -i -n -p -e "s/^127\.0\.1\.1.*/127.0.1.1 $FQDN_HOSTNAME $HOSTNAME/" /etc/hosts > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
blank_line
|
||
|
||
echononl "Create sources.list for '$DIST $DIST_RELEASE'.."
|
||
cat <<EOF > /etc/apt/sources.list 2> "$log_file"
|
||
deb http://archive.ubuntu.com/ubuntu ${DIST_RELEASE} main restricted universe multiverse
|
||
deb http://archive.ubuntu.com/ubuntu ${DIST_RELEASE}-updates main restricted universe multiverse
|
||
|
||
deb http://security.ubuntu.com/ubuntu ${DIST_RELEASE}-security main restricted universe multiverse
|
||
|
||
deb http://archive.ubuntu.com/ubuntu ${DIST_RELEASE}-backports main restricted universe multiverse
|
||
EOF
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
echononl "Update repositories.."
|
||
apt-get update > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
echononl "Upgrade System.."
|
||
apt-get --yes dist-upgrade > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
blank_line
|
||
|
||
|
||
# Set the locale of the server to 'en_US.UTF-8'.
|
||
|
||
echononl "Install 'language-pack-en'.."
|
||
apt-get install --yes language-pack-en > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
echononl "Set the locale of the server to 'en_US.UTF-8'.."
|
||
update-locale LANG=en_US.UTF-8 > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
echononl "Set system environment to 'en_US.UTF-8'.."
|
||
systemctl set-environment LANG=en_US.UTF-8 > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
blank_line
|
||
|
||
|
||
# BigBlueButton’s components, such as Tomcat, need a source of entropy when starting up.
|
||
#
|
||
echononl "Install 'haveged'.."
|
||
apt-get install --yes haveged > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
echononl "Install 'software-properties-common'.."
|
||
apt-get install --yes software-properties-common -y > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
blank_line
|
||
|
||
|
||
# Add reposototies for 'ffmpeg' (create recordings) and 'yq' (update YAML files)
|
||
#
|
||
# Note:
|
||
# The default version of ffmpeg in Ubuntu 16.04 is old and yq does not exist
|
||
# in the default repositories
|
||
#
|
||
echononl "Add repository for 'ffmpeg' .."
|
||
add-apt-repository ppa:bigbluebutton/support -y > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
echononl "Add repository for 'yq'.."
|
||
add-apt-repository ppa:rmescandon/yq -y > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
echononl "Update repositories.."
|
||
apt-get update > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
echononl "Upgrade System.."
|
||
apt-get --yes dist-upgrade > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
blank_line
|
||
|
||
# add repository for mongodb
|
||
#
|
||
echononl "Add apt key for 'mongodb' repository.."
|
||
wget -qO - https://www.mongodb.org/static/pgp/server-3.4.asc | sudo apt-key add - > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
echononl "Add repository for 'mongodb'.."
|
||
cat <<EOF > /etc/apt/sources.list.d/mongodb-org-3.4.list 2> "$log_file"
|
||
deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu ${DIST_RELEASE}/mongodb-org/3.4 multiverse
|
||
EOF
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
echononl "Update repositories.."
|
||
apt-get update > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
echononl "Install mongo-db and curl .."
|
||
apt-get install -y mongodb-org curl > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
blank_line
|
||
|
||
|
||
# install nodejs
|
||
#
|
||
echononl "Trigger script to install the NodeSource Node.js 8.x LTS Carbon repo.."
|
||
echo_wait
|
||
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
echononl "Install nodejs.."
|
||
apt-get install -y nodejs > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
|
||
# apt-get key for BigBlueButton repository
|
||
#
|
||
echononl "Add apt key for BigBlueButton repository.."
|
||
wget https://ubuntu.bigbluebutton.org/repo/bigbluebutton.asc -O- 2> "$log_file" | sudo apt-key add - > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
# add the repository for BigBlueButton 2.2 packages
|
||
#
|
||
echononl "Add repository for BigBlueButton 2.2 packages.."
|
||
cat <<EOF > /etc/apt/sources.list.d/bigbluebutton.list 2> "$log_file"
|
||
deb https://ubuntu.bigbluebutton.org/${DIST_RELEASE}-220/ bigbluebutton-${DIST_RELEASE} main
|
||
EOF
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
|
||
echononl "Update repositories.."
|
||
apt-get update > "$log_file" 2>&1
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
blank_line
|
||
|
||
|
||
# Create 'override'-directory for service 'redis-server'
|
||
#
|
||
echononl "Create 'override'-directory for service 'redis-server'.."
|
||
if [[ -d "/etc/systemd/system/redis-server.service.d" ]] ; then
|
||
echo_skipped
|
||
else
|
||
mkdir /etc/systemd/system/redis-server.service.d
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
fi
|
||
|
||
echononl "Create 'override'-file for service 'redis-server'.."
|
||
cat <<EOF > /etc/systemd/system/redis-server.service.d/override.conf 2> "$log_file"
|
||
[Service]
|
||
PrivateDevices=no
|
||
EOF
|
||
if [[ $? -ne 0 ]]; then
|
||
echo_failed
|
||
error "$(cat "$log_file")"
|
||
else
|
||
echo_ok
|
||
fi
|
||
|
||
clean_up 0
|