#!/bin/bash # eccc_fixer.sh - Create Environment and Climate change Canada historical data # files download list # Copyright (C) 2019-2020 Pierre Choffet # # 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, see . set -ex SOURCE="${1}" DESTINATION="${2}" if [ -z "${SOURCE}" ]||[ -z "${DESTINATION}" ]||[ -d "${DESTINATION}" ] then echo 'Fix XMLs provided by Environment and Climate change Canada' echo 'Usage: eccc_fixer.sh ' echo '' echo 'To prevent wrong usage, must not exist.' exit 1 fi # Recreate folders structure while IFS= read -r -d '' -u 9 do mkdir -p -- "${DESTINATION}/$(realpath --relative-to "${SOURCE}" "${REPLY}")" done 9< <( find "${SOURCE}" -type d -print0 ) # Transform original files while IFS= read -r -d '' -u 9 do xmlstarlet tr eccc_fixer.xslt "${REPLY}" > "${DESTINATION}/$(realpath --relative-to "${SOURCE}" "${REPLY}")" done 9< <( find "${SOURCE}" -type f -name '*.xml' -print0 )