summaryrefslogtreecommitdiffstats
path: root/generate.sh
blob: 517c2e9b21e0c0ff24b6708650f0d2cc6ae487ed (plain)
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
#! /bin/bash

function prepare {
    rm -rf work
    mkdir work
    mkdir -p maps
    7z x -owork $1 &> /dev/null
    [ $? -ne 0 ] && 7z x -owork $1

   for file_name in `find work -maxdepth 1 -type d -name "???"`; do mv $file_name/* work/ ; done
   for file_name in `find work -maxdepth 1 -type d -regextype posix-extended -iregex ".*($name|mtb$name|velo$name)"`; do mv $file_name/* work/ ; done
}

function clean {
    rm -rf work
}

if [ -z "$1" ]; then
    echo "Usage: $1 [map_file.exe]"
    exit 1
fi

file="$1"
name="$2"
img="$3"

echo "====> Generating Garmin maps for $file"

if [ -f $img ]; then
    echo "Already existing, skipping..."
    exit 0
fi

prepare "$file"

if [ ! -f work/$typ ]; then
    [ -f work/clas*.TYP ] && typ=clas*.TYP
    [ -z "$typ" ] && { echo "TYP file is not found (might be naming changed again, check in workdir), failing out..."; exit 1; }
fi

id=`ls work/6*.img | head -n 1 | cut -c 6-9`
if [ $? -ne 0 ]; then
    echo "No image files in $file, failing out..."
    exit 1
fi

date=`date +%d.%m.%Y`
(
    cd work

#    java  -Xmx2048M -jar /usr/share/mkgmap/lib/mkgmap.jar \

    if [ -f velo*.TYP ]; then
	mkgmap \
	    --route --index  --unicode \
	    --family-id=$id --family-name=velo-$name --series-name=velo-$name --area-name=$name --country-name="$name" --region-name="$name" --description="$name [velo $date]" \
	    --gmapsupp 6*.img $typ 
    else
	mkgmap \
	    --route --index  --unicode \
	    --family-id=$id --family-name=$name --series-name=$name --area-name=$name --country-name="$name" --region-name="$name" --description="$name [mtb $date]" \
	    --gmapsupp 6*.img $typ 
    fi
)

exit_code=$?
if [ $exit_code -ne 0 ]; then
    echo "mkgmap failed with code $exit_code, failing out..."
    exit $exit_code
fi

if [ ! -f work/gmapsupp.img ]; then
    echo "mkgmap failed to produce Garmin image, failing out..."
    exit 1
fi

mv work/gmapsupp.img $img

echo "====> $img done"

clean