User:Skyper/JOSM update script

From OpenStreetMap Wiki
Jump to navigation Jump to search

JOSM Update Script

This shell script checks the local revision and the available revision at the JOSM webpage and downloads if the local revision is lower.

There could be some improvements but it works for now. Please, mail me if it does not work or if you have some improvements. Thanks.--Skyper 16:32, 9 June 2011 (BST)

Changelog

  • shorten the script. new revision: 0.1.1a. --Skyper 14:21, 13 June 2011 (BST)
  • some small changes. --Skyper 22:19, 12 June 2011 (BST)
#!/bin/sh 
## automatically download of josm_latest or tested, after 
## revision check on server
##
## users needs write permission on the josm.jar file.
##
## Feel free to improve !
## Version= 0.1.1a 

PATH=/bin:/usr/bin:
set -e

## some variables
j_dir="/usr/local/share/josm"		# local JOSM . jar dir
j_version="latest"			# josm version (revision)
j_jar=""$j_dir"/josm-"$j_version".jar"	# josm.jar
j_server="josm.openstreetmap.de"	# download server
tp=http					# download protocol


## check write permission
if [ -w "$j_dir" ]; then
	if [ -w "$j_jar" ]; then
		echo "you have write permission"
	else
		echo "no write permission for $j_jar."
		exit 1
	fi
else 
	echo "no write permission for $j_dir."
	exit 1
fi


## test server through ping
ping="$(ping $j_server -q -c 1 |awk '/PING/ { print $1 }')"
if [ "$ping" = "PING" ]; then
	echo "network status OK"
else
	echo "$j_server unreachable"
	exit 1
fi


## get local revision 
if [ -e "$j_jar" ]; then
	local_rev="$(unzip -c $j_jar REVISION|awk '/Last Changed Rev:/ { print $4 } ')"
	echo "local revision: $local_rev"
else
	echo "no josm-$j_version installed"
	exit 1
fi


## get server revision
server_rev="$(wget -O - $tp://$j_server/$j_version)" 
echo "server revision: $server_rev"


## download and install
if [ "$local_rev" -le  "$server_rev" ]; then
	if [ "$local_rev" -lt "$server_rev" ]; then
		wget -O $j_jar $tp://$j_server/josm-$j_version.jar
			echo "New $j_version installed."
		exit 0
	elif [ "$local_rev" -eq "$server_rev" ]; then
		echo "no newer $j_version found, system is up-to-date"
		exit 0
	fi
elif [ "$local_rev" -gt "$server_rev" ]; then
	echo "Strange !!!! Newer local version !"
	exit 1
fi

Installation

  1. copy the code into a new text file and name it appropriate (e.g. josm_update.sh).
  2. Please adjust the variables at top of the script to your needs (local settings) and save the file.
  3. make the file excecutable.
  4. (move it to a reachable place (e.g. /usr/local/bin)

You can just simply run the script but you could also run it as cron job.

Do not run this script as user root, as there is no server nor file validation, so far.
Just run it in user space or create a new user with limited rights.

Note: Please adjust the variables at top of the script to your needs (local settings). You might have to create a directory and set the right permissions.