diff --git a/jitsi_disable_recording.sh b/jitsi_disable_recording.sh new file mode 100755 index 0000000..10d8990 --- /dev/null +++ b/jitsi_disable_recording.sh @@ -0,0 +1,269 @@ +#!/usr/bin/env bash + +# ============================================================================= +# +# To allow normal users using this script to disable recording, then add +# +# ALL ALL = (root) NOPASSWD: /usr/local/src/jitsi/jitsi_disable_recording.sh +# +# to file '/etc/sudoers.d/50-user' +# +# ============================================================================= + +script_name="$(basename $(realpath $0))" +working_dir="$(dirname $(realpath $0))" + +#conf_file="${working_dir}/conf/${script_name%%.*}.conf" +conf_file="${working_dir}/conf/jitsi.conf" + +LOCK_DIR="/tmp/$(basename $0).$$.LOCK" +log_file="${LOCK_DIR}/${script_name%%.*}.log" + + +# ---------- +# 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 "" +} + +warn (){ + if $terminal ; then + echo "" + echo -e " [ \033[33m\033[1mWarning\033[m ] $*" + echo "" + else + echo "" + echo " [ Warning ] $*" + echo "" + fi +} + +notice (){ + if $terminal ; then + echo "" + echo -e " [ \033[33m\033[1mNotice\033[m ] $*" + echo "" + else + echo "" + echo " [ Notice ] $*" + echo "" + fi +} + +info (){ + if $terminal ; then + echo "" + echo -e " [ \033[32m\033[1mInfo\033[m ] $*" + echo "" + else + echo "" + echo " [ Info ] $*" + echo "" + fi +} + +echo_ok() { + if $terminal ; then + echo -e "\033[85G[ \033[32mok\033[m ]" + fi +} +echo_done() { + if $terminal ; then + echo -e "\033[85G[ \033[32mdone\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 +} + +detect_os () { + + if $(which lsb_release > /dev/null 2>&1) ; then + + DIST="$(lsb_release -i | awk '{print tolower($3)}')" + DIST_VERSION="$(lsb_release -r | awk '{print tolower($2)}')" + DIST_CODENAME="$(lsb_release -c | awk '{print tolower($2)}')" + + if [[ "$DIST" = "debian" ]]; then + if $(echo "$DIST_VERSION" | grep -q '\.') ; then + DIST_VERSION=$(echo "$DIST_VERSION" | cut --delimiter='.' -f1) + fi + fi + + elif [[ -e "/etc/os-release" ]]; then + + . /etc/os-release + + DIST=$ID + DIST_VERSION=${VERSION_ID} + + fi + + # remove whitespace from DIST and DIST_VERSION + DIST="${DIST// /}" + DIST_VERSION="${DIST_VERSION// /}" + +} + + + +# ---------- +# - 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 + terminal=false +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" + echo "" +fi + + + +# ---------- +# Read Configurations from $conf_file +# ---------- + + +# - Give your default values here +# - +DEFAULT_FQHN_HOSTNAME="$(hostname -f)" + + +if [[ -f "$conf_file" ]]; then + source "$conf_file" +else + warn "No configuration file '$conf_file' present.\n + Loading default values.." +fi + +[[ -n "$FQHN_HOSTNAME" ]] || FQHN_HOSTNAME="$DEFAULT_FQHN_HOSTNAME" + +JITSI_MEET_CONFIG_FILE="/etc/jitsi/meet/${FQHN_HOSTNAME}-config.js" + +if [[ ! -f "$JITSI_MEET_CONFIG_FILE" ]] ; then + fatal "Jitsi Meet Configuration '$JITSI_MEET_CONFIG_FILE' not found." +fi + +echononl "Disable Recording Jitsi Meet Conference.." +if grep -q -E "^\s*fileRecordingsEnabled:\s+true\s*,\s*$" $JITSI_MEET_CONFIG_FILE 2> /dev/null ; then + perl -i -n -p -e "s/^(\s*fileRecordingsEnabled:)\s+.*/\1 false,/" $JITSI_MEET_CONFIG_FILE 2> "$log_file" + if [[ -s "$log_file" ]]; then + echo_failed + error "$(cat "$log_file")" + else + echo_ok + if ! $terminal ; then + echo "" + echo " [ ok ] Recording disnabled.." + echo "" + fi + fi +else + echo_skipped + notice "Recording already disabled" +fi + + +clean_up 0 + diff --git a/jitsi_enable_recording.sh b/jitsi_enable_recording.sh new file mode 100755 index 0000000..acf8073 --- /dev/null +++ b/jitsi_enable_recording.sh @@ -0,0 +1,286 @@ +#!/usr/bin/env bash + +# ============================================================================= +# +# To allow normal users using this script to enable recording, then add +# +# ALL ALL = (root) NOPASSWD: /usr/local/src/jitsi/jitsi_enable_recording.sh +# +# to file '/etc/sudoers.d/50-user' +# +# ============================================================================= + +script_name="$(basename $(realpath $0))" +working_dir="$(dirname $(realpath $0))" + +#conf_file="${working_dir}/conf/${script_name%%.*}.conf" +conf_file="${working_dir}/conf/jitsi.conf" + +LOCK_DIR="/tmp/$(basename $0).$$.LOCK" +log_file="${LOCK_DIR}/${script_name%%.*}.log" + + +# ---------- +# 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 "" +} + +warn (){ + if $terminal ; then + echo "" + echo -e " [ \033[33m\033[1mWarning\033[m ] $*" + echo "" + else + echo "" + echo " [ Warning ] $*" + echo "" + fi +} + +notice (){ + if $terminal ; then + echo "" + echo -e " [ \033[33m\033[1mNotice\033[m ] $*" + echo "" + else + echo "" + echo " [ Notice ] $*" + echo "" + fi +} + +info (){ + if $terminal ; then + echo "" + echo -e " [ \033[32m\033[1mInfo\033[m ] $*" + echo "" + else + echo "" + echo " [ Info ] $*" + echo "" + fi +} + +echo_ok() { + if $terminal ; then + echo -e "\033[85G[ \033[32mok\033[m ]" + fi +} +echo_done() { + if $terminal ; then + echo -e "\033[85G[ \033[32mdone\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 +} + +detect_os () { + + if $(which lsb_release > /dev/null 2>&1) ; then + + DIST="$(lsb_release -i | awk '{print tolower($3)}')" + DIST_VERSION="$(lsb_release -r | awk '{print tolower($2)}')" + DIST_CODENAME="$(lsb_release -c | awk '{print tolower($2)}')" + + if [[ "$DIST" = "debian" ]]; then + if $(echo "$DIST_VERSION" | grep -q '\.') ; then + DIST_VERSION=$(echo "$DIST_VERSION" | cut --delimiter='.' -f1) + fi + fi + + elif [[ -e "/etc/os-release" ]]; then + + . /etc/os-release + + DIST=$ID + DIST_VERSION=${VERSION_ID} + + fi + + # remove whitespace from DIST and DIST_VERSION + DIST="${DIST// /}" + DIST_VERSION="${DIST_VERSION// /}" + +} + + + +# ---------- +# - 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 + terminal=false +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" + echo "" +fi + + + +# ---------- +# Read Configurations from $conf_file +# ---------- + + +# - Give your default values here +# - +DEFAULT_FQHN_HOSTNAME="$(hostname -f)" + + +if [[ -f "$conf_file" ]]; then + source "$conf_file" +else + warn "No configuration file '$conf_file' present.\n + Loading default values.." +fi + +[[ -n "$FQHN_HOSTNAME" ]] || FQHN_HOSTNAME="$DEFAULT_FQHN_HOSTNAME" + +JITSI_MEET_CONFIG_FILE="/etc/jitsi/meet/${FQHN_HOSTNAME}-config.js" + +if [[ ! -f "$JITSI_MEET_CONFIG_FILE" ]] ; then + fatal "Jitsi Meet Configuration '$JITSI_MEET_CONFIG_FILE' not found." +fi + +echononl "Enable Recording Jitsi Meet Conference.." +if grep -q -E "^\s*fileRecordingsEnabled:\s+true\s*,\s*$" $JITSI_MEET_CONFIG_FILE 2> /dev/null ; then + echo_skipped + notice "Recording already enabled" +elif grep -q -E "^\s*fileRecordingsEnabled:\s+false\s*" $JITSI_MEET_CONFIG_FILE 2> /dev/null ; then + perl -i -n -p -e "s/^(\s*fileRecordingsEnabled:)\s+.*/\1 true,/" $JITSI_MEET_CONFIG_FILE 2> "$log_file" + if [[ -s "$log_file" ]]; then + echo_failed + error "$(cat "$log_file")" + else + echo_ok + if ! $terminal ; then + echo "" + echo " [ ok ] Recording successfully enabled.." + echo "" + fi + fi +elif grep -q -E "^\s*//\s*fileRecordingsEnabled.*" $JITSI_MEET_CONFIG_FILE 2> /dev/null ; then + perl -i -n -p -e "s/^((\s*)\/\/\s*fileRecordingsEnabled.*)/\1\n\2fileRecordingsEnabled: true,/" \ + $JITSI_MEET_CONFIG_FILE 2> "$log_file" + if [[ -s "$log_file" ]]; then + echo_failed + error "$(cat "$log_file")" + else + echo_ok + if ! $terminal ; then + echo "" + echo " [ ok ] Recording successfully enabled.." + echo "" + fi + fi +else + echo_failed + error "File '$JITSI_MEET_CONFIG_FILE' not changed." +fi + + +clean_up 0 +