diff --git a/rootfs/usr/share/planefence/prep-planefence.sh b/rootfs/usr/share/planefence/prep-planefence.sh index d9a404d..64a5126 100755 --- a/rootfs/usr/share/planefence/prep-planefence.sh +++ b/rootfs/usr/share/planefence/prep-planefence.sh @@ -1,5 +1,5 @@ #!/command/with-contenv bash -#shellcheck shell=bash disable=SC2015,SC2268,SC2174 +#shellcheck shell=bash disable=SC2015,SC2268,SC2174,SC1091,SC2154 # ----------------------------------------------------------------------------------- # Copyright 2020, 2021 Ramon F. Kolb - licensed under the terms and conditions # of GPLv3. The terms and conditions of this license are included with the Github @@ -11,14 +11,14 @@ # # ----------------------------------------------------------------------------------- # -APPNAME="$(hostname)/planefence" +source /scripts/common + REMOTEURL=$(sed -n 's/\(^\s*REMOTEURL=\)\(.*\)/\2/p' /usr/share/planefence/planefence.conf) function configure_planefence() { local SETTING_NAME="$1" local SETTING_VALUE="$2" - if [[ "x$SETTING_VALUE" != "x" ]] - then + if [[ -n "$SETTING_VALUE" ]]; then sed -i "s~\(^\s*${SETTING_NAME}=\).*~\1${SETTING_VALUE}~" /usr/share/planefence/planefence.conf else sed -i "s|\(^\s*${SETTING_NAME}=\).*|\1|" /usr/share/planefence/planefence.conf @@ -27,8 +27,7 @@ function configure_planefence() { function configure_planealert() { local SETTING_NAME="$1" local SETTING_VALUE="$2" - if [[ "x$SETTING_VALUE" != "x" ]] - then + if [[ -n "$SETTING_VALUE" ]]; then sed -i "s~\(^\s*${SETTING_NAME}=\).*~\1${SETTING_VALUE}~" /usr/share/plane-alert/plane-alert.conf else sed -i "s|\(^\s*${SETTING_NAME}=\).*|\1|" /usr/share/plane-alert/plane-alert.conf @@ -39,7 +38,7 @@ function configure_both() { configure_planealert "$1" "$2" } -[[ "$LOGLEVEL" != "ERROR" ]] && echo "[$APPNAME][$(date)] Running PlaneFence configuration - either the container is restarted or a config change was detected." || true +[[ "$LOGLEVEL" != "ERROR" ]] && "${s6wrap[@]}" echo" Running PlaneFence configuration - either the container is restarted or a config change was detected." || true # Sometimes, variables are passed in through .env in the Docker-compose directory # However, if there is a planefence.config file in the ..../persist directory # (by default exposed to ~/.planefence) then export all of those variables as well @@ -50,8 +49,7 @@ chmod -f a=rwx /usr/share/planefence/persist chmod -fR a+rw /usr/share/planefence/persist/{.[!.]*,*} chmod a=rwx /usr/share/planefence/persist/planepix -if [[ -f /usr/share/planefence/persist/planefence.config ]] -then +if [[ -f /usr/share/planefence/persist/planefence.config ]]; then set -o allexport source /usr/share/planefence/persist/planefence.config set +o allexport @@ -94,8 +92,7 @@ mkdir -p /usr/share/planefence/html/plane-alert cp -n /usr/share/plane-alert/plane-alert-db.txt /usr/share/planefence/persist # # LOOPTIME is the time between two runs of PlaneFence (in seconds) -if [[ "$PF_INTERVAL" != "" ]] -then +if [[ "$PF_INTERVAL" != "" ]]; then export LOOPTIME=$PF_INTERVAL else @@ -109,31 +106,26 @@ fi mkdir -p /run/planefence # ----------------------------------------------------------------------------------- # Do one last check. If FEEDER_LAT= empty or 90.12345, then the user obviously hasn't touched the config file. -if [[ "x$FEEDER_LAT" == "x" ]] || [[ "$FEEDER_LAT" == "90.12345" ]] -then +if [[ -z "$FEEDER_LAT" ]] || [[ "$FEEDER_LAT" == "90.12345" ]]; then sleep 10s - echo "[$APPNAME][$(date)] ----------------------------------------------------------" - echo "[$APPNAME][$(date)] !!! STOP !!!! You haven't configured FEEDER_LON and/or FEEDER_LAT for PlaneFence !!!!" - echo "[$APPNAME][$(date)] Planefence will not run unless you edit it configuration." - echo "[$APPNAME][$(date)] You can do this by pressing CTRL-c now and typing:" - echo "[$APPNAME][$(date)] sudo nano -l ~/.planefence/planefence.config" - echo "[$APPNAME][$(date)] Once done, restart the container and this message should disappear." - echo "[$APPNAME][$(date)] ----------------------------------------------------------" - while true - do - sleep 99999 - done + "${s6wrap[@]}" echo" ----------------------------------------------------------" + "${s6wrap[@]}" echo" !!! STOP !!!! You haven\'t configured FEEDER_LON and/or FEEDER_LAT for PlaneFence !!!!" + "${s6wrap[@]}" echo" Planefence will not run unless you edit it configuration." + "${s6wrap[@]}" echo" You can do this by pressing CTRL-c now and typing:" + "${s6wrap[@]}" echo" sudo nano -l ~/.planefence/planefence.config" + "${s6wrap[@]}" echo" Once done, restart the container and this message should disappear." + "${s6wrap[@]}" echo" ----------------------------------------------------------" + exec sleep infinity fi # # Set logging in planefence.conf: # -if [[ "$PF_LOG" == "off" ]] -then +if chk_disabled "$PF_LOG"; then export LOGFILE=/dev/null sed -i 's/\(^\s*VERBOSE=\).*/\1'""'/' /usr/share/planefence/planefence.conf else - [[ "x$PF_LOG" == "x" ]] && export LOGFILE="/tmp/planefence.log" || export LOGFILE="$PF_LOG" + [[ -z "$PF_LOG" ]] && export LOGFILE="/tmp/planefence.log" || export LOGFILE="$PF_LOG" fi # echo pflog=$PF_LOG and logfile=$LOGFILE sed -i 's|\(^\s*LOGFILE=\).*|\1'"$LOGFILE"'|' /usr/share/planefence/planefence.conf @@ -141,39 +133,39 @@ sed -i 's|\(^\s*LOGFILE=\).*|\1'"$LOGFILE"'|' /usr/share/planefence/planefence.c # ----------------------------------------------------------------------------------- # # read the environment variables and put them in the planefence.conf file: -[[ "x$FEEDER_LAT" != "x" ]] && sed -i 's/\(^\s*LAT=\).*/\1'"\"$FEEDER_LAT\""'/' /usr/share/planefence/planefence.conf || { echo "[$APPNAME][$(date)] Error - \$FEEDER_LAT ($FEEDER_LAT) not defined"; while :; do sleep 2073600; done; } -[[ "x$FEEDER_LONG" != "x" ]] && sed -i 's/\(^\s*LON=\).*/\1'"\"$FEEDER_LONG\""'/' /usr/share/planefence/planefence.conf || { echo "[$APPNAME][$(date)] Error - \$FEEDER_LONG not defined"; while :; do sleep 2073600; done; } -[[ "x$PF_MAXALT" != "x" ]] && sed -i 's/\(^\s*MAXALT=\).*/\1'"\"$PF_MAXALT\""'/' /usr/share/planefence/planefence.conf -[[ "x$PF_MAXDIST" != "x" ]] && sed -i 's/\(^\s*DIST=\).*/\1'"\"$PF_MAXDIST\""'/' /usr/share/planefence/planefence.conf -[[ "x$PF_ELEVATION" != "x" ]] && sed -i 's/\(^\s*ALTCORR=\).*/\1'"\"$PF_ELEVATION\""'/' /usr/share/planefence/planefence.conf -[[ "x$PF_NAME" != "x" ]] && sed -i 's/\(^\s*MY=\).*/\1'"\"$PF_NAME\""'/' /usr/share/planefence/planefence.conf || sed -i 's/\(^\s*MY=\).*/\1\"My\"/' /usr/share/planefence/planefence.conf -[[ "x$PF_TRACKSVC" != "x" ]] && sed -i 's|\(^\s*TRACKSERVICE=\).*|\1'"\"$PF_TRACKSVC\""'|' /usr/share/planefence/planefence.conf -[[ "x$PF_MAPURL" != "x" ]] && sed -i 's|\(^\s*MYURL=\).*|\1'"\"$PF_MAPURL\""'|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*MYURL=\).*|\1|' /usr/share/planefence/planefence.conf -[[ "x$PF_NOISECAPT" != "x" ]] && sed -i 's|\(^\s*REMOTENOISE=\).*|\1'"\"$PF_NOISECAPT\""'|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*REMOTENOISE=\).*|\1|' /usr/share/planefence/planefence.conf -[[ "x$PF_FUDGELOC" != "x" ]] && sed -i 's|\(^\s*FUDGELOC=\).*|\1'"\"$PF_FUDGELOC\""'|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*FUDGELOC=\).*|\1|' /usr/share/planefence/planefence.conf -[[ "$PF_OPENAIP_LAYER" == "ON" ]] && sed -i 's|\(^\s*OPENAIP_LAYER=\).*|\1'"\"ON\""'|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*OPENAIP_LAYER=\).*|\1'"\"OFF\""'|' /usr/share/planefence/planefence.conf -[[ "x$PF_TWEET_MINTIME" != "x" ]] && sed -i 's|\(^\s*TWEET_MINTIME=\).*|\1'"$PF_TWEET_MINTIME"'|' /usr/share/planefence/planefence.conf +[[ -n "$FEEDER_LAT" ]] && sed -i 's/\(^\s*LAT=\).*/\1'"\"$FEEDER_LAT\""'/' /usr/share/planefence/planefence.conf || { "${s6wrap[@]}" echo" Error - \$FEEDER_LAT ($FEEDER_LAT) not defined"; while :; do sleep 2073600; done; } +[[ -n "$FEEDER_LONG" ]] && sed -i 's/\(^\s*LON=\).*/\1'"\"$FEEDER_LONG\""'/' /usr/share/planefence/planefence.conf || { "${s6wrap[@]}" echo" Error - \$FEEDER_LONG not defined"; while :; do sleep 2073600; done; } +[[ -n "$PF_MAXALT" ]] && sed -i 's/\(^\s*MAXALT=\).*/\1'"\"$PF_MAXALT\""'/' /usr/share/planefence/planefence.conf +[[ -n "$PF_MAXDIST" ]] && sed -i 's/\(^\s*DIST=\).*/\1'"\"$PF_MAXDIST\""'/' /usr/share/planefence/planefence.conf +[[ -n "$PF_ELEVATION" ]] && sed -i 's/\(^\s*ALTCORR=\).*/\1'"\"$PF_ELEVATION\""'/' /usr/share/planefence/planefence.conf +[[ -n "$PF_NAME" ]] && sed -i 's/\(^\s*MY=\).*/\1'"\"$PF_NAME\""'/' /usr/share/planefence/planefence.conf || sed -i 's/\(^\s*MY=\).*/\1\"My\"/' /usr/share/planefence/planefence.conf +[[ -n "$PF_TRACKSVC" ]] && sed -i 's|\(^\s*TRACKSERVICE=\).*|\1'"\"$PF_TRACKSVC\""'|' /usr/share/planefence/planefence.conf +[[ -n "$PF_MAPURL" ]] && sed -i 's|\(^\s*MYURL=\).*|\1'"\"$PF_MAPURL\""'|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*MYURL=\).*|\1|' /usr/share/planefence/planefence.conf +[[ -n "$PF_NOISECAPT" ]] && sed -i 's|\(^\s*REMOTENOISE=\).*|\1'"\"$PF_NOISECAPT\""'|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*REMOTENOISE=\).*|\1|' /usr/share/planefence/planefence.conf +[[ -n "$PF_FUDGELOC" ]] && sed -i 's|\(^\s*FUDGELOC=\).*|\1'"\"$PF_FUDGELOC\""'|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*FUDGELOC=\).*|\1|' /usr/share/planefence/planefence.conf +chk_enabled "$PF_OPENAIP_LAYER" && sed -i 's|\(^\s*OPENAIP_LAYER=\).*|\1'"\"ON\""'|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*OPENAIP_LAYER=\).*|\1'"\"OFF\""'|' /usr/share/planefence/planefence.conf +[[ -n "$PF_TWEET_MINTIME" ]] && sed -i 's|\(^\s*TWEET_MINTIME=\).*|\1'"$PF_TWEET_MINTIME"'|' /usr/share/planefence/planefence.conf [[ "$PF_TWEET_BEHAVIOR" == "PRE" ]] && sed -i 's|\(^\s*TWEET_BEHAVIOR=\).*|\1PRE|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*TWEET_BEHAVIOR=\).*|\1POST|' /usr/share/planefence/planefence.conf -[[ "$PF_PLANEALERT" == "ON" ]] && sed -i 's|\(^\s*PA_LINK=\).*|\1\"'"$PF_PA_LINK"'\"|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*PA_LINK=\).*|\1|' /usr/share/planefence/planefence.conf -[[ "$PF_TWEETEVERY" == "true" ]] && sed -i 's|\(^\s*TWEETEVERY=\).*|\1true|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*TWEETEVERY=\).*|\1false|' /usr/share/planefence/planefence.conf -[[ "x$PA_HISTTIME" != "x" ]] && sed -i 's|\(^\s*HISTTIME=\).*|\1\"'"$PA_HISTTIME"'\"|' /usr/share/plane-alert/plane-alert.conf -[[ "x$PF_ALERTHEADER" != "x" ]] && sed -i "s|\(^\s*ALERTHEADER=\).*|\1\'$PF_ALERTHEADER\'|" /usr/share/plane-alert/plane-alert.conf +chk_enabled "$PF_PLANEALERT" && sed -i 's|\(^\s*PA_LINK=\).*|\1\"'"$PF_PA_LINK"'\"|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*PA_LINK=\).*|\1|' /usr/share/planefence/planefence.conf +chk_enabled "$PF_TWEETEVERY" && sed -i 's|\(^\s*TWEETEVERY=\).*|\1true|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*TWEETEVERY=\).*|\1false|' /usr/share/planefence/planefence.conf +[[ -n "$PA_HISTTIME" ]] && sed -i 's|\(^\s*HISTTIME=\).*|\1\"'"$PA_HISTTIME"'\"|' /usr/share/plane-alert/plane-alert.conf +[[ -n "$PF_ALERTHEADER" ]] && sed -i "s|\(^\s*ALERTHEADER=\).*|\1\'$PF_ALERTHEADER\'|" /usr/share/plane-alert/plane-alert.conf -if [[ "x$PF_SOCK30003HOST" != "x" ]] -then +if [[ -n "$PF_SOCK30003HOST" ]]; then + # shellcheck disable=SC2001 a=$(sed 's|\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)|\1\_\2\_\3\_\4|g' <<< "$PF_SOCK30003HOST") sed -i 's|\(^\s*LOGFILEBASE=/run/socket30003/dump1090-\).*|\1'"$a"'-|' /usr/share/planefence/planefence.conf sed -i 's/127_0_0_1/'"$a"'/' /usr/share/planefence/planeheat.sh unset a else sleep 10s - echo "[$APPNAME][$(date)] ----------------------------------------------------------" - echo "[$APPNAME][$(date)] !!! STOP !!!! You haven't configured PF_SOCK30003HOST for PlaneFence !!!!" - echo "[$APPNAME][$(date)] Planefence will not run unless you edit it configuration." - echo "[$APPNAME][$(date)] You can do this by pressing CTRL-c now and typing:" - echo "[$APPNAME][$(date)] sudo nano -l ~/.planefence/planefence.config" - echo "[$APPNAME][$(date)] Once done, restart the container and this message should disappear." - echo "[$APPNAME][$(date)] ----------------------------------------------------------" + "${s6wrap[@]}" echo" ----------------------------------------------------------" + "${s6wrap[@]}" echo" !!! STOP !!!! You haven't configured PF_SOCK30003HOST for PlaneFence !!!!" + "${s6wrap[@]}" echo" Planefence will not run unless you edit it configuration." + "${s6wrap[@]}" echo" You can do this by pressing CTRL-c now and typing:" + "${s6wrap[@]}" echo" sudo nano -l ~/.planefence/planefence.config" + "${s6wrap[@]}" echo" Once done, restart the container and this message should disappear." + "${s6wrap[@]}" echo" ----------------------------------------------------------" while true do sleep 99999 @@ -181,10 +173,10 @@ else fi # # Deal with duplicates. Put IGNOREDUPES in its place and create (or delete) the link to the ignorelist: -[[ "x$PF_IGNOREDUPES" != "x" ]] && sed -i 's|\(^\s*IGNOREDUPES=\).*|\1ON|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*IGNOREDUPES=\).*|\1OFF|' /usr/share/planefence/planefence.conf -[[ "x$PF_COLLAPSEWITHIN" != "x" ]] && sed -i 's|\(^\s*COLLAPSEWITHIN=\).*|\1'"$PF_COLLAPSEWITHIN"'|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*IGNOREDUPES=\).*|\1300|' /usr/share/planefence/planefence.conf -a=$(sed -n 's/^\s*IGNORELIST=\(.*\)/\1/p' /usr/share/planefence/planefence.conf | sed 's/\"//g') -[[ "$a" != "" ]] && ln -sf $a /usr/share/planefence/html/ignorelist.txt || rm -f /usr/share/planefence/html/ignorelist.txt +[[ -n "$PF_IGNOREDUPES" ]] && sed -i 's|\(^\s*IGNOREDUPES=\).*|\1ON|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*IGNOREDUPES=\).*|\1OFF|' /usr/share/planefence/planefence.conf +[[ -n "$PF_COLLAPSEWITHIN" ]] && sed -i 's|\(^\s*COLLAPSEWITHIN=\).*|\1'"$PF_COLLAPSEWITHIN"'|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*IGNOREDUPES=\).*|\1300|' /usr/share/planefence/planefence.conf +a="$(sed -n 's/^\s*IGNORELIST=\(.*\)/\1/p' /usr/share/planefence/planefence.conf | sed 's/\"//g')" +[[ -n "$a" ]] && ln -sf "$a" /usr/share/planefence/html/ignorelist.txt || rm -f /usr/share/planefence/html/ignorelist.txt unset a # # ----------------------------------------------------------------------------------- @@ -193,8 +185,8 @@ unset a # sed -i 's/\(^\s*LAT=\).*/\1'"\"$FEEDER_LAT\""'/' /usr/share/planefence/planeheat.sh sed -i 's/\(^\s*LON=\).*/\1'"\"$FEEDER_LONG\""'/' /usr/share/planefence/planeheat.sh -[[ "x$PF_MAXALT" != "x" ]] && sed -i 's/\(^\s*MAXALT=\).*/\1'"\"$PF_MAXALT\""'/' /usr/share/planefence/planeheat.sh -[[ "x$PF_MAXDIST" != "x" ]] && sed -i 's/\(^\s*DIST=\).*/\1'"\"$PF_MAXDIST\""'/' /usr/share/planefence/planeheat.sh +[[ -n "$PF_MAXALT" ]] && sed -i 's/\(^\s*MAXALT=\).*/\1'"\"$PF_MAXALT\""'/' /usr/share/planefence/planeheat.sh +[[ -n "$PF_MAXDIST" ]] && sed -i 's/\(^\s*DIST=\).*/\1'"\"$PF_MAXDIST\""'/' /usr/share/planefence/planeheat.sh # ----------------------------------------------------------------------------------- # @@ -211,74 +203,68 @@ sed -i 's/\(^\s*LON=\).*/\1'"\"$FEEDER_LONG\""'/' /usr/share/planefence/planehea # # enable or disable tweeting: # -[[ "${PF_TWEET,,}" == "off" ]] && sed -i 's/\(^\s*PLANETWEET=\).*/\1/' /usr/share/planefence/planefence.conf -if [[ "${PF_TWEET,,}" == "on" ]] -then - if [[ ! -f ~/.twurlrc ]] - then - echo "[$APPNAME][$(date)] Warning: PF_TWEET is set to ON in .env file, but the Twitter account is not configured." - echo "[$APPNAME][$(date)] Sign up for a developer account at Twitter, create an app, and get a Consumer Key / Secret." - echo "[$APPNAME][$(date)] Then run this from the host machine: \"docker exec -it planefence /root/config_tweeting.sh\"" - echo "[$APPNAME][$(date)] For more information on how to sign up for a Twitter Developer Account, see this link:" - echo "[$APPNAME][$(date)] https://elfsight.com/blog/2020/03/how-to-get-twitter-api-key/" - echo "[$APPNAME][$(date)] PlaneFence will continue to start without Twitter functionality." +chk_disabled "${PF_TWEET}" && sed -i 's/\(^\s*PLANETWEET=\).*/\1/' /usr/share/planefence/planefence.conf +if chk_enabled "${PF_TWEET,,}"; then + if [[ ! -f ~/.twurlrc ]]; then + "${s6wrap[@]}" echo" Warning: PF_TWEET is set to ON in .env file, but the Twitter account is not configured." + "${s6wrap[@]}" echo" Sign up for a developer account at Twitter, create an app, and get a Consumer Key / Secret." + "${s6wrap[@]}" echo" Then run this from the host machine: \"docker exec -it planefence /root/config_tweeting.sh\"" + "${s6wrap[@]}" echo" For more information on how to sign up for a Twitter Developer Account, see this link:" + "${s6wrap[@]}" echo" https://elfsight.com/blog/2020/03/how-to-get-twitter-api-key/" + "${s6wrap[@]}" echo" PlaneFence will continue to start without Twitter functionality." sed -i 's/\(^\s*PLANETWEET=\).*/\1/' /usr/share/planefence/planefence.conf else sed -i 's|\(^\s*PLANETWEET=\).*|\1'"$(sed -n '/profiles:/{n;p;}' /root/.twurlrc | tr -d '[:blank:][=:=]')"'|' /usr/share/planefence/planefence.conf - [[ "x$PF_TWATTRIB" != "x" ]] && sed -i 's|\(^\s*ATTRIB=\).*|\1'"\"$PF_TWATTRIB\""'|' /usr/share/planefence/planefence.conf + [[ -n "$PF_TWATTRIB" ]] && sed -i 's|\(^\s*ATTRIB=\).*|\1'"\"$PF_TWATTRIB\""'|' /usr/share/planefence/planefence.conf fi fi # ----------------------------------------------------------------------------------- # # Change the heatmap height and width if they are defined in the .env parameter file: -[[ "x$PF_MAPHEIGHT" != "x" ]] && sed -i 's|\(^\s*HEATMAPHEIGHT=\).*|\1'"\"$PF_MAPHEIGHT\""'|' /usr/share/planefence/planefence.conf -[[ "x$PF_MAPWIDTH" != "x" ]] && sed -i 's|\(^\s*HEATMAPWIDTH=\).*|\1'"\"$PF_MAPWIDTH\""'|' /usr/share/planefence/planefence.conf -[[ "x$PF_MAPZOOM" != "x" ]] && sed -i 's|\(^\s*HEATMAPZOOM=\).*|\1'"\"$PF_MAPZOOM\""'|' /usr/share/planefence/planefence.conf +[[ -n "$PF_MAPHEIGHT" ]] && sed -i 's|\(^\s*HEATMAPHEIGHT=\).*|\1'"\"$PF_MAPHEIGHT\""'|' /usr/share/planefence/planefence.conf +[[ -n "$PF_MAPWIDTH" ]] && sed -i 's|\(^\s*HEATMAPWIDTH=\).*|\1'"\"$PF_MAPWIDTH\""'|' /usr/share/planefence/planefence.conf +[[ -n "$PF_MAPZOOM" ]] && sed -i 's|\(^\s*HEATMAPZOOM=\).*|\1'"\"$PF_MAPZOOM\""'|' /usr/share/planefence/planefence.conf # # Also do this for files in the past -- /usr/share/planefence/html/planefence-??????.html -if find /usr/share/planefence/html/planefence-??????.html >/dev/null 2>&1 -then +if find /usr/share/planefence/html/planefence-??????.html >/dev/null 2>&1; then for i in /usr/share/planefence/html/planefence-??????.html do - [[ "x$PF_MAPWIDTH" != "x" ]] && sed -i 's|\(^\s*
~/.planefence/plane-alert-db.txt" - echo "[$APPNAME][$(date)] and then restart this docker container" +if [[ ! -f /usr/share/planefence/persist/plane-alert-db.txt ]] && chk_enabled "$PF_PLANEALERT"; then + "${s6wrap[@]}" echo" Cannot find or create the plane-alert-db.txt file. Disabling Plane-Alert." + "${s6wrap[@]}" echo" Do this on the host to get a base file:" + "${s6wrap[@]}" echo" curl --compressed -s https://raw.githubusercontent.com/kx1t/docker-planefence/plane-alert/plane-alert-db.txt >~/.planefence/plane-alert-db.txt" + "${s6wrap[@]}" echo" and then restart this docker container" PF_PLANEALERT="OFF" fi # make sure $PLANEALERT is set to ON in the planefence.conf file, so it will be invoked: -[[ "$PF_PLANEALERT" == "ON" ]] && sed -i 's|\(^\s*PLANEALERT=\).*|\1'"\"ON\""'|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*PLANEALERT=\).*|\1'"\"OFF\""'|' /usr/share/planefence/planefence.conf +chk_enabled "$PF_PLANEALERT" && sed -i 's|\(^\s*PLANEALERT=\).*|\1'"\"ON\""'|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*PLANEALERT=\).*|\1'"\"OFF\""'|' /usr/share/planefence/planefence.conf # Go get the plane-alert-db files: /usr/share/plane-alert/get-pa-alertlist.sh /usr/share/plane-alert/get-silhouettes.sh # Now make sure that the file containing the twitter IDs is rewritten with 1 ID per line -[[ "x$PF_PA_TWID" != "x" ]] && tr , "\n" <<< "$PF_PA_TWID" > /usr/share/plane-alert/plane-alert.twitterid || rm -f /usr/share/plane-alert/plane-alert.twitterid +[[ -n "$PF_PA_TWID" ]] && tr , "\n" <<< "$PF_PA_TWID" > /usr/share/plane-alert/plane-alert.twitterid || rm -f /usr/share/plane-alert/plane-alert.twitterid # and write the rest of the parameters into their place -[[ "x$PF_PA_TWID" != "x" ]] && [[ "$PF_PA_TWEET" == "DM" ]] && sed -i 's|\(^\s*TWITTER=\).*|\1DM|' /usr/share/plane-alert/plane-alert.conf || sed -i 's|\(^\s*TWITTER=\).*|\1false|' /usr/share/plane-alert/plane-alert.conf +[[ -n "$PF_PA_TWID" ]] && [[ "$PF_PA_TWEET" == "DM" ]] && sed -i 's|\(^\s*TWITTER=\).*|\1DM|' /usr/share/plane-alert/plane-alert.conf || sed -i 's|\(^\s*TWITTER=\).*|\1false|' /usr/share/plane-alert/plane-alert.conf [[ "$PF_PA_TWEET" == "TWEET" ]] && sed -i 's|\(^\s*TWITTER=\).*|\1TWEET|' /usr/share/plane-alert/plane-alert.conf [[ "$PF_PA_TWEET" != "TWEET" ]] && [[ "$PF_PA_TWEET" != "DM" ]] && sed -i 's|\(^\s*TWITTER=\).*|\1false|' /usr/share/plane-alert/plane-alert.conf configure_planefence "PF_DISCORD" "$PF_DISCORD" @@ -293,8 +279,7 @@ configure_both "NOTIFICATION_SERVER" "\"NOTIFICATION_SERVER\"" configure_planefence "OPENAIPKEY" "$PF_OPENAIPKEY" # Configure Mastodon parameters: -if [[ -n "$MASTODON_SERVER" ]] && [[ -n "$MASTODON_ACCESS_TOKEN" ]] -then +if [[ -n "$MASTODON_SERVER" ]] && [[ -n "$MASTODON_ACCESS_TOKEN" ]]; then MASTODON_SERVER="${MASTODON_SERVER,,}" # strip http:// https:// [[ "${MASTODON_SERVER:0:7}" == "http://" ]] && MASTODON_SERVER="${MASTODON_SERVER:7}" || true @@ -307,8 +292,7 @@ then configure_planefence "MASTODON_ACCESS_TOKEN" "" configure_planefence "MASTODON_SERVER" "" fi - if chk_enabled "${PA_MASTODON,,}" - then + if chk_enabled "${PA_MASTODON,,}"; then configure_planealert "MASTODON_ACCESS_TOKEN" "$MASTODON_ACCESS_TOKEN" configure_planealert "MASTODON_SERVER" "$MASTODON_SERVER" configure_planealert "MASTODON_VISIBILITY" "${PA_MASTODON_VISIBILITY:-unlisted}" @@ -319,11 +303,11 @@ then fi fi -[[ "x$PF_NAME" != "x" ]] && sed -i 's|\(^\s*NAME=\).*|\1'"\"$PF_NAME\""'|' /usr/share/plane-alert/plane-alert.conf || sed -i 's|\(^\s*NAME=\).*|\1My|' /usr/share/plane-alert/plane-alert.conf -[[ "x$PF_MAPURL" != "x" ]] && sed -i 's|\(^\s*ADSBLINK=\).*|\1'"\"$PF_MAPURL\""'|' /usr/share/plane-alert/plane-alert.conf -# removed for now - hardcoding PlaneAlert map zoom to 7 in plane-alert.conf: [[ "x$PF_MAPZOOM" != "x" ]] && sed -i 's|\(^\s*MAPZOOM=\).*|\1'"\"$PF_MAPZOOM\""'|' /usr/share/plane-alert/plane-alert.conf -[[ "x$PF_PARANGE" != "x" ]] && sed -i 's|\(^\s*RANGE=\).*|\1'"$PF_PARANGE"'|' /usr/share/plane-alert/plane-alert.conf || sed -i 's|\(^\s*RANGE=\).*|\1999999|' /usr/share/plane-alert/plane-alert.conf -[[ "x$PF_PA_SQUAWKS" != "x" ]] && sed -i 's|\(^\s*SQUAWKS=\).*|\1'"$PF_PA_SQUAWKS"'|' /usr/share/plane-alert/plane-alert.conf || sed -i 's|\(^\s*SQUAWKS=\).*|\1|' /usr/share/plane-alert/plane-alert.conf +[[ -n "$PF_NAME" ]] && sed -i 's|\(^\s*NAME=\).*|\1'"\"$PF_NAME\""'|' /usr/share/plane-alert/plane-alert.conf || sed -i 's|\(^\s*NAME=\).*|\1My|' /usr/share/plane-alert/plane-alert.conf +[[ -n "$PF_MAPURL" ]] && sed -i 's|\(^\s*ADSBLINK=\).*|\1'"\"$PF_MAPURL\""'|' /usr/share/plane-alert/plane-alert.conf +# removed for now - hardcoding PlaneAlert map zoom to 7 in plane-alert.conf: [[ -n "$PF_MAPZOOM" ]] && sed -i 's|\(^\s*MAPZOOM=\).*|\1'"\"$PF_MAPZOOM\""'|' /usr/share/plane-alert/plane-alert.conf +[[ -n "$PF_PARANGE" ]] && sed -i 's|\(^\s*RANGE=\).*|\1'"$PF_PARANGE"'|' /usr/share/plane-alert/plane-alert.conf || sed -i 's|\(^\s*RANGE=\).*|\1999999|' /usr/share/plane-alert/plane-alert.conf +[[ -n "$PF_PA_SQUAWKS" ]] && sed -i 's|\(^\s*SQUAWKS=\).*|\1'"$PF_PA_SQUAWKS"'|' /usr/share/plane-alert/plane-alert.conf || sed -i 's|\(^\s*SQUAWKS=\).*|\1|' /usr/share/plane-alert/plane-alert.conf configure_both "AUTOREFRESH" "${PF_AUTOREFRESH,,}" @@ -337,18 +321,17 @@ cp -f /usr/share/planefence/stage/sort-table.js /usr/share/planefence/html/plane sleep 1 if [[ "$PF_DISTUNIT" != $(sed -n 's/^\s*distanceunit=\(.*\)/\1/p' /usr/share/socket30003/socket30003.cfg) ]] \ || [[ "$PF_ALTUNIT" != $(sed -n 's/^\s*altitudeunit=\(.*\)/\1/p' /usr/share/socket30003/socket30003.cfg) ]] \ - || [[ "$PF_SPEEDUNIT" != $(sed -n 's/^\s*speedunit=\(.*\)/\1/p' /usr/share/socket30003/socket30003.cfg) ]] -then - [[ "x$PF_DISTUNIT" != "x" ]] && sed -i 's/\(^\s*distanceunit=\).*/\1'"$PF_DISTUNIT"'/' /usr/share/socket30003/socket30003.cfg - [[ "x$PF_SPEEDUNIT" != "x" ]] && sed -i 's/\(^\s*speedunit=\).*/\1'"$PF_SPEEDUNIT"'/' /usr/share/socket30003/socket30003.cfg - [[ "x$PF_ALTUNIT" != "x" ]] && sed -i 's/\(^\s*altitudeunit=\).*/\1'"$PF_ALTUNIT"'/' /usr/share/socket30003/socket30003.cfg + || [[ "$PF_SPEEDUNIT" != $(sed -n 's/^\s*speedunit=\(.*\)/\1/p' /usr/share/socket30003/socket30003.cfg) ]]; then + [[ -n "$PF_DISTUNIT" ]] && sed -i 's/\(^\s*distanceunit=\).*/\1'"$PF_DISTUNIT"'/' /usr/share/socket30003/socket30003.cfg + [[ -n "$PF_SPEEDUNIT" ]] && sed -i 's/\(^\s*speedunit=\).*/\1'"$PF_SPEEDUNIT"'/' /usr/share/socket30003/socket30003.cfg + [[ -n "$PF_ALTUNIT" ]] && sed -i 's/\(^\s*altitudeunit=\).*/\1'"$PF_ALTUNIT"'/' /usr/share/socket30003/socket30003.cfg fi # #-------------------------------------------------------------------------------- # Check if the remote airlinename server is online #[[ "$PF_CHECKREMOTEDB" != "OFF" ]] && a="$(curl -L -s https://get-airline.planefence.com/?flight=hello_from_$(grep 'PF_NAME' /usr/share/planefence/persist/planefence.config | awk -F '=' '{ print $2 }' | tr -dc '[:alnum:]')_bld_$([[ -f /usr/share/planefence/build ]] && cat /usr/share/planefence/build || cat /root/.buildtime | cut -c 1-23 | tr ' ' '_'))" || a="" #shellcheck disable=SC2046 -[[ "$PF_CHECKREMOTEDB" != "OFF" ]] && a="$(curl -L -s $REMOTEURL/?flight=hello_from_$(grep 'PF_NAME' /usr/share/planefence/persist/planefence.config | awk -F '=' '{ print $2 }' | tr -dc '[:alnum:]')_bld_$([[ -f /usr/share/planefence/branch ]] && cat /usr/share/planefence/branch || cat /root/.buildtime))" || a="" +! chk_disabled "$PF_CHECKREMOTEDB" && a="$(curl -L -s "$REMOTEURL"/?flight=hello_from_$(grep 'PF_NAME' /usr/share/planefence/persist/planefence.config | awk -F '=' '{ print $2 }' | tr -dc '[:alnum:]')_bld_$([[ -f /usr/share/planefence/branch ]] && cat /usr/share/planefence/branch || cat /root/.buildtime))" || a="" [[ "${a:0:4}" == "#100" ]] && sed -i 's|\(^\s*CHECKREMOTEDB=\).*|\1ON|' /usr/share/planefence/planefence.conf || sed -i 's|\(^\s*CHECKREMOTEDB=\).*|\1OFF|' /usr/share/planefence/planefence.conf # #-------------------------------------------------------------------------------- @@ -361,8 +344,8 @@ fi # if curl -L -s https://raw.githubusercontent.com/sdr-enthusiasts/plane-alert-db/main/planepix.txt > /usr/share/planefence/persist/planepix.txt.samplefile # then # chmod a+r /usr/share/planefence/persist/planepix.txt.samplefile -# echo "[$APPNAME][$(date)] Successfully downloaded planepix sample file to ~/.planefence/planepix.txt.samplefile directory." -# echo "[$APPNAME][$(date)] To use it, rename it to, or incorporate it into ~/.planefence/planepix.txt. Any entries in this file will replace the tar1090 screenshot with a picture of the plane." +# "${s6wrap[@]}" echo" Successfully downloaded planepix sample file to ~/.planefence/planepix.txt.samplefile directory." +# "${s6wrap[@]}" echo" To use it, rename it to, or incorporate it into ~/.planefence/planepix.txt. Any entries in this file will replace the tar1090 screenshot with a picture of the plane." # fi #-------------------------------------------------------------------------------- # Put the MOTDs in place: