2020-04-08 20:31:01 -06:00
|
|
|
#!/bin/sh
|
|
|
|
true <<'LICENSE'
|
2024-05-29 01:45:25 -06:00
|
|
|
Part of AREDN® -- Used for creating Amateur Radio Emergency Data Networks
|
2020-04-08 20:31:01 -06:00
|
|
|
Copyright (C) 2020 Darryl Quinn K5DLQ
|
|
|
|
See Contributors file for additional contributors
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation version 3 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Additional Terms:
|
|
|
|
|
2024-05-29 01:45:25 -06:00
|
|
|
Additional use restrictions exist on the AREDN® trademark and logo.
|
2020-04-08 20:31:01 -06:00
|
|
|
See AREDNLicense.txt for more info.
|
|
|
|
|
2024-05-29 01:45:25 -06:00
|
|
|
Attributions to the AREDN® Project must be retained in the source code.
|
2020-04-08 20:31:01 -06:00
|
|
|
If importing this code into a new or existing project attribution
|
2024-05-29 01:45:25 -06:00
|
|
|
to the AREDN® project must be added to the source code.
|
2020-04-08 20:31:01 -06:00
|
|
|
|
|
|
|
You must not misrepresent the origin of the material contained within.
|
|
|
|
|
|
|
|
Modified versions must be modified to attribute to the original source
|
|
|
|
and be marked in reasonable ways as differentiate it from the original
|
|
|
|
version.
|
|
|
|
|
|
|
|
LICENSE
|
|
|
|
|
2023-07-08 23:09:02 -06:00
|
|
|
function retrieve_alert() {
|
|
|
|
url=$1
|
|
|
|
file=$2
|
|
|
|
label=$3
|
|
|
|
|
|
|
|
# label is an optional argument
|
|
|
|
[ -z "$label" ] && label=$file
|
|
|
|
|
|
|
|
wget -q -O "${file}" -P /tmp "${url}"
|
|
|
|
if [ -s "/tmp/${file}" ]; then
|
|
|
|
echo "<strong>↣ ${label}:</strong>"|cat - "/tmp/${file}" > /tmp/out &&
|
|
|
|
echo "<p>" >> /tmp/out &&
|
|
|
|
mv /tmp/out "/tmp/${file}"
|
|
|
|
|
|
|
|
# return success
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-04-08 20:31:01 -06:00
|
|
|
# does the node have access to downloads.arednmesh.org
|
2020-08-29 08:19:27 -06:00
|
|
|
ping -q -W10 -c1 downloads.arednmesh.org > /dev/null &&
|
2020-04-08 20:31:01 -06:00
|
|
|
online=true;
|
2020-08-29 08:19:27 -06:00
|
|
|
[ -f /tmp/aredn_message ] &&
|
2020-04-08 20:31:01 -06:00
|
|
|
rm /tmp/aredn_message
|
|
|
|
|
2020-08-22 08:50:58 -06:00
|
|
|
nodename=$(echo "$HOSTNAME" | tr 'A-Z' 'a-z')
|
2020-04-08 20:31:01 -06:00
|
|
|
|
2022-12-22 13:22:49 -07:00
|
|
|
if [ "$online" = "true" ]
|
2020-04-08 20:31:01 -06:00
|
|
|
then
|
|
|
|
# fetch node specific message file
|
2023-07-08 23:09:02 -06:00
|
|
|
retrieve_alert http://downloads.arednmesh.org/messages/${nodename}.txt aredn_message ${nodename}
|
2020-04-08 20:31:01 -06:00
|
|
|
if [ $? -ne 0 ] # no node specific file
|
|
|
|
then
|
|
|
|
# fetch broadcast message file
|
2024-04-29 19:34:42 -06:00
|
|
|
retrieve_alert http://downloads.arednmesh.org/messages/all.txt aredn_message "all nodes"
|
2020-04-08 20:31:01 -06:00
|
|
|
else
|
|
|
|
# need to append to node file
|
2023-07-08 23:09:02 -06:00
|
|
|
retrieve_alert http://downloads.arednmesh.org/messages/all.txt aredn_message_all "all nodes"
|
2024-06-07 19:39:44 -06:00
|
|
|
if [ -s "/tmp/aredn_message_all" ]; then
|
|
|
|
echo "<br />" >> /tmp/aredn_message
|
|
|
|
cat /tmp/aredn_message_all >> /tmp/aredn_message
|
|
|
|
rm /tmp/aredn_message_all
|
|
|
|
fi
|
2020-04-08 20:31:01 -06:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-08-18 15:17:03 -06:00
|
|
|
# are local alerts enabled? uci: aredn.alerts.localpath != NULL
|
|
|
|
alertslocalpath=$(uci -q get aredn.@alerts[0].localpath)
|
2023-07-08 23:09:02 -06:00
|
|
|
if [ -n "$alertslocalpath" ]; then
|
2023-08-14 23:53:38 -06:00
|
|
|
cat /dev/null > /tmp/local_message # initialize local_message file
|
2023-07-08 23:09:02 -06:00
|
|
|
|
|
|
|
# try node specific message file
|
|
|
|
retrieve_alert "${alertslocalpath}/${nodename}.txt" "${nodename}-alert" "${nodename}" &&
|
|
|
|
FILES="${nodename}"
|
|
|
|
|
|
|
|
# try group messages uci: aredn.alerts.groups != NULL
|
|
|
|
alertgroups=$(uci -q get aredn.@alerts[0].groups)
|
|
|
|
if [ -n "$alertgroups" ]; then
|
|
|
|
IFS=',' # split multiple groups on comma
|
|
|
|
for group in $alertgroups; do
|
|
|
|
groupname=$(echo $group | xargs | tr 'A-Z' 'a-z')
|
|
|
|
retrieve_alert "${alertslocalpath}/${groupname}.txt" "${groupname}-alert" "${groupname}" &&
|
|
|
|
FILES="${FILES} ${groupname}"
|
|
|
|
done
|
|
|
|
IFS=' ' # reset IFS
|
|
|
|
fi
|
|
|
|
|
|
|
|
# try broadcast message file
|
|
|
|
retrieve_alert "${alertslocalpath}/all.txt" "all-alert" "all nodes" &&
|
|
|
|
FILES="${FILES} all"
|
|
|
|
|
|
|
|
# combine all files
|
|
|
|
if [ -n "$FILES" ];then
|
|
|
|
for FILE in $FILES; do
|
|
|
|
cat /tmp/${FILE}-alert >> /tmp/local_message
|
|
|
|
rm /tmp/${FILE}-alert
|
|
|
|
done
|
2020-08-18 15:17:03 -06:00
|
|
|
fi
|
|
|
|
fi
|