Files
shell_sequencer/seqs/coturn.sh

87 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
toolName=coturn
toolConf="/etc/turnserver.conf"
toolServiceName="coturn.service"
# Get script working directory
# (when called from a different directory)
WDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >>/dev/null 2>&1 && pwd)"
APTOPT=
CONFIG=0
SCRIPT_FILE=$(basename -- $0)
SCRIPT_NAME=${SCRIPT_FILE%%.*}
CONFIG_FILE_NAME="${SCRIPT_NAME}.cfg"
CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example"
step_config() {
#echo "Called once before executing steps."
## e.g. to source a config file manually:
#. "$CONFIG_FILE"
## or to use sequencer api with global config file:
#initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE"
## or to use sequencer api with profile config file support:
#initSeqConfig -p "$SCRIPT_NAME" "$CONFIG_FILE_TEMPLATE"
#if [ $? -eq 0 ] ; then
# CONFIG=1
#else
# # End if no configuration file exists
# [ $DRY -eq 0 ] && return -1
#fi
[ $QUIET -ne 0 ] && APTOPT="-y"
return 0
}
step_1_info() { echo "Install $toolName"; }
step_1_alias() { ALIAS="install"; }
step_1() {
exe apt update
exe apt install coturn $APTOPT
}
step_10_info() {
echo "Update $toolName 'external-ip' using dig [OPTION] [CUSTOM DNS]"
echoinfo " [OPTION]"
echoinfo " -l : Always output informations (even with -qq)"
}
step_10_alias() { ALIAS="updateip"; }
step_10() {
shift
local lecho="echoseq"
if [ "$1" == "-l" ]; then
lecho="echo"
shift
fi
local dnsUrl="46.182.19.48" #digitalcourage.de/support/zensurfreier-dns-server
[ ! -z "$1" ] && dnsUrl="$1"
local pubIp=$(dig @$dnsUrl +short cloud.imoff.de)
local confIp=`cat "$toolConf" | grep "^external-ip" | cut -d'=' -f2`
local locDate=`date`
if [ "$pubIp" != "$confIp" ]; then
$lecho " [I] Update required. New public ip: $pubIp"
$lecho " $locDate"
exe sed -i "s/^external-ip[[:space:]]*=.*/external-ip=${pubIp}/" "$toolConf"
exe sleep 1
$lecho " [I] Restarting $toolName"
exe /bin/systemctl restart $toolServiceName
else
echoseq " [I] No update required. Current ip: $confIp"
echoseq " $locDate"
fi
}
step_12_info() { echo "Setup public ip update cron job every 5 minutes"; }
step_12_alias() { ALIAS="cronip"; }
step_12() {
echoseq " [I] Setup $ipCronLoc"
addConf -s "$ipCron" "$ipCronLoc"
}
ipCronLoc="/etc/cron.d/update_public_ip"
ipCron="*/5 * * * * root $WDIR/$SCRIPT_FILE -qq updateip"
VERSION_SEQREV=12
. /usr/local/bin/sequencer.sh