#!/bin/bash

# Copyright (C) 2024 Humanitarian OpenstreetMap Team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#

# This script processes multiple boundaries to create the data extracts
# for every task being setup for the HOT Tasking Manager. Most people
# would have probably written this in python, but since most of this
# is executing external command line utilities, Bourne shell works better.

# The remote server
dest="fieldmapper"
remote="/var/www/html/fieldmapper/SourceData/States"

dryrun="" # echo
# Get all the states
files=$(find -name \*.geojson -o -name \*.osm | sed -e 's:./::')
for file in ${files}; do
    state=$(echo ${file} | cut -d '/' -f 1)
    # ${dryrun} ssh ${dest} if test -e ${remote}/${file}.bz2; then rm -f ${remote}/${file}.bz2; fi
    # ${dryrun} ssh ${dest} rm -f ${remote}/${file}.bz2 >& /dev/null
    # ${dryrun} scp -C ${file} ${dest}:${remote}/${file}
    # ${dryrun} ssh ${dest} rm -f ${remote}/${file}.bz2 >& /dev/null
    # ${dryrun} ssh ${dest} bzip2 -f ${remote}/${file}
    bzip2 -f ${file}
    echo "Updated ${dest}:${remote}/${file}"
done
	   
