├── .gitignore ├── README.mediawiki └── create_omtb_garmin_img.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .* 2 | /OMTB_tmp/ 3 | -------------------------------------------------------------------------------- /README.mediawiki: -------------------------------------------------------------------------------- 1 | __NOTOC__ 2 | = Linux/Unix script to compile garmin *.img map files from openmtbmap.org or openvelomap.org files = 3 | 4 | === Requirements === 5 | 6 | * zsh 7 | * 7z 8 | * mkgmap OR wine 9 | 10 | you can obtain mkgmap with your package manager or from http://www.mkgmap.org.uk/snapshots/ 11 | 12 | gmt linux version can be downloaded from http://www.gmaptool.eu/en/content/gmaptool 13 | 14 | ==== Installation of required files on Debian/Ubuntu ==== 15 | 16 | sudo apt-get install zsh p7zip-full 17 | wget http://www.gmaptool.eu/sites/default/files/lgmt08220.zip 18 | unzip lgmt08220.zip gmt 19 | sudo mv gmt /usr/local/bin/ 20 | 21 | also, get newest mkgmap from http://www.mkgmap.org.uk/snapshots/ and install (aka copy) it to e.g. /usr/local/share/mkgmap/ 22 | 23 | ==== Installation of required files on Gentoo ==== 24 | 25 | emerge zsh p7zip mkgmap 26 | wget http://www.gmaptool.eu/sites/default/files/lgmt08220.zip 27 | unzip lgmt08220.zip gmt 28 | sudo mv gmt /usr/local/bin/ 29 | 30 | ==== Installation of required files on openSUSE ==== 31 | 32 | add GEO-repo from opensuse's open build service according to your version 33 | http://download.opensuse.org/repositories/Application:/Geo/ 34 | e.g. http://download.opensuse.org/repositories/Application:/Geo/ for openSUSE 13.1 35 | Using YaST - "Software Management" to search for and install GMT, mkgmap and p7zip 36 | 37 | Alternativly use the following commands on the command line 38 | zypper ar http://download.opensuse.org/repositories/Application:/Geo/openSUSE_13.1/ GEO 39 | zypper ref 40 | zypper in p7zip mkgmap GMT 41 | 42 | === Usage === 43 | 44 | Usage: create_omtb_garmin_img.sh [options] 45 | as TYP-style you can choose: 46 | For OpenMTB-maps: 47 | clas: Classic layout - optimized for Vista/Legend series. 48 | thin: Thinner tracks and pathes - optimized for Gpsmap60/76 series. 49 | wide: High contrast layout, like classic but with white forest - optimized for Oregon/Colorado displays. 50 | hike: Like classic layout - but optimized for hiking (does not show mtb/bicycle informations). 51 | easy: Similar to classic layout - focused on easy readability, not showing mtb/bicycle information except routes. 52 | For OpenVelo-maps: 53 | velo: Layout optimized for small GPS screen 54 | velw: Wide layout optimized for high DPI screens like Oregon 55 | race: Clean layout for road biking. No buildings or features. 56 | or give the path to your own .TYP style file 57 | Options: 58 | -g 59 | -m 60 | -o 61 | -------------------------------------------------------------------------------- /create_omtb_garmin_img.sh: -------------------------------------------------------------------------------- 1 | #!/bin/zsh 2 | # License: Creative Commons Share Alike 3.0 3 | # Copyright: 2012, Bernhard Tittelbach 4 | # Thanks to malenki on #osm-de@oftc.net for constructive input and nagging me into making this thing useable in the first place 5 | # Thanks to Thomas Friebel who fixed some typos and noted that in some extracted openmtbmaps the numbered image files start with 0001 instead of 0000 6 | 7 | # Required software: 8 | # - zsh (obviously) 9 | # - 7z (debian/ubuntu: apt-get install p7zip-full) 10 | # - mkgmap (preferred) [http://www.mkgmap.org.uk/download/mkgmap.html] OR wine 11 | # - optionally: gmt Linux version [ http://www.gmaptool.eu/pl/content/wersja-dla-linuksa ] OR wine 12 | # 13 | 14 | setopt extendedglob 15 | setopt cshnullglob 16 | setopt nonomatch #otherwise =executable will abort script if executable not found 17 | 18 | SCRIPT_NAME=${0:t} 19 | usage() 20 | { 21 | print "\nUsage: $SCRIPT_NAME [options] " > /dev/stderr 22 | print " as TYP-style you can choose:" > /dev/stderr 23 | if [[ $OMTBORVELO != openvelomap ]]; then 24 | print " For OpenMTB-maps:" > /dev/stderr 25 | print " clas: Classic layout - optimized for Vista/Legend series." > /dev/stderr 26 | print " thin: Thinner tracks and pathes - optimized for Gpsmap60/76 series." > /dev/stderr 27 | print " wide: High contrast layout, like classic but with white forest - optimized for Oregon/Colorado displays." > /dev/stderr 28 | print " hike: Like classic layout - but optimized for hiking (does not show mtb/bicycle informations)." > /dev/stderr 29 | print " easy: Similar to classic layout - focused on easy readability, not showing mtb/bicycle information except routes." > /dev/stderr 30 | fi 31 | if [[ $OMTBORVELO != openmtbmap ]]; then 32 | print " For OpenVelo-maps:" > /dev/stderr 33 | print " velo: Layout optimized for small GPS screen" > /dev/stderr 34 | print " velw: Wide layout optimized for high DPI screens like Oregon" > /dev/stderr 35 | print " race: Clean layout for road biking. No buildings or features." > /dev/stderr 36 | fi 37 | print " or give the path to your own .TYP style file" > /dev/stderr 38 | print "\nOptions:" > /dev/stderr 39 | print " -g " > /dev/stderr 40 | print " -m " > /dev/stderr 41 | print " -o \n" > /dev/stderr 42 | exit 1 43 | # descriptions taken from openmtbmap.org batch files 44 | } 45 | 46 | # convert decimal number to octal number and output as ascii character 47 | chr () 48 | { 49 | printf \\$(($1/64*100+$1%64/8*10+$1%8)) 50 | } 51 | 52 | # use linux-gmt or wine-gmt or set manually 53 | # thanks to luhk @ github for pioniering this 54 | # depends on global variable GMT_CMD 55 | setFID() 56 | { 57 | local FID=$(($1)) 58 | local FIDFILE="$2" 59 | if [[ -n $GMT_CMD ]]; then 60 | ${=GMT_CMD} -wy ${FID} ${FIDFILE} 61 | else 62 | #DIY 63 | #This is adapted from http://pinns.co.uk/osm/typformat.html 64 | HIGH_BYTE=$[FID/256] 65 | LOW_BYTE=$[FID%256] 66 | chr $HIGH_BYTE | dd of=${FIDFILE} bs=1 seek=48 count=1 conv=notrunc &> /dev/null 67 | chr $LOW_BYTE | dd of=${FIDFILE} bs=1 seek=47 count=1 conv=notrunc &> /dev/null 68 | fi 69 | } 70 | 71 | zparseopts -A ARGS_A -D -E -- "g:" "m:" "o:" 72 | OMTB_EXE="$1" 73 | TYPFILE="$2" 74 | 75 | if [ $# -lt 2 ]; then 76 | usage 77 | elif [ ! -f "$OMTB_EXE" ]; then 78 | echo "ERROR: Input map file does not exist (or is not a file)!" > /dev/stderr 79 | exit 2 80 | fi 81 | 82 | if [[ ${OMTB_EXE:t} == mtb* ]]; then 83 | OMTBORVELO=openmtbmap 84 | OMTB_NAME="${OMTB_EXE:t:r:s/mtb/}" 85 | elif [[ ${OMTB_EXE:t} == velo* ]]; then 86 | OMTBORVELO=openvelomap 87 | OMTB_NAME="${OMTB_EXE:t:r:s/velo/}" 88 | elif [[ -n ${OMTB_EXE:t} ]]; then 89 | print "\nERROR: Not a openmtbmap.org or openvelomap.org file ?" > /dev/stderr 90 | usage 91 | fi 92 | 93 | GMT_CMD=( ${ARGS_A[-g]}(.N,@-.) ${^path}/gmt(.N,@-.) ) 94 | GMT_CMD="${GMT_CMD[1]:a}" 95 | # if wine exists, this expands into e.g. /usr/bin/wine, otherwhise it will remain as string =wine 96 | # advantage over which wine is, that it outputs only one result, namely the executable that a call to wine on the CL would actually use 97 | WINE_EXE==wine 98 | 99 | # NB: If mkgmap is not found, we fall back to using gmt later. 100 | MKGMAP=( ${ARGS_A[-m]}(.N,@-.) /usr/share/mkgmap/mkgmap.jar(.N,@-.) /usr/local/share/mkgmap/mkgmap.jar(.N,@-.) /usr/share/java/mkgmap.jar(.N,@-.) /usr/share/java/mkgmap/mkgmap.jar(.N,@-.) ${^path}/mkgmap.jar(.N,@-.) ) 101 | MKGMAP="${MKGMAP[1]:a}" 102 | 103 | if ! [[ -x =7z ]]; then 104 | print "\nERROR: 7z is not installed, but needed to extract openmtbmap downloads !" > /dev/stderr 105 | exit 3 106 | fi 107 | 108 | 109 | DESC="${OMTBORVELO}_${OMTB_NAME}" 110 | if [[ -d ${ARGS_A[-o]} ]]; then 111 | DSTFILENAME="${ARGS_A[-o]:A}/${DESC}.img" 112 | TMPDIR=${ARGS_A[-o]:A}/OMTB_tmp 113 | else 114 | DSTFILENAME="${OMTB_EXE:A:h}/${DESC}.img" 115 | TMPDIR=${OMTB_EXE:A:h}/OMTB_tmp 116 | [[ -n $ARGS_A[-o] ]] && {print "\nWarning: -o given but ${ARGS_A[-o]} is not a directory.\n Using ${OMTB_EXE:A:h} instead..\n"} 117 | fi 118 | 119 | if ! [[ ( -n $MKGMAP && -x =java ) || -x $WINE_EXE ]]; then 120 | print "\nERROR: either mkgmap (+java) or wine are required!" > /dev/stderr 121 | exit 4 122 | fi 123 | 124 | 125 | 126 | if [[ -e $DSTFILENAME ]]; then 127 | print "\nWarning: The script will create (overwrite) $DSTFILENAME" 128 | print " but $DSTFILENAME already exists." 129 | read -q "?Continue and overwrite ? [y/N] " || exit 0 130 | print "" 131 | fi 132 | 133 | if [[ -e $TMPDIR ]] ; then 134 | print "\nWarning: The script wants to create directory $TMPDIR, but it already exists." 135 | if [[ -d $TMPDIR ]] ; then 136 | print " If you press [y], $OMTB_EXE will be extracted" 137 | print " to $TMPDIR regardless of its contents." 138 | print " That's fine if it was created during a previous abortet run of this script." 139 | print " Otherwise you should say [n] and move $OMTB_EXE into a clean directory." 140 | read -q "?Continue ? [y/N] " || exit 0 141 | print "" 142 | else 143 | print " Please use another output directory and try again." 144 | exit 1 145 | fi 146 | else 147 | mkdir $TMPDIR || exit 1 148 | fi 149 | 150 | #Check if extracted files are already present. 151 | FIMG_a=(${TMPDIR}/6<->.img(N[1])) 152 | if [[ -z $FIMG_a ]] ; then 153 | print "Extracting $OMTB_EXE ..." 154 | 7z e -y -o$TMPDIR ${OMTB_EXE} &>/dev/null || exit 1 155 | #Check if extraction files are there 156 | FIMG_a=(${TMPDIR}/6<->.img(N[1])) 157 | [[ -z $FIMG_a ]] && {print "\nERROR: Could not find 6*.img file after extracting $OMTB_EXE" >/dev/stderr ; exit 1} 158 | fi 159 | if [[ -f $TYPFILE ]] ; then 160 | TYPFILE="${TYPFILE:A}" 161 | else 162 | TYPFILE=( "${TMPDIR}/"(#i)${TYPFILE}*.typ(.N:A)) 163 | TYPFILE="${TYPFILE[1]}" 164 | fi 165 | 166 | trap "cd '$PWD'" EXIT 167 | cd $TMPDIR || exit 5 168 | 169 | if [[ -z $TYPFILE ]] ; then 170 | print "\nERROR: TYP-file or -style not found" > /dev/stderr 171 | print " Please choose your own file or one of these styles: " *.(#l)TYP(.N:r) > /dev/stderr 172 | exit 2 173 | fi 174 | 175 | print "Using display-TYP-file: $TYPFILE" 176 | cp $TYPFILE 01002468.TYP || exit 4 177 | FID=${${FIMG_a:t}[1][1,4]} 178 | print "Using FID $FID" 179 | 180 | if ! [[ -x "$GMT_CMD" ]] ; then 181 | #linux gmx not found, looking for alternatives 182 | if [[ -x $WINE_EXE && -f gmt.exe ]] ; then 183 | GMT_CMD="wine gmt.exe" 184 | else 185 | GMT_CMD="" 186 | fi 187 | fi 188 | 189 | setFID $FID 01002468.TYP 190 | 191 | if [[ -n $MKGMAP ]]; then 192 | print "Using mkgmap, building address search index..." 193 | #java -Xmx1000M -jar mkgmap.jar --family-id=$FID --index --description="$DESC" --series-name="$DESC" --family-name="$DESC" --show-profiles=1 --product-id=1 --gmapsupp 6*.img 7*.img 01002468.TYP 194 | if [[ $(grep MemTotal: /proc/meminfo | awk '{print $2}') -gt $((1024*1024*3)) ]]; then 195 | java -Xmx3000M -jar "$MKGMAP" --family-id=$FID --index --description="$DESC" --series-name="$DESC" --family-name="$DESC" --show-profiles=1 --product-id=1 --gmapsupp [67]*.img 01002468.TYP || exit 7 196 | else 197 | java -Xmx1000M -jar "$MKGMAP" --family-id=$FID --index --description="$DESC" --series-name="$DESC" --family-name="$DESC" --show-profiles=1 --product-id=1 --gmapsupp [67]*.img 01002468.TYP || exit 7 198 | fi 199 | mv (#i)gmapsupp.img "${DSTFILENAME}" || exit 7 200 | else 201 | print "mkgmap not found, using gmt..." 202 | if [[ -z $GMT_CMD ]]; then 203 | print "Error: gmt not found either." 204 | exit 3 205 | fi 206 | ${=GMT_CMD} -j -o "${DSTFILENAME}" -f $FID -m "$DESC" 6*.img 7*.img 01002468.TYP || exit 7 207 | fi 208 | rm -R "$TMPDIR" 209 | print "\nSuccessfully created ${DSTFILENAME}" 210 | --------------------------------------------------------------------------------