From c121e060d16e297b12f2bfbe23fc90e945f5fcd3 Mon Sep 17 00:00:00 2001 From: kx1t <15090643+kx1t@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:35:27 -0400 Subject: [PATCH] Add max toot length check / toot truncation (#13), fix linter issues --- buildnow.sh | 4 ++-- .../etc/s6-overlay/scripts/10-container-init | 2 +- .../s6-overlay/scripts/40-check-ais-notify | 2 +- .../etc/s6-overlay/scripts/60-check-mastodon | 2 +- .../etc/s6-overlay/scripts/80-tropoalert-init | 2 +- rootfs/etc/s6-overlay/scripts/ais-collect | 2 +- rootfs/etc/s6-overlay/scripts/tropo-alert | 2 +- rootfs/healthcheck/healthcheck.sh | 1 + rootfs/opt/data/masto-l10n-de_DE.db | 4 ++-- rootfs/opt/data/masto-l10n-en_US.db | 4 ++-- rootfs/opt/data/masto-l10n-es_ES.db | 6 +++--- rootfs/opt/data/masto-l10n-fr_FR.db | 4 ++-- rootfs/opt/data/masto-l10n-nl_NL.db | 4 ++-- rootfs/tools/force_notify | 2 +- rootfs/usr/share/vesselalert/save_databases | 2 +- rootfs/usr/share/vesselalert/send_mastodon | 21 ++++++++++++++----- 16 files changed, 38 insertions(+), 26 deletions(-) diff --git a/buildnow.sh b/buildnow.sh index 21f15d1..d6ba7dd 100755 --- a/buildnow.sh +++ b/buildnow.sh @@ -7,10 +7,10 @@ [[ "$ARCHS" == "" ]] && ARCHS="linux/armhf,linux/arm64,linux/amd64" BASETARGET1=ghcr.io/sdr-enthusiasts -BASETARGET2=kx1t +#BASETARGET2=kx1t IMAGE1="$BASETARGET1/$(pwd | sed -n 's|.*/docker-\(.*\)|\1|p'):$TAG" -IMAGE2="$BASETARGET2/$(pwd | sed -n 's|.*/docker-\(.*\)|\1|p'):$TAG" +#IMAGE2="$BASETARGET2/$(pwd | sed -n 's|.*/docker-\(.*\)|\1|p'):$TAG" echo "press enter to start building $IMAGE1 from $BRANCH" diff --git a/rootfs/etc/s6-overlay/scripts/10-container-init b/rootfs/etc/s6-overlay/scripts/10-container-init index 7b53a86..881198b 100755 --- a/rootfs/etc/s6-overlay/scripts/10-container-init +++ b/rootfs/etc/s6-overlay/scripts/10-container-init @@ -1,5 +1,5 @@ #!/command/with-contenv bash -# shellcheck shell=bash disable=SC1091 +# shellcheck shell=bash disable=SC1091,SC2154 source /scripts/common "${s6wrap[@]}" echo "[INFO] Starting VesselAlert version $(cat /.CONTAINER_VERSION)" diff --git a/rootfs/etc/s6-overlay/scripts/40-check-ais-notify b/rootfs/etc/s6-overlay/scripts/40-check-ais-notify index 1e74d43..08c5329 100755 --- a/rootfs/etc/s6-overlay/scripts/40-check-ais-notify +++ b/rootfs/etc/s6-overlay/scripts/40-check-ais-notify @@ -1,5 +1,5 @@ #!/command/with-contenv bash -# shellcheck shell=bash disable=SC1091 +# shellcheck shell=bash disable=SC1091,SC2154 # Check to make sure the correct parameters are defined. #--------------------------------------------------------------------------------------------- diff --git a/rootfs/etc/s6-overlay/scripts/60-check-mastodon b/rootfs/etc/s6-overlay/scripts/60-check-mastodon index 750cdc9..bbe67a2 100755 --- a/rootfs/etc/s6-overlay/scripts/60-check-mastodon +++ b/rootfs/etc/s6-overlay/scripts/60-check-mastodon @@ -1,5 +1,5 @@ #!/command/with-contenv bash -#shellcheck shell=bash disable=SC2015,SC1091 +#shellcheck shell=bash disable=SC2015,SC1091,SC2154 #--------------------------------------------------------------------------------------------- # Copyright (C) 2022-2023, Ramon F. Kolb (kx1t) diff --git a/rootfs/etc/s6-overlay/scripts/80-tropoalert-init b/rootfs/etc/s6-overlay/scripts/80-tropoalert-init index 96bfa86..ec1ffdf 100755 --- a/rootfs/etc/s6-overlay/scripts/80-tropoalert-init +++ b/rootfs/etc/s6-overlay/scripts/80-tropoalert-init @@ -1,5 +1,5 @@ #!/command/with-contenv bash -# shellcheck shell=bash disable=SC1091 +# shellcheck shell=bash disable=SC1091,SC2154 source /scripts/common if ! chk_enabled "${TROPOALERT:-enabled}"; then diff --git a/rootfs/etc/s6-overlay/scripts/ais-collect b/rootfs/etc/s6-overlay/scripts/ais-collect index 55b4fc7..7669f8f 100755 --- a/rootfs/etc/s6-overlay/scripts/ais-collect +++ b/rootfs/etc/s6-overlay/scripts/ais-collect @@ -1,6 +1,6 @@ #!/command/with-contenv bash #shellcheck shell=bash -#shellcheck disable=SC2016,SC2068,SC2076,SC2086,SC2015,SC2164,SC1090,SC1091 +#shellcheck disable=SC2016,SC2068,SC2076,SC2086,SC2015,SC2164,SC1090,SC1091,SC2154 # AIS-Collect: # read AIS data from a AIS-Catcher web service and diff --git a/rootfs/etc/s6-overlay/scripts/tropo-alert b/rootfs/etc/s6-overlay/scripts/tropo-alert index 73ba2e5..f312f04 100755 --- a/rootfs/etc/s6-overlay/scripts/tropo-alert +++ b/rootfs/etc/s6-overlay/scripts/tropo-alert @@ -1,6 +1,6 @@ #!/command/with-contenv bash #shellcheck shell=bash -#shellcheck disable=SC2015,SC1090,SC2164,SC2001,SC1091 +#shellcheck disable=SC2015,SC1090,SC2164,SC2001,SC1091,SC2154 # AIS Tropo Alert # Based on, and improved upon AISTropoAlert by Jeffrey Luszcz diff --git a/rootfs/healthcheck/healthcheck.sh b/rootfs/healthcheck/healthcheck.sh index 622b83a..d818aca 100755 --- a/rootfs/healthcheck/healthcheck.sh +++ b/rootfs/healthcheck/healthcheck.sh @@ -1,4 +1,5 @@ #!/command/with-contenv bash +# shellcheck shell=bash #--------------------------------------------------------------------------------------------- # Copyright (C) 2022-2023, Ramon F. Kolb (kx1t) diff --git a/rootfs/opt/data/masto-l10n-de_DE.db b/rootfs/opt/data/masto-l10n-de_DE.db index fc281a4..d65f626 100644 --- a/rootfs/opt/data/masto-l10n-de_DE.db +++ b/rootfs/opt/data/masto-l10n-de_DE.db @@ -31,10 +31,10 @@ MASTO_TERM[SPEED]="Geschwindigkeit" MASTO_TERM[HEADING]="Richtung" MASTO_TERM[DESTINATION]="Reiseziel" MASTO_TERM[SIGNAL]="Signal" -MASTO_TERM[LOCATION]="Schiffsstandort" +MASTO_TERM[LOCATION]="Schiffsangaben" MASTO_TERM[ISMOVING]="is unterwegs" MASTO_TERM[ISSEENON]="beobachtet um" MASTO_TERM[AGAIN]="Wiederholung:" MASTO_TERM[NEW2]="Neu:" MASTO_TERM[DIST_SINCE_LAST]="hat sich seit der letzten Meldung um %.1f sm bewegt" -MASTO_TERM[DISTANCE]="Entfernung vom Empfänger" +MASTO_TERM[DISTANCE]="Entfernung" diff --git a/rootfs/opt/data/masto-l10n-en_US.db b/rootfs/opt/data/masto-l10n-en_US.db index 5067b58..3d28824 100644 --- a/rootfs/opt/data/masto-l10n-en_US.db +++ b/rootfs/opt/data/masto-l10n-en_US.db @@ -31,10 +31,10 @@ MASTO_TERM[SPEED]="Speed" MASTO_TERM[HEADING]="Heading" MASTO_TERM[DESTINATION]="Destination" MASTO_TERM[SIGNAL]="Signal" -MASTO_TERM[LOCATION]="Vessel location" +MASTO_TERM[LOCATION]="Details" MASTO_TERM[ISMOVING]="is on the move" MASTO_TERM[ISSEENON]="is seen on" MASTO_TERM[AGAIN]="Again:" MASTO_TERM[NEW2]="New:" MASTO_TERM[DIST_SINCE_LAST]="moved %.1f nm since last notification" -MASTO_TERM[DISTANCE]="Distance from receiver" \ No newline at end of file +MASTO_TERM[DISTANCE]="Distance" diff --git a/rootfs/opt/data/masto-l10n-es_ES.db b/rootfs/opt/data/masto-l10n-es_ES.db index 3495f92..baf6616 100644 --- a/rootfs/opt/data/masto-l10n-es_ES.db +++ b/rootfs/opt/data/masto-l10n-es_ES.db @@ -25,16 +25,16 @@ MASTO_TERM[CALLSIGN]="Indicativo" MASTO_TERM[SHIPTYPE]="Tipo" MASTO_TERM[FLAG]="Bandera" MASTO_TERM[MSGS_RECVD]="Mensajes Recibidos" -MASTO_TERM[SEEN_ON]="Visto últimamente" +MASTO_TERM[SEEN_ON]="Visto últ." MASTO_TERM[STATUS]="Estado" MASTO_TERM[SPEED]="Velocidad" MASTO_TERM[HEADING]="Rumbo" MASTO_TERM[DESTINATION]="Destino" MASTO_TERM[SIGNAL]="Señal" -MASTO_TERM[LOCATION]="Ubicacion del barco" +MASTO_TERM[LOCATION]="Detalles" MASTO_TERM[ISMOVING]="está en marcha" MASTO_TERM[ISSEENON]="fue visto a la hora" MASTO_TERM[AGAIN]="Nuevamente:" MASTO_TERM[NEW2]="Nuevo:" MASTO_TERM[DIST_SINCE_LAST]="se ha transladado %.1f nm desde la última notificación" -MASTO_TERM[DISTANCE]="Distancia del receptor" +MASTO_TERM[DISTANCE]="Distancia" diff --git a/rootfs/opt/data/masto-l10n-fr_FR.db b/rootfs/opt/data/masto-l10n-fr_FR.db index c448508..bfc0bc0 100644 --- a/rootfs/opt/data/masto-l10n-fr_FR.db +++ b/rootfs/opt/data/masto-l10n-fr_FR.db @@ -30,10 +30,10 @@ MASTO_TERM[SPEED]="Vitesse" MASTO_TERM[HEADING]="Cap" MASTO_TERM[DESTINATION]="Destination" MASTO_TERM[SIGNAL]="Signal" -MASTO_TERM[LOCATION]="Localisation du navire" +MASTO_TERM[LOCATION]="Détails" MASTO_TERM[ISMOVING]="est en mouvement" MASTO_TERM[ISSEENON]="est vu à" MASTO_TERM[AGAIN]="A nouveau:" MASTO_TERM[NEW2]="Nouveau:" MASTO_TERM[DIST_SINCE_LAST]="déplacé de %.1f nm depuis la dernière notification" -MASTO_TERM[DISTANCE]="Distance du récepteur" +MASTO_TERM[DISTANCE]="Distance" diff --git a/rootfs/opt/data/masto-l10n-nl_NL.db b/rootfs/opt/data/masto-l10n-nl_NL.db index d328b77..9f5d648 100644 --- a/rootfs/opt/data/masto-l10n-nl_NL.db +++ b/rootfs/opt/data/masto-l10n-nl_NL.db @@ -30,10 +30,10 @@ MASTO_TERM[SPEED]="Snelheid" MASTO_TERM[HEADING]="Richting" MASTO_TERM[DESTINATION]="Doel" MASTO_TERM[SIGNAL]="Signaal" -MASTO_TERM[LOCATION]="Schip locatie" +MASTO_TERM[LOCATION]="Details" MASTO_TERM[ISMOVING]="is onderweg" MASTO_TERM[ISSEENON]="is gezien om" MASTO_TERM[AGAIN]="Herhaling:" MASTO_TERM[NEW2]="Nieuw:" MASTO_TERM[DIST_SINCE_LAST]="%.1f nm verplaatst sinds de vorige notificatie" -MASTO_TERM[DISTANCE]="Afstand van ontvanger" +MASTO_TERM[DISTANCE]="Afstand" diff --git a/rootfs/tools/force_notify b/rootfs/tools/force_notify index 7d8123d..b7ae955 100755 --- a/rootfs/tools/force_notify +++ b/rootfs/tools/force_notify @@ -1,6 +1,6 @@ #!/command/with-contenv bash #shellcheck shell=bash -#shellcheck disable=SC1090,SC2015,SC1091 +#shellcheck disable=SC1090,SC2015,SC1091,SC2302,SC2303 # AIS-Collect: # read AIS data from a AIS-Catcher web service and diff --git a/rootfs/usr/share/vesselalert/save_databases b/rootfs/usr/share/vesselalert/save_databases index 4fe82d5..2f0b7fe 100755 --- a/rootfs/usr/share/vesselalert/save_databases +++ b/rootfs/usr/share/vesselalert/save_databases @@ -1,5 +1,5 @@ #!/command/with-contenv bash -#shellcheck shell=bash disable=SC2015 +#shellcheck shell=bash disable=SC2015,SC2154,SC1091 #--------------------------------------------------------------------------------------------- # Copyright (C) 2022-2023, Ramon F. Kolb (kx1t) # diff --git a/rootfs/usr/share/vesselalert/send_mastodon b/rootfs/usr/share/vesselalert/send_mastodon index 55793d8..a9733ae 100755 --- a/rootfs/usr/share/vesselalert/send_mastodon +++ b/rootfs/usr/share/vesselalert/send_mastodon @@ -1,5 +1,5 @@ #!/command/with-contenv bash -#shellcheck shell=bash disable=SC2015,SC2164,SC1090,SC1091,SC2154 +#shellcheck shell=bash disable=SC2015,SC2164,SC1090,SC1091,SC2154,SC2001 #--------------------------------------------------------------------------------------------- # Copyright (C) 2022-2023, Ramon F. Kolb (kx1t) # @@ -104,18 +104,29 @@ if [[ -n "${VESSELS[$1:lat]}" ]] && [[ -n "${VESSELS[$1:lon]}" ]] && [[ -n "$LAT fi mast_str+="${MASTO_TERM[SIGNAL]} #RSSI: $(printf "%.1f dBFS" "${VESSELS[$1:level]}")\n" -[[ -n "${links}" ]] && mast_str+="${links}\n" || true + [[ -n "${NOTIFICATION_MAPURL}" ]] && [[ "${NOTIFICATION_MAPURL:0:4}" != "http" ]] && mast_str+="${MASTO_TERM[LOCATION]}: ${AIS_URL}?mmsi=${VESSELS[$1:mmsi]}\n" || true [[ -n "${NOTIFICATION_MAPURL}" ]] && [[ "${NOTIFICATION_MAPURL:0:4}" == "http" ]] && mast_str+="${MASTO_TERM[LOCATION]}: ${NOTIFICATION_MAPURL}?mmsi=${VESSELS[$1:mmsi]}\n" || true +[[ -n "${links}" ]] && mast_str+="${links}\n" || true -[[ -n "$MASTODON_CUSTOM_FIELD" ]] && mast_str+="\n$MASTODON_CUSTOM_FIELD" || true +mast_str+="\n" -mast_str+="\n#Ship #Vessel #AIS" -mast_str+="\n#VesselAlert © 2023-2024 kx1t" +[[ -n "$MASTODON_CUSTOM_FIELD" ]] && mast_str+="$MASTODON_CUSTOM_FIELD\n" || true + +mast_str+="#Ship #Vessel #AIS\n" +mast_str+="#VesselAlert © 2023-2024 kx1t" #shellcheck disable=SC2001 mast_str="$(sed -e 's|\\n|\n|g' <<< "$mast_str")" +# test and correct if max toot length is exceeded +toot_length="$(sed 's/http[^ ]*/xxxxxxxxxxxxxxxxxxxxxxxx/g' <<<"${mast_str//$'\n'/ }" | wc -m)" +if (( toot_length >= 500 )); then + new_length="$(( ${#mast_str} - toot_length + 496 ))" + mast_str="${mast_str:0:$new_length}..." + "${s6wrap[@]}" echo "[WARNING] Mastodon Notification Truncated: it was $(( toot_length - 499)) characters too long" +fi + # Now we have the notification string, lets upload an image if one exists: # If the image still exists, then upload it to Mastodon: