tunuifranken.info/bin/pull-procedures.sh

43 lines
1.5 KiB
Bash
Raw Normal View History

#!/bin/bash
2021-03-05 16:18:59 +01:00
# This script is executed by make in the parent directory
[ "$HOSTNAME" != lime2 ] || exit 1
2021-01-01 19:22:33 +01:00
awk -v header="$(<./header.html)" '{sub(/===HEADER===/,header)} 1' ./procedures/index.template.html |
awk -v footer="$(<./footer.html)" '{sub(/===FOOTER===/,footer)} 1' > ./procedures/index.tmp.html
2021-01-01 19:22:33 +01:00
for folder in ~/tssr/procedures/*; do
if [ -d "$folder" ]; then
name=$(basename "$folder")
display_name=$(echo "$name" | sed -E 's/procedure_//g; s/_202.+//g; s/-/ /g; s/_/ /g')
if [[ "$name" = *chose* ]]; then # ignore procedure_chose
2021-03-12 12:23:00 +01:00
if [ "$VERBOSE" = true ]; then
echo "Ignoring ${name}"
fi
2021-01-01 21:05:23 +01:00
else
2021-03-12 12:23:00 +01:00
if [ "$VERBOSE" = true ]; then
echo -n "Pulling ${name}..."
fi
2021-02-16 16:36:12 +01:00
if [[ ! "$name" = *tablette* ]]; then
origin_file_time=$(stat -c %Y "$folder"/procedure*.pdf)
current_file_time=$(stat -c %Y ./procedures/procedure_"$name".pdf)
2021-02-16 16:36:12 +01:00
fi
if [ -z "$current_file_time" ] || [ "$origin_file_time" -gt "$current_file_time" ]; then
2021-03-12 12:23:00 +01:00
cp "$folder"/procedure*.pdf ./procedures/procedure_"$name".pdf && echo "Updated $name"
else
2021-03-12 12:23:00 +01:00
if [ "$VERBOSE" = true ]; then
echo "Already up to date"
fi
fi
sed -i "s@===PROCEDURE===@<li><p><a href='./procedure_${name}.pdf'>${display_name}</a></p></li>\n===PROCEDURE===@g" ./procedures/index.tmp.html
2021-01-01 21:05:23 +01:00
fi
2021-01-01 19:22:33 +01:00
fi
done
chmod 644 ./procedures/index.html
2021-03-12 12:23:00 +01:00
sed 's/===PROCEDURE===//g' ./procedures/index.tmp.html > ./procedures/index.html && rm ./procedures/index.tmp.html
chmod 444 ./procedures/index.html