tunuifranken.info/bin/pull-procedures.sh

42 lines
1.5 KiB
Bash
Executable file

#!/bin/bash
# This script is executed by make in the parent directory
[ "$HOSTNAME" != lime2 ] || exit 1
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
for folder in ~/src/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
if [ "$VERBOSE" = true ]; then
echo "Ignoring ${name}"
fi
else
if [ "$VERBOSE" = true ]; then
echo -n "Pulling ${name}..."
fi
if [[ ! "$name" = *tablette* ]]; then
origin_file_time=$(stat -c %Y "$folder"/procedure*.pdf)
current_file_time=$(stat -c %Y ./procedures/procedure_"$name".pdf)
fi
if [ -z "$current_file_time" ] || [ "$origin_file_time" -gt "$current_file_time" ]; then
cp "$folder"/procedure*.pdf ./procedures/procedure_"$name".pdf && echo "Updated $name"
else
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
fi
fi
done
chmod 644 ./procedures/index.html
sed 's/===PROCEDURE===//g' ./procedures/index.tmp.html > ./procedures/index.html && rm ./procedures/index.tmp.html
chmod 444 ./procedures/index.html