-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathigc2kmz.sh
executable file
·66 lines (47 loc) · 1.33 KB
/
igc2kmz.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
#!/bin/bash
#
# Uses perfetct lib https://github.com/twpayne/igc2kmz to convert
# all *.igc files in dir to *.kmz
# Put color.txt with color line like FF00FFFF in each subfolder to define track color
#set -xe #for debugging and early abort on error
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
IGC2KMZ="$SCRIPT_DIR/igc2kmz/bin/igc2kmz.py"
PY="/usr/bin/python2.7"
TRACKS_DEFAULT="$SCRIPT_DIR/"
echo "Start script for converting tracks"
usage() { echo "Usage: $0 [-d <string> directory to search for igc files]" 1>&2; exit 1; }
d=$TRACKS_DEFAULT
while getopts ":d:" o; do
case "${o}" in
d)
d=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${d}" ]; then
usage
fi
if [ ! -d "${d}" ]; then
echo "Directory ${d} not found"
exit 1
fi
OIFS="$IFS"
IFS=$'\n'
for f in $(find ${d} -iname "*.igc" -type f); do
dirname="$(dirname ${f})"
color="FFFFFFFF"
if [ -f "${dirname}/color.txt" ]; then
color=$(head -n 1 "${dirname}/color.txt");
fi
pname=$(echo $dirname|xargs basename)
out="${f}.kmz"
if [ ! -f "$out" ]; then
$PY $IGC2KMZ -i "${f}" -o "${out}" -c $color -n $pname
echo "Converted ${f} to ${out} with color=${color} and pilot=${pname}"
fi
done
IFS="$OIFS"