From 0b31567ad6fcef59156d4e15ca56613d39645cee Mon Sep 17 00:00:00 2001 From: "Marcel Kapfer (mmk2410)" Date: Wed, 15 Feb 2017 13:14:48 +0100 Subject: [PATCH] Reworked the buildpdf script --- buildpdf/buildpdf.sh | 128 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 102 insertions(+), 26 deletions(-) diff --git a/buildpdf/buildpdf.sh b/buildpdf/buildpdf.sh index 8018c20..d2f268b 100755 --- a/buildpdf/buildpdf.sh +++ b/buildpdf/buildpdf.sh @@ -2,31 +2,107 @@ # A script for automatically creating PDf files from a latex document # You can set the amounts of builds and the time between these builds # Usage: ./buildpdf.sh filename [build amount] [time between builds in s] -# Marcel Michael Kapfer -# 6th January 2015 +# Marcel Michael Kapfer (mmk2410) +# 6th January 2015 - 2017 # GNU GPL v3.0 -> Feel free to re-distribute it or fork it -if [[ -z "$1" ]]; then - echo "Usage: ./buildpdf.sh filename [build amount] [time between builds in s]" - exit 1 -else - filename=$1 -fi -if [[ -z "$2" ]]; then - builds=1 -else - builds=$2 -fi -if [[ -z "$3" ]]; then - sleeptime=120 -else - sleeptime=$3 -fi -for ((i=1; i<=$builds; ++i)) ; -do - pdflatex $filename - echo "Build $i ready" - if (( i < builds )); then - echo "Waiting $sleeptime seconds - then build again" - sleep $sleeptime + +print() { + + local text="$1" + + date "+[%F %T] $text" +} + +run() { + + local filename="$1" + local number="$2" + + pdflatex "$filename" > /dev/null 2>&1 + print "Build $number ready" + +} + + +build() { + + local filename="$1" + local builds="$2" + local sleeptime="$3" + local i="1" + + while [[ "$i" -le "$builds" ]]; do + + run "$filename" "$i" + + if [[ "$i" -lt "$builds" ]]; then + print "Waiting $sleeptime seconds - then build again" + sleep "$sleeptime" + else + print "Jobs done. Exiting now..." fi -done + + ((++i)) + + done + +} + +build_infty() { + + local filename="$1" + local builds="1" + local sleeptime="$2" + + while : ; do + + run "$filename" "$builds" + + print "Waiting $sleeptime seconds - then build again" + sleep "$sleeptime" + + ((++builds)) + + done + +} + +main() { + + if [[ -z "$1" || "$1" == "--help" || "$1" == "-h" ]]; then + cat <