diff --git a/.gitignore b/.gitignore index db2fc0d..d173cb8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ secrets +*.csv diff --git a/collector.sh b/collector.sh index 020dea6..959ae89 100755 --- a/collector.sh +++ b/collector.sh @@ -1,3 +1,4 @@ +#!/usr/bin/sh # Collects and logs data from the OpenShipData API and the OSM API # source ./secrets @@ -21,3 +22,21 @@ province=$(echo "$osm_response" | jq --raw-output .address.province) country=$(echo "$osm_response" | jq --raw-output .address.country) echo "La ville la plus proche est $town dans la province de $province, $country" + +curl -s -d "Donnees collectes" $NTFY_ENDPOINT + +# store values in file +if ! [ -e "$DATA_FILE" ] ; then + touch $DATA_FILE + echo "timestamp,latitude,longitude,bearing,speed,town,province,country" >> $DATA_FILE +fi + +if ! [ -w "$DATA_FILE" ] ; then + echo "$DATA_FILE is not writeable" + exit 1 +fi + +timestamp=$(date) +echo "\"$timestamp\",$lat,$lon,$bearing,$speed,\"$town\",\"$province\",\"$country\"" >> $DATA_FILE + +exit 0 diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..4721a34 --- /dev/null +++ b/install.sh @@ -0,0 +1,19 @@ +#!/usr/bin/sh + + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +echo $SCRIPT_DIR + +cp lighthouse.service.default lighthouse.service +sed -i 's|WORKING_DIR|'"$SCRIPT_DIR"'|g' lighthouse.service + + +cp ./lighthouse.service /etc/systemd/system/. +cp ./lighthouse.timer /etc/systemd/system/. + +systemctl daemon-reload +systemctl enable lighthouse.service +systemctl enable lighthouse.timer +systemctl start lighthouse.timer + +echo "All done." diff --git a/lighthouse.service.default b/lighthouse.service.default new file mode 100644 index 0000000..45583f5 --- /dev/null +++ b/lighthouse.service.default @@ -0,0 +1,10 @@ +[Unit] +Description=Lighthouse vessel tracker and notification +After=network.target + +[Service] +WorkingDirectory=WORKING_DIR +ExecStart=WORKING_DIR/collector.sh + +[Install] +WantedBy=default.target diff --git a/lighthouse.timer b/lighthouse.timer new file mode 100644 index 0000000..612e52f --- /dev/null +++ b/lighthouse.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Run the Lighthouse collector every 10 minutes + +[Timer] +OnCalendar=*:0/15 +Persistent=true + +[Install] +WantedBy=basic.target diff --git a/secrets.example b/secrets.example index cb53f4a..813108b 100644 --- a/secrets.example +++ b/secrets.example @@ -1,3 +1,5 @@ #!/bin/bash MMSI=#MMSI of the ship to track KEY=#OpenShipData API key +DATA_FILE=# output file location +NTFY_ENDPOINT=# address of ntfy endpoint with topic name