#!/bin/bash
set -e

if [ ! -d ~/.lectorbus/firefox ] ; then mkdir -p ~/.lectorbus/firefox; fi

version=19.10.0
year=`echo $version | sed -e "s|\([^.]*\).*|\1|g"`
month=`echo $version | sed -e "s|${year}\.\([^.]*\).*|\1|g"`
patch=`echo $version | sed -e "s|${year}\.${month}\.\(.*\)$|\1|g"`
id=$(($year*10000+$month*100+$patch))
fill=0
filename=~/.lectorbus/VERSION

if [ -f $filename ] ; then
	oldid=`cat $filename`
    if [ $id -gt $oldid ] ; then
		echo $id > $filename
		fill=1
	fi
else
	echo $id > $filename
    fill=1
fi

if [ $fill -eq 1 ] ; then
	cp -rf /usr/share/pragmatice/lectorbus/* ~/.lectorbus/firefox/
fi

 
/usr/bin/firefox -profile ~/.lectorbus/firefox -new-window file:///usr/share/pragmatice/lectorbus/app/index.html
