nginx-streamer/startscript.sh
Torma Kristof fd182b6baf
Some checks failed
continuous-integration/drone/push Build is failing
copy nginx sample configs
2020-09-19 21:55:02 +02:00

51 lines
1.5 KiB
Bash

#!/usr/bin/env bash
NGINX_CONF=/etc/nginx/nginx.conf
NGINX_INGEST_CONF=/etc/nginx/nginx_ingest.conf
NGINX_RESTREAM_CONF=/etc/nginx/nginx_restream.conf
if test -f "$NGINX_CONF"; then
nginx -g daemon off;
exit 0
fi
function mfcb { local val="$4"; "$1"; eval "$2[$3]=\$val;"; };
function val_ltrim { if [[ "$val" =~ ^[[:space:]]+ ]]; then val="${val:${#BASH_REMATCH[0]}}"; fi; };
function val_rtrim { if [[ "$val" =~ [[:space:]]+$ ]]; then val="${val:0:${#val}-${#BASH_REMATCH[0]}}"; fi; };
function val_trim { val_ltrim; val_rtrim; };
if [[ -z "${TYPE}" ]]; then
NGINX_TYPE="ingest"
else
if [[ $TYPE == "ingest" ]] || [[ $TYPE == "restream" ]]; then
NGINX_TYPE="${TYPE}"
else
echo -e "Envvar TYPE must be either ingest or restream"
exit 1
fi
fi
if [[ $NGINX_TYPE == "ingest" ]]; then
if [[ -z "${STREAM_KEY}" ]]; then
NGINX_STREAM_KEY=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
echo -e "Stream Key: $NGINX_STREAM_KEY"
else
NGINX_STREAM_KEY="${STREAM_KEY}"
fi
sed -i 's@___STREAMKEY___@'"$NGINX_STREAM_KEY"'@' $NGINX_INGEST_CONF > $NGINX_CONF
else
if [[ -z "${PUSH_URLS}" ]]; then
echo -e "Envvar PUSH_URLS required"
exit 1
else
readarray -c1 -C 'mfcb val_trim a' -td, <<<"$PUSH_URLS,"; unset 'a[-1]'; declare -a a;
NGINX_PUSH_URLS=""
for i in "${a[@]}"
do
:
NGINX_PUSH_URLS=$NGINX_PUSH_URLS$'push '$i$'\n'
done
sed -i 's@___PUSH_DIRECTIVES___@'"$NGINX_PUSH_URLS"'@' $NGINX_RESTREAM_CONF > $NGINX_CONF
fi
fi
nginx -g daemon off;