From a01f09839f80390a1aba18e868ad3408a5763c4e Mon Sep 17 00:00:00 2001 From: kx1t Date: Mon, 8 Apr 2024 16:34:43 +0200 Subject: [PATCH] cleanup --- rootfs/usr/share/planefence/noise2fence.sh | 31 ++-- rootfs/usr/share/planefence/planefence.sh | 196 +++++++-------------- 2 files changed, 79 insertions(+), 148 deletions(-) diff --git a/rootfs/usr/share/planefence/noise2fence.sh b/rootfs/usr/share/planefence/noise2fence.sh index 0cc220b9..792e655d 100755 --- a/rootfs/usr/share/planefence/noise2fence.sh +++ b/rootfs/usr/share/planefence/noise2fence.sh @@ -2,7 +2,7 @@ # NOISE2FENCE -- a script for extracting recorded noise values from NOISECAPT # and adding them to CSV files that have been created by PlaneFence # -# Copyright 2020 Ramon F. Kolb - licensed under the terms and conditions +# Copyright 2020-2024 Ramon F. Kolb - licensed under the terms and conditions # of GPLv3. The terms and conditions of this license are included with the Github # distribution of this package, and are also available here: # https://github.com/kx1t/planefence/ @@ -15,6 +15,7 @@ # Feel free to make changes to the variables between these two lines. However, it is # STRONGLY RECOMMENDED to RTFM! See README.md for explanation of what these do. # +# shellcheck disable=SC1091 [[ -f "/usr/share/planefence/planefence.conf" ]] && source /usr/share/planefence/planefence.conf CSVDIR=/usr/share/planefence/html @@ -26,14 +27,14 @@ CSVTMP=/usr/share/planefence/persist/.internal/pf-noise-csv.tmp NOISETMP=/usr/share/planefence/persist/.internal/pf-noise-data.tmp LOGFILE=/tmp/noise2fence.log VERBOSE= -VERSION=0.2-docker +VERSION=0.3-docker # ----------------------------------------------------------------------------------- # Figure out if NOISECAPT is active or not. REMOTENOISE contains the URL of the NoiseCapt container/server # and is configured via the $PF_NOISECAPT variable in the .env file. # Only if REMOTENOISE contains a URL and this URL is reachable, we collect noise data # Note that this doesn't check for the validity of the actual URL, just that we can reach it. #replace wget with curl to save disk space --was [[ "x$REMOTENOISE" != "x" ]] && [[ "$(wget -q -O /dev/null $REMOTENOISE ; echo $?)" == "0" ]] && NOISECAPT=1 || NOISECAPT=0 -[[ "x$REMOTENOISE" != "x" ]] && [[ "$(curl --fail -s -o /dev/null $REMOTENOISE ; echo $?)" == "0" ]] && NOISECAPT=1 || NOISECAPT=0 +if [[ -n "$REMOTENOISE" ]] && curl --fail -s -o /dev/null "$REMOTENOISE"; then NOISECAPT=1; else NOISECAPT=0; fi if [ "$NOISECAPT" != "1" ] then @@ -63,20 +64,19 @@ CSVFILE=$CSVNAMEBASE$NOISEDATE$CSVNAMEEXT # replace wget by curl to save disk space. was: if [ "$(wget -q -O - $REMOTENOISE/${LOGNAMEBASE##*/}$NOISEDATE$LOGNAMEEXT > $LOGNAMEBASE$NOISEDATE$LOGNAMEEXT.tmp ; echo $?)" != "0" ] -if [ "$(curl --fail -s $REMOTENOISE/${LOGNAMEBASE##*/}$NOISEDATE$LOGNAMEEXT > $LOGNAMEBASE$NOISEDATE$LOGNAMEEXT.tmp ; echo $?)" != "0" ] +if ! curl --fail -s "$REMOTENOISE/${LOGNAMEBASE##*/}$NOISEDATE$LOGNAMEEXT" > "$LOGNAMEBASE$NOISEDATE$LOGNAMEEXT.tmp" then echo "Can't reach $REMOTENOISE/${LOGNAMEBASE##*/}$NOISEDATE$LOGNAMEEXT ... exiting" exit 1 fi -mv -f $LOGNAMEBASE$NOISEDATE$LOGNAMEEXT.tmp $LOGNAMEBASE$NOISEDATE$LOGNAMEEXT +mv -f "$LOGNAMEBASE$NOISEDATE$LOGNAMEEXT.tmp" "$LOGNAMEBASE$NOISEDATE$LOGNAMEEXT" LOG "Got $LOGNAMEBASE$NOISEDATE$LOGNAMEEXT from $REMOTELOG" -NOISEFILE=$LOGNAMEBASE$NOISEDATE$LOGNAMEEXT +NOISEFILE="$LOGNAMEBASE$NOISEDATE$LOGNAMEEXT" # make sure there's no stray TMP file around, so we can directly append -[ -f "$CSVTMP" ] && rm "$CSVTMP" -[ -f "$NOISETMP" ] && rm "$NOISETMP" +rm -f "$CSVTMP" "$NOISETMP" #Now iterate through the CSVFILE: LOG "------------------------------" @@ -88,13 +88,13 @@ then # Clean the $CSVFILE first # cat "$CSVFILE" | tr -d '\r' >/tmp/noisetmp.tmp # mv /tmp/noisetmp.tmp "$CSVFILE" - while read CSVLINE + while read -r CSVLINE do - XX=$(echo -n $CSVLINE | tr -d '[:cntrl:]') + XX=$(echo -n "$CSVLINE" | tr -d '[:cntrl:]') CSVLINE=$XX unset RECORD # Read the line, but first clean it up as it appears to have a newline in it - IFS="," read -aRECORD <<< "$CSVLINE" + IFS="," read -ra RECORD <<< "$CSVLINE" LOG "${#RECORD[*]} records in the current line: (${RECORD[*]})" # if there's no audio stored in the record if [ "${#RECORD[*]}" -le "7" ] @@ -115,7 +115,7 @@ then (( NUMPOS=NUMPOS+1 )) LOG "Start Position: $STARTPOS, Number of samples: $NUMPOS" # Then put the corresponding noisecapt records into $NOISETMP. - tail --lines=+"$STARTPOS" $NOISEFILE | head --lines="$NUMPOS" > $NOISETMP + tail --lines=+"$STARTPOS" "$NOISEFILE" | head --lines="$NUMPOS" > $NOISETMP #RECORD[6]="${RECORD[6]//[$'\t\r\n']}" # Next is to figure out the data that we want to add to the PLANEFENCE record. # $NOISEFILE and $NOISECAPT have the following format, with all audio values in dBFS: @@ -133,12 +133,7 @@ then fi # Now write everything back to $CSVTMP, which we will then copy back over the old CSV file ( IFS=','; echo "${RECORD[*]}" >> "$CSVTMP" ) - LOG "The record now contains $(IFS=','; echo ${RECORD[*]})" - #for i in {0..10} - #do - # printf "%s," "${RECORD[i]}" >> "$CSVTMP" - #done - # printf "%s\n" "${RECORD[11]}" >> "$CSVTMP" + LOG "The record now contains ${RECORD[*]}" done < "$CSVFILE" # Now, if there is a $CSVTMP file, we will overwrite $CSVFILE with it. diff --git a/rootfs/usr/share/planefence/planefence.sh b/rootfs/usr/share/planefence/planefence.sh index cf10e9d1..c8904e81 100755 --- a/rootfs/usr/share/planefence/planefence.sh +++ b/rootfs/usr/share/planefence/planefence.sh @@ -7,7 +7,7 @@ # # Usage: ./planefence.sh # -# Copyright 2020-2023 Ramon F. Kolb - licensed under the terms and conditions +# Copyright 2020-2024 Ramon F. Kolb - licensed under the terms and conditions # of GPLv3. The terms and conditions of this license are included with the Github # distribution of this package, and are also available here: # https://github.com/kx1t/planefence/ @@ -31,7 +31,7 @@ # Only change the variables below if you know what you are doing. # all errors will show a line number and the command used to produce the error -trap 'echo -e "[ERROR] $(basename $0) in line $LINENO when executing: $BASH_COMMAND"' ERR +source /scripts/common # We need to define the directory where the config file is located: @@ -74,9 +74,8 @@ fi # first get DISTANCE unit: DISTUNIT="mi" DISTCONV=1 -if [ "$SOCKETCONFIG" != "" ] -then - case "$(grep "^distanceunit=" $SOCKETCONFIG |sed "s/distanceunit=//g")" in +if [[ -f "$SOCKETCONFIG" ]]; then + case "$(grep "^distanceunit=" "$SOCKETCONFIG" |sed "s/distanceunit=//g")" in nauticalmile) DISTUNIT="nm" ;; @@ -93,9 +92,8 @@ fi # get ALTITUDE unit: ALTUNIT="ft" -if [ "$SOCKETCONFIG" != "" ] -then - case "$(grep "^altitudeunit=" $SOCKETCONFIG |sed "s/altitudeunit=//g")" in +if [[ -f "$SOCKETCONFIG" ]]; then + case "$(grep "^altitudeunit=" "$SOCKETCONFIG" |sed "s/altitudeunit=//g")" in feet) ALTUNIT="ft" ;; @@ -110,8 +108,7 @@ fi # replace wget by curl to save memory space. Was: [[ "x$REMOTENOISE" != "x" ]] && [[ "$(wget -q -O /tmp/noisecapt-$FENCEDATE.log $REMOTENOISE/noisecapt-$FENCEDATE.log ; echo $?)" == "0" ]] && NOISECAPT=1 || NOISECAPT=0 if [[ "x$REMOTENOISE" != "x" ]] then - if [[ "$(curl --fail -s $REMOTENOISE/noisecapt-$FENCEDATE.log > /tmp/noisecapt-$FENCEDATE.log; echo $?)" == "0" ]] - then + if curl --fail -s "$REMOTENOISE/noisecapt-$FENCEDATE.log" > "/tmp/noisecapt-$FENCEDATE.log"; then NOISECAPT=1 else NOISECAPT=0 @@ -124,30 +121,32 @@ if [[ "$FUDGELOC" != "" ]] then if [[ "$FUDGELOC" == "0" ]] then - printf -v LON_VIS "%.0f" $LON - printf -v LAT_VIS "%.0f" $LAT + printf -v LON_VIS "%.0f" "$LON" + printf -v LAT_VIS "%.0f" "$LAT" elif [[ "$FUDGELOC" == "1" ]] then - printf -v LON_VIS "%.1f" $LON - printf -v LAT_VIS "%.1f" $LAT + printf -v LON_VIS "%.1f" "$LON" + printf -v LAT_VIS "%.1f" "$LAT" elif [[ "$FUDGELOC" == "2" ]] then - printf -v LON_VIS "%.2f" $LON - printf -v LAT_VIS "%.2f" $LAT + printf -v LON_VIS "%.2f" "$LON" + printf -v LAT_VIS "%.2f" "$LAT" else # If $FUDGELOC != "" but also != "2", then assume it is "3" - printf -v LON_VIS "%.3f" $LON - printf -v LAT_VIS "%.3f" $LAT + printf -v LON_VIS "%.3f" "$LON" + printf -v LAT_VIS "%.3f" "$LAT" fi # clean up the strings: else # let's not print more than 5 digits - printf -v LON_VIS "%.5f" $LON - printf -v LAT_VIS "%.5f" $LAT + printf -v LON_VIS "%.5f" "$LON" + printf -v LAT_VIS "%.5f" "$LAT" fi -LON_VIS="$(sed 's/^00*\|00*$//g' <<< $LON_VIS)" # strip any trailing zeros - "41.10" -> "41.1", or "41.00" -> "41." +# shellcheck disable=SC2001 +LON_VIS="$(sed 's/^00*\|00*$//g' <<< "$LON_VIS")" # strip any trailing zeros - "41.10" -> "41.1", or "41.00" -> "41." LON_VIS="${LON_VIS%.}" # If the last character is a ".", strip it - "41.1" -> "41.1" but "41." -> "41" -LAT_VIS="$(sed 's/^00*\|00*$//g' <<< $LAT_VIS)" # strip any trailing zeros - "41.10" -> "41.1", or "41.00" -> "41." +# shellcheck disable=SC2001 +LAT_VIS="$(sed 's/^00*\|00*$//g' <<< "$LAT_VIS")" # strip any trailing zeros - "41.10" -> "41.1", or "41.00" -> "41." LAT_VIS="${LAT_VIS%.}" # If the last character is a ".", strip it - "41.1" -> "41.1" but "41." -> "41" # @@ -158,7 +157,7 @@ LAT_VIS="${LAT_VIS%.}" # If the last character is a ".", strip it - "41.1" -> LOG () { # This reads a string from stdin and stores it in a variable called IN. This enables things like 'echo hello world > LOG' - while [ -n "$1" ] || read IN; do + while [ -n "$1" ] || read -r IN; do if [ -n "$1" ]; then IN="$1" fi @@ -168,7 +167,7 @@ LOG () then printf "%s-%s[%s]v%s: %s\n" "$(date +"%Y%m%d-%H%M%S")" "$PROCESS_NAME" "$CURRENT_PID" "$VERSION" "$IN" | logger else - printf "%s-%s[%s]v%s: %s\n" "$(date +"%Y%m%d-%H%M%S")" "$PROCESS_NAME" "$CURRENT_PID" "$VERSION" "$IN" >> $LOGFILE + printf "%s-%s[%s]v%s: %s\n" "$(date +"%Y%m%d-%H%M%S")" "$PROCESS_NAME" "$CURRENT_PID" "$VERSION" "$IN" >> "$LOGFILE" fi fi if [ -n "$1" ]; then @@ -243,8 +242,7 @@ EOF 1 hr avg EOF # If there are spectrograms for today, then also make a column for these: - if (( $(ls -1 "$OUTFILEDIR/noisecapt-spectro-$FENCEDATE*.png" 2>/dev/null |wc -l) > 0 )) - then + if compgen -G "$OUTFILEDIR/noisecapt-spectro-$FENCEDATE*.png" >/dev/null; then printf "Spectrogram\n" >> "$2" SPECTROPRINT="true" else @@ -279,7 +277,8 @@ EOF # do this for the whole INPUT at once, doing it for every line is slow (subshell, sed initialization) # Step 1/5. Replace the map zoom by whatever $HEATMAPZOOM contains - [[ -n "$HEATMAPZOOM" ]] && INPUT=$(sed 's|\(^.*&zoom=\)[0-9]*\(.*\)|\1'"$HEATMAPZOOM"'\2|' <<< "$INPUT") + # shellcheck disable=SC2001 + [[ -n "$HEATMAPZOOM" ]] && INPUT=$(sed 's|\(^.*&zoom=\)[0-9]*\(.*\)|\1'"$HEATMAPZOOM"'\2|' <<< "$INPUT") || true # Now write the table COUNTER=1 @@ -346,11 +345,10 @@ EOF STARTTIME=$(date +%s -d "${NEWVALUES[2]}") ENDTIME=$(date +%s -d "${NEWVALUES[3]}") (( ENDTIME - STARTTIME < 30 )) && ENDTIME=$(( STARTTIME + 30 )) - [[ -f "/usr/share/planefence/persist/.internal/noisecapt-$FENCEDATE.log" ]] && SPECTROFILE=noisecapt-spectro-$(date -d "@$(awk -F, -v a=$STARTTIME -v b=$ENDTIME 'BEGIN{c=-999; d=0}{if ($1>=0+a && $1<=1+b && $2>0+c) {c=$2; d=$1}} END{print d}' /usr/share/planefence/persist/.internal/noisecapt-$FENCEDATE.log)" +%y%m%d-%H%M%S).png || SPECTROFILE="" - # if it has a weird date, discard it because it wont exist. - # otherwise, go get it from the remote server: + [[ -f "/usr/share/planefence/persist/.internal/noisecapt-$FENCEDATE.log" ]] && SPECTROFILE=noisecapt-spectro-$(date -d "@$(awk -F, -v a="$STARTTIME" -v b="$ENDTIME" 'BEGIN{c=-999; d=0}{if ($1>=0+a && $1<=1+b && $2>0+c) {c=$2; d=$1}} END{print d}' /usr/share/planefence/persist/.internal/noisecapt-"$FENCEDATE".log)" +%y%m%d-%H%M%S).png || SPECTROFILE="" + # go get it from the remote server: # debug code: echo $REMOTENOISE/$SPECTROFILE to $OUTFILEDIR/$SPECTROFILE - [[ "$SPECTROFILE" == "noisecapt-spectro-691231-190000.png" ]] && SPECTROFILE="" || curl --fail -s "$REMOTENOISE/$SPECTROFILE" > "$OUTFILEDIR/$SPECTROFILE" + if ! curl --fail -s "$REMOTENOISE/$SPECTROFILE" > "$OUTFILEDIR/$SPECTROFILE"; then SPECTROFILE=""; fi else SPECTROFILE="" fi @@ -375,7 +373,7 @@ EOF # if it's not in the cache, look it up with the appropriate shell script if [[ -z $CACHEDNAME ]]; then - AIRLINENAME=$(/usr/share/planefence/airlinename.sh ${CALLSIGN} ${NEWVALUES[0]}) + AIRLINENAME=$(/usr/share/planefence/airlinename.sh "${CALLSIGN}" "${NEWVALUES[0]}") #echo ${CALLSIGN} ${AIRLINENAME} elif [[ $CACHEDNAME == "UNKNOWN" ]]; then AIRLINENAME="" @@ -501,19 +499,21 @@ EOF # right below. Right now, it lists all files that have the planefence-20*.html format (planefence-200504.html, etc.), and then # picks the newest 7 (or whatever HISTTIME is set to), reverses the strings to capture the characters 6-11 from the right, which contain the date (200504) # and reverses the results back so we get only a list of dates in the format yymmdd. - for d in $(ls -1 "$1"/planefence-??????.html | tail --lines=$((HISTTIME+1)) | head --lines=$HISTTIME | rev | cut -c6-11 | rev | sort -r) + # shellcheck disable=SC2012 + for d in $(ls -1 "$1"/planefence-??????.html | tail --lines=$((HISTTIME+1)) | head --lines="$HISTTIME" | rev | cut -c6-11 | rev | sort -r) do - printf " | %s" "$(date -d "$d" +%d-%b-%Y): " >> "$2" - printf "html - " "planefence-$(date -d "$d" +"%y%m%d").html" >> "$2" - printf "csv" "planefence-$(date -d "$d" +"%y%m%d").csv" >> "$2" + { printf " | %s" "$(date -d "$d" +%d-%b-%Y): " + printf "html - " "planefence-$(date -d "$d" +"%y%m%d").html" + printf "csv" "planefence-$(date -d "$d" +"%y%m%d").csv" + } >> "$2" done - printf "

\n" >> "$2" - printf "

Additional dates may be available by browsing to planefence-yymmdd.html in this directory.

" >> "$2" - printf "\n\n" >> "$2" + { printf "

\n" + printf "

Additional dates may be available by browsing to planefence-yymmdd.html in this directory.

" + printf "\n\n" + } >> "$2" # and print the footer: - if [ "$3" == "standalone" ] - then + if [[ "$3" == "standalone" ]]; then printf "\n\n" >>"$2" fi } @@ -534,9 +534,9 @@ then rm "$TMPLINES" 2>/dev/null rm "$OUTFILEHTML" 2>/dev/null rm "$OUTFILECSV" 2>/dev/null - rm $OUTFILEBASE-"$FENCEDATE"-table.html 2>/dev/null - rm $OUTFILETMP 2>/dev/null - rm $TMPDIR/dump1090-pf* 2>/dev/null + rm "$OUTFILEBASE-$FENCEDATE"-table.html 2>/dev/null + rm "$OUTFILETMP" 2>/dev/null + rm "$TMPDIR"/dump1090-pf* 2>/dev/null LOG "File cache reset- doing full run for $FENCEDATE" fi @@ -549,6 +549,7 @@ then else READLINES=0 fi +# shellcheck disable=SC2153 if [ -f "$TOTLINES" ] then read -r TOTALLINES < "$TOTLINES" @@ -588,12 +589,12 @@ SOCKETFILEYESTERDAY="$LOGFILEBASE$(date -d yesterday +%y%m%d).txt" if [[ -f $SOCKETFILEYESTERDAY ]] && (( $(date -d "1970-01-01 $(date +%T) +0:00" +%s) > PRUNEMINS * 60 )) then # If we're longer than PRUNEMINS into today, remove yesterday's file - rm -v -f $SOCKETFILEYESTERDAY + rm -v -f "$SOCKETFILEYESTERDAY" fi # if the PRUNESTARTFILE file doesn't exist # note down that we started up, write down 0 for the next prune as nothing will be older than PRUNEMINS -if ! [ -f "$PRUNESTARTFILE" ] || [[ "$LASTFENCEDATE" != "$FENCEDATE" ]]; then +if [[ ! -f "$PRUNESTARTFILE" ]] || [[ "$LASTFENCEDATE" != "$FENCEDATE" ]]; then echo 0 > $PRUNESTARTFILE # if PRUNESTARTFILE is older than PRUNEMINS, do the pruning elif [[ $(find $PRUNESTARTFILE -mmin +$PRUNEMINS | wc -l) == 1 ]]; then @@ -603,15 +604,15 @@ elif [[ $(find $PRUNESTARTFILE -mmin +$PRUNEMINS | wc -l) == 1 ]]; then CUTLINES=0 fi tmpfile=$(mktemp) - tail --lines=+$((CUTLINES + 1)) "$SOCKETFILE" > $tmpfile + tail --lines=+$((CUTLINES + 1)) "$SOCKETFILE" > "$tmpfile" # restart Socket30003 to ensure that things run smoothly: touch /tmp/socket-cleanup # this flags the socket30003 runfile not to complain about the exit and restart immediately killall /usr/bin/perl sleep .1 # give the script a moment to exit, then move the files - mv -f $tmpfile "$SOCKETFILE" - rm -f $tmpfile + mv -f "$tmpfile" "$SOCKETFILE" + rm -f "$tmpfile" # update line numbers (( READLINES -= CUTLINES )) @@ -639,13 +640,13 @@ echo "$TOTALLINES" > "$TOTLINES" LOG "Current run starts at line $READLINES of $CURRCOUNT, with $TOTALLINES lines for today" # Now create a temp file with the latest logs -tail --lines=+$READLINES "$SOCKETFILE" > $INFILETMP +tail --lines=+"$READLINES" "$SOCKETFILE" > "$INFILETMP" [[ "$BASETIME" != "" ]] && echo "2. $(bc -l <<< "$(date +%s.%2N) - $BASETIME")s -- invoking planefence.py" || true # First, run planefence.py to create the CSV file: LOG "Invoking planefence.py..." -$PLANEFENCEDIR/planefence.py --logfile=$INFILETMP --outfile=$OUTFILETMP --maxalt=$MAXALT --altcorr=$ALTCORR --dist=$DIST --distunit=$DISTUNIT --lat=$LAT --lon=$LON $VERBOSE $CALCDIST --trackservice=$TRACKSERVICE | LOG +$PLANEFENCEDIR/planefence.py --logfile="$INFILETMP" --outfile="$OUTFILETMP" --maxalt="$MAXALT" --altcorr="$ALTCORR" --dist="$DIST" --distunit="$DISTUNIT" --lat="$LAT" --lon="$LON" "$VERBOSE" "$CALCDIST" --trackservice="$TRACKSERVICE" | LOG LOG "Returned from planefence.py..." # Now we need to combine any double entries. This happens when a plane was in range during two consecutive Planefence runs @@ -721,6 +722,7 @@ $PLANEFENCEDIR/pf-fix.sh "$OUTFILECSV" # Ignore list -- first clean up the list to ensure there are no empty lines sed -i '/^$/d' "$IGNORELIST" 2>/dev/null # now apply the filter +# shellcheck disable=SC2126 LINESFILTERED=$(grep -i -f "$IGNORELIST" "$OUTFILECSV" 2>/dev/null | wc -l) if (( LINESFILTERED > 0 )) then @@ -743,80 +745,12 @@ then mv -f /tmp/pf-out.tmp "$OUTFILECSV" fi # rewrite LINESFILTERED to file - [[ -f /run/planefence/filtered-$FENCEDATE ]] && read -ra i < "/run/planefence/filtered-$FENCEDATE" || i=0 + if [[ -f /run/planefence/filtered-$FENCEDATE ]]; then read -r i < "/run/planefence/filtered-$FENCEDATE"; else i=0; fi echo $((LINESFILTERED + i)) > "/run/planefence/filtered-$FENCEDATE" fi -# Now see is IGNORETIME is set. If so, we need to filter duplicates -# We will do it all in memory - load OUTFILECSV into an array, process the array, and write back to disk: -#if [[ -f "$OUTFILECSV" ]] && [[ "$IGNORETIME" -gt 0 ]] -#then -# -# # read the entire OUTFILECSV into memory: line by line into 'l[]' -# unset l -# i=0 -# while IFS= read -r l[i] -# do -# (( i++ )) -# done < "$OUTFILECSV" -# -# # if the file was empty, stop processing -# -# # $l[] contains all the OUTFILECSV lines. $i contains the total line count -# # Loop through them in reverse order - skip the top one as the 1st entry is always unique -# # Note - if the file is empty or has only 1 element, then the initial value of j (=i-1) = -1 or 0 and the -# # loop will be skipped. This is intentional behavior. -# -# for (( j=i-1; j>0; j-- )) -# do -# unset r -# IFS=, read -ra r <<< "${l[j]}" -# # $l now contains the entire line, $r contains the line in records. Start time is in r[2]. End time is in r[3] -# # We now need to filter out any that are too close in time -# echo r: ${r[@]} -# echo rst: date -d "${r[2]}" +%s -# rst=$(date -d "${r[2]}" +%s) # get the record's start time in seconds (rst= r start time) -# icao="${r[0]}" # get the record's icao address -# for (( k=j-1; k>=0; k-- )) -# do -# # if the line is empty, continue, else read in the line -# [[ -z "${l[k]}" ]] && continue -# unset s -# IFS=, read -ra s <<< "${l[k]}" -# -# # skip/continue if ICAO don't match -# [[ "${s[0]}" != "$icao" ]] && continue -# -# # stop processing this loop if the time diff is larger -# tet=$(date -d "${s[3]}" +%s) # (tet= test's end time. Didn't want to use 'set') -# echo tet: date -d "${s[3]}" +%s -# (( rst - tet > IGNORETIME )) && break -# -# # If we're still here, then the ICAO's match and the time is within the IGNORETIME boundaries. -# # So we take action and empty out the entire string -# l[k]="" -# done -# done -# -# # Now, the array in memory contains the records, with empty lines for the dupes -# # Write back all lines except for the empty ones: -# rm -f /tmp/pf-out.tmp -# for ((a=0; a> /tmp/pf-out.tmp -# done -# # mv /tmp/pf-out.tmp "$OUTFILECSV" -# mv -f /tmp/pf-out.tmp /usr/share/planefence/persist -# -# # clean up some memory -# unset l r s i j k a rst tet icao -# -#fi - -#----end implementation of ignore list---# -# And see if we need to invoke PlaneTweet: - +# see if we need to invoke PlaneTweet: [[ "$BASETIME" != "" ]] && echo "7. $(bc -l <<< "$(date +%s.%2N) - $BASETIME")s -- done applying filters, invoking PlaneTweet" || true if [[ -n "$PLANETWEET" || "${PF_DISCORD,,}" == "true" || "${PF_DISCORD,,}" == "on" || -n "$MASTODON_SERVER" ]] && [[ -z "$1" ]] @@ -865,7 +799,7 @@ fi [[ "$BASETIME" != "" ]] && echo "10. $(bc -l <<< "$(date +%s.%2N) - $BASETIME")s -- done getting NoiseCapt stuff, invoking plane-alert.sh" || true # If $PLANEALERT=on then lets call plane-alert to see if the new lines contain any planes of special interest: -[ "$PLANEALERT" == "ON" ] && ( LOG "Calling Plane-Alert as $PLALERTFILE $INFILETMP"; $PLALERTFILE $INFILETMP; ) +[ "$PLANEALERT" == "ON" ] && ( LOG "Calling Plane-Alert as $PLALERTFILE $INFILETMP"; $PLALERTFILE "$INFILETMP"; ) # Next, we are going to print today's HTML file: # Note - all text between 'cat' and 'EOF' is HTML code: @@ -972,15 +906,16 @@ ${PF_MOTD}
  • Last update: $(date +"%b %d, %Y %R:%S %Z")
  • Maximum distance from ${LAT_VIS}°N, ${LON_VIS}°E: $DIST $DISTUNIT -
  • Only aircraft below $(printf "%'.0d" $MAXALT) $ALTUNIT are reported -
  • Data extracted from $(printf "%'.0d" $TOTALLINES) ADS-B messages received since midnight today +
  • Only aircraft below $(printf "%'.0d" "$MAXALT") $ALTUNIT are reported +
  • Data extracted from $(printf "%'.0d" "$TOTALLINES") ADS-B messages received since midnight today EOF [[ "$FUDGELOC" != "" ]] && printf "
  • Please note that the reported station coordinates and the center of the circle on the heatmap are rounded for privacy protection. They do not reflect the exact location of the station.\n" >> "$OUTFILEHTMTMP" -[[ -f "/run/planefence/filtered-$FENCEDATE" ]] && [[ -f "$IGNORELIST" ]] && (( $(grep -c "^[^#;]" $IGNORELIST) > 0 )) && printf "
  • %d entries were filtered out today because of an ignore list\n" "$(> "$OUTFILEHTMTMP" +[[ -f "/run/planefence/filtered-$FENCEDATE" ]] && [[ -f "$IGNORELIST" ]] && (( $(grep -c "^[^#;]" "$IGNORELIST") > 0 )) && printf "
  • %d entries were filtered out today because of an ignore list\n" "$(<"/run/planefence/filtered-$FENCEDATE")" >> "$OUTFILEHTMTMP" [[ "$PA_LINK" != "" ]] && printf "
  • Additionally, click here to visit Plane Alert: a watchlist of aircraft in general range of the station.\n" "$PA_LINK" >> "$OUTFILEHTMTMP" +# shellcheck disable=SC2129 cat <>"$OUTFILEHTMTMP" @@ -1002,14 +937,14 @@ cat <>"$OUTFILEHTMTMP"
      EOF -printf "
    • Click on the Transponder ID to see the full flight information/history (from AdsbExchange)" >> "$OUTFILEHTMTMP" +printf "
    • Click on the Transponder ID to see the full flight information/history (from AdsbExchange)" "$LAT_VIS" "$LON_VIS" >> "$OUTFILEHTMTMP" printf "
    • Click on the Flight Number to see the full flight information/history (from FlightAware)" >> "$OUTFILEHTMTMP" printf "
    • Click on the Owner Information to see the FAA record for this plane (private, US registered planes only)" >> "$OUTFILEHTMTMP" (( ALTCORR > 0 )) && printf "
    • Minimum altitude is the altitude above local ground level, which is %s %s MSL." "$ALTCORR" "$ALTUNIT" >> "$OUTFILEHTMTMP" || printf "
    • Minimum altitude is the altitude above sea level." >> "$OUTFILEHTMTMP" [[ "$PLANETWEET" != "" ]] && printf "
    • Click on the word "yes" in the Tweeted column to see the Tweet.\n
    • Note that tweets are issued after a slight delay\n" >> "$OUTFILEHTMTMP" [[ "$PLANETWEET" != "" ]] && printf "
    • Get notified instantaneously of aircraft in range by following @%s on Twitter!\n" "$PLANETWEET" "$PLANETWEET" >> "$OUTFILEHTMTMP" -(( $(find $TMPDIR/noisecapt-spectro*.png -daystart -maxdepth 1 -mmin -1440 -print 2>/dev/null | wc -l ) > 0 )) && printf "
    • Click on the word "Spectrogram" to see the audio spectrogram of the noisiest period while the aircraft was in range\n" >> "$OUTFILEHTMTMP" +(( $(find "$TMPDIR"/noisecapt-spectro*.png -daystart -maxdepth 1 -mmin -1440 -print 2>/dev/null | wc -l ) > 0 )) && printf "
    • Click on the word "Spectrogram" to see the audio spectrogram of the noisiest period while the aircraft was in range\n" >> "$OUTFILEHTMTMP" [[ "$PLANEALERT" == "ON" ]] && printf "
    • See a list of aircraft matching the station's Alert List here\n" >> "$OUTFILEHTMTMP" printf "
    • Press the header of any of the columns to sort by that column.\n" >> "$OUTFILEHTMTMP" @@ -1055,6 +990,7 @@ fi # if $PLANEHEATHTML exists, then add the heatmap if [ -f "$PLANEHEATHTML" ] then + # shellcheck disable=SC2129 cat <>"$OUTFILEHTMTMP"
      @@ -1117,13 +1053,13 @@ EOF [[ "$BASETIME" != "" ]] && echo "16. $(bc -l <<< "$(date +%s.%2N) - $BASETIME")s -- starting final cleanup" || true -pushd "$OUTFILEDIR" > /dev/null +pushd "$OUTFILEDIR" > /dev/null || true mv -f "$OUTFILEHTMTMP" "$OUTFILEHTML" ln -sf "${OUTFILEHTML##*/}" index.html -popd > /dev/null +popd > /dev/null || true # VERY last thing... ensure that the log doesn't overflow: -if [ "$VERBOSE" != "" ] && [ "$LOGFILE" != "" ] && [ "$LOGFILE" != "logger" ] && [[ -f $LOGFILE ]] && (( $(wc -l < $LOGFILE) > 8000 )) +if [ "$VERBOSE" != "" ] && [ "$LOGFILE" != "" ] && [ "$LOGFILE" != "logger" ] && [[ -f $LOGFILE ]] && (( $(wc -l < "$LOGFILE") > 8000 )) then #sed -i -e :a -e '$q;N;8000,$D;ba' tail -n 4000 "$LOGFILE" > "$LOGFILE.tmp"