aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-04-19 17:34:11 +0200
committerMattias Andrée <maandree@kth.se>2016-04-19 17:34:11 +0200
commit4fb16a6998ea6bd33f6e0cba51d541d146370531 (patch)
treedc090437ac190aaf9ed4dc95d5f2b943830c43a1
parentupdate doc (diff)
downloadmetar-4fb16a6998ea6bd33f6e0cba51d541d146370531.tar.gz
metar-4fb16a6998ea6bd33f6e0cba51d541d146370531.tar.bz2
metar-4fb16a6998ea6bd33f6e0cba51d541d146370531.tar.xz
add support for ~/.config/geolocation and /etc/geolocation1
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rwxr-xr-xmetar35
1 files changed, 32 insertions, 3 deletions
diff --git a/metar b/metar
index b9c68c8..4953882 100755
--- a/metar
+++ b/metar
@@ -1,8 +1,10 @@
#!/bin/sh
+set -e
+
usage ()
{
- echo "usage: $0 (get | print | set STATION | list [PREFIX] | closest LATITUDE LONGITUDE [LIST])"
+ echo "usage: $0 (get | print | set STATION | list [PREFIX] | closest [LATITUDE LONGITUDE] [LIST])"
}
get_station ()
@@ -20,6 +22,27 @@ get_station ()
echo "$icao"
}
+get_location ()
+{
+ geo=""
+ if test -f ~/.config/geolocation; then
+ geo="$(cat ~/.config/geolocation | head -n 1)"
+ geof=~/.config/geolocation
+ elif test -f /etc/geolocation; then
+ geo="$(cat /etc/geolocation | head -n 1)"
+ geof=/etc/geolocation
+ fi
+ if test -z "$geo"; then
+ echo 'No location has been specificed or configured.' >&2
+ exit 1
+ fi
+ if ! test $(printf '%s\n' $geo | wc -l) = 2; then
+ echo "Invalid geolocation configuration (${geof})." >&2
+ exit 1
+ fi
+ echo "$geo"
+}
+
list_stations ()
{
file="$(mktemp)"
@@ -45,8 +68,8 @@ get_closest ()
location="$(echo "$line" | cut -d ')' -f 2 | cut -d ' ' -f 2,3)"
latitude="$(echo "$location" | cut -d ' ' -f 1)"
longitude="$(echo "$location" | cut -d ' ' -f 2)"
- north="$(echo "$latitude" | grep 'S' > /dev/null; echo $?)"
- east="$(echo "$longitude" | grep 'W' > /dev/null; echo $?)"
+ north="$(set +e; echo "$latitude" | grep 'S' > /dev/null; echo $?)"
+ east="$(set +e; echo "$longitude" | grep 'W' > /dev/null; echo $?)"
latitude="$(echo "$latitude" | tr -d NSEW | sed 's/-/ /g')"
longitude="$(echo "$longitude" | tr -d NSEW | sed 's/-/ /g')"
best="$(python3 - $north "$latitude" $east "$longitude" "$1" "$2" "$icao" $best <<EOF
@@ -87,6 +110,12 @@ elif test $# = 1 && test "$1" = "list"; then
list_stations ""
elif test $# = 2 && test "$1" = "list"; then
list_stations "$(echo "$2" | tr [a-z] [A-Z])"
+elif test $# = 1 && test "$1" = "closest"; then
+ location="$(get_location)"
+ list_stations "" | get_closest $location
+elif test $# = 2 && test "$1" = "closest"; then
+ location="$(get_location)"
+ get_closest $location < "$2"
elif test $# = 3 && test "$1" = "closest"; then
list_stations "" | get_closest "$2" "$3"
elif test $# = 4 && test "$1" = "closest"; then