diff --git a/rootfs/usr/share/planefence/noise2fence.sh b/rootfs/usr/share/planefence/noise2fence.sh index 0cc220b..792e655 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 cf10e9d..c8904e8 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
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 "