]> Wikimedia Canada | Git repositories - eccc_to_commons.git/blob - eccc_fixer.sh
Rewrite almanach merge logic
[eccc_to_commons.git] / eccc_fixer.sh
1 #!/bin/bash
2
3 # eccc_fixer.sh - Create Environment and Climate change Canada historical data
4 # files download list
5 # Copyright (C) 2019-2020 Pierre Choffet
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 set -ex
21
22 SOURCE="${1}"
23 DESTINATION="${2}"
24
25 if [ -z "${SOURCE}" ]||[ -z "${DESTINATION}" ]||[ -d "${DESTINATION}" ]
26 then
27 echo 'Fix XMLs provided by Environment and Climate change Canada'
28 echo 'Usage: eccc_fixer.sh <source folder> <destination folder>'
29 echo ''
30 echo 'To prevent wrong usage, <destination folder> must not exist.'
31 exit 1
32 fi
33
34 # Recreate folders structure
35 while IFS= read -r -d '' -u 9
36 do
37 mkdir -p -- "${DESTINATION}/$(realpath --relative-to "${SOURCE}" "${REPLY}")"
38
39 done 9< <( find "${SOURCE}" -type d -print0 )
40
41 # Transform original files
42 while IFS= read -r -d '' -u 9
43 do
44 xmlstarlet tr eccc_fixer.xslt "${REPLY}" > "${DESTINATION}/$(realpath --relative-to "${SOURCE}" "${REPLY}")"
45 done 9< <( find "${SOURCE}" -type f -name '*.xml' -print0 )