forked from MaskedBit/aviationCharts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfreshenLocalCharts.sh
executable file
·83 lines (70 loc) · 2.64 KB
/
freshenLocalCharts.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
set -eu # Always put this in Bourne shell scripts
IFS=$(printf '\n\t') # Always put this in Bourne shell scripts
# Download latest charts from faa/aeronav
# The script begins here
# Set some basic variables
declare -r PROGNAME=$(basename "$0")
declare -r PROGDIR=$(readlink -m $(dirname "$0"))
declare -r ARGS="$@"
# Set fonts for Help.
declare -r NORM=$(tput sgr0)
declare -r BOLD=$(tput bold)
declare -r REV=$(tput smso)
#Get the number of remaining command line arguments
NUMARGS=$#
#Validate number of command line parameters
if [ "$NUMARGS" -ne 1 ] ; then
echo "Usage: $PROGNAME <where_to_save_charts>" >&2
exit 1
fi
# Get command line parameter
AERONAV_ROOT_DIR=$(readlink -f "$1")
if [ ! -d "$AERONAV_ROOT_DIR" ]; then
echo "$AERONAV_ROOT_DIR doesn't exist"
exit 1
fi
# Exit if we ran this command within the last 24 hours (adjust as you see fit)
if [ -e "${PROGDIR}/lastChartRefresh" ] && [ $(date +%s -r "${PROGDIR}/lastChartRefresh") -gt $(date +%s --date="24 hours ago") ]; then
echo "Charts updated within last 24 hours, exiting"
exit 0
fi
# Update the time of this file so we can check when we ran this last
touch "${PROGDIR}/lastChartRefresh"
# Test local .zips in the $CHARTS_BASE_DIRECTORY tree and delete any bad ones so
# we can get fresh ones from FAA
find \
"$AERONAV_ROOT_DIR" \
-iname '*.zip' \
-type f \
-readable ! \
-exec unzip -q -t {} \; \
-exec rm -i {} \;
# Get all of the latest charts
# Skip the compilations
set +e
wget \
--directory-prefix="$AERONAV_ROOT_DIR" \
--recursive \
-l1 \
--span-hosts \
--domains=aeronav.faa.gov,www.faa.gov \
--timestamping \
--no-parent \
-A.zip \
-R"DD?C*" \
-erobots=off \
http://www.faa.gov/air_traffic/flight_info/aeronav/digital_products/vfr
wget \
--directory-prefix="$AERONAV_ROOT_DIR" \
--recursive \
-l1 \
--span-hosts \
--domains=aeronav.faa.gov,www.faa.gov \
--timestamping \
--no-parent \
-A.zip \
-R"DD?C*" \
-erobots=off \
http://www.faa.gov/air_traffic/flight_info/aeronav/digital_products/ifr
set -e