#! /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 -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 echo "====> Generating Garmin maps for $file" if [[ "$file" =~ "velo" ]]; then typ=velo*.TYP name=`basename $file .exe | cut -c 5-` img=maps/velo-$name.img else typ=thin*.TYP name=`basename $file .exe | cut -c 4-` img=maps/mtb-$name.img fi if [ -f $img ]; then echo "Already existing, skipping..." exit 0 fi prepare $file if [ ! -f work/$typ ]; then echo "Type file is not found, 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