-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·57 lines (49 loc) · 1.64 KB
/
update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
#
# Update script
#
set -euo pipefail
script_dir=$(dirname "$0")
date=$(date +"%Y-%m-%d-%H:%M")
if [ ! -d "${script_dir}/venv" ]; then
echo "venv not found, creating"
python3 -m venv "${script_dir}/venv"
"${script_dir}/venv/bin/pip" install -qq -r requirements.txt
"${script_dir}/venv/bin/pip" install xmldiff
fi
# Move existing cache away
rm -rf "${script_dir}/cache.previous" || true
mv "${script_dir}/cache" "${script_dir}/cache.previous" || true
mkdir "${script_dir}/cache" 2> /dev/null || true
"${script_dir}/venv/bin/python3" \
"${script_dir}/teltarif-dl.py" \
--quiet "${script_dir}/cache/teltarif-${date}.xml"
"${script_dir}/venv/bin/python3" \
"${script_dir}/auerswald-lcr.py" \
download \
"${script_dir}/cache/current-${date}.xml"
# Now do the actual check --check would be easier,
# but we do not have that on older releases...
if [ "$("${script_dir}/venv/bin/xmldiff" \
"${script_dir}/cache/current-${date}.xml" \
"${script_dir}/cache/teltarif-${date}.xml" | \
grep -c '\[')" -eq "0" ]; then
# File is the same, means no change
true
else
# File is different than PBX, upload to PBX
echo "LCR Tables differ, uploading new tables to PBX..."
"${script_dir}/venv/bin/python3" \
"${script_dir}/auerswald-lcr.py" \
upload \
"${script_dir}/cache/teltarif-${date}.xml"
# Visualize changes
echo "Differences in LCR data"
"${script_dir}/venv/bin/python3" \
"${script_dir}/lcr-cache-diff.py" \
"${script_dir}/cache.previous" \
"${script_dir}/cache"
# Archive the cache for debugging
tar -cz -f "${script_dir}/cache.tar.gz" -C "${script_dir}" ./cache
mv "${script_dir}/cache.tar.gz" "${script_dir}/cache-${date}.tar.gz"
fi