Added flag that disables Gotify notification

+ cleaned up help section
+ replaced hard-coded colour codes with dependency on colours script
master
Taha Ahmed 2 years ago
parent 44ff1cfdc1
commit 688c7404ef

@ -11,22 +11,24 @@ set -euo pipefail
usage() { usage() {
cat <<EOF cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [arg1] Usage: $(basename "${BASH_SOURCE[0]}") <flags> job.Rnw
Compiles Rnw documents with knitr and latexmk. This is a highly customised script. Compiles R Sweave documents using knitr and LaTeXMK.
Takes zero or one arguments. The argument must be a filename with the extension "Rnw". Filename extension must be .Rnw.
If an argument is supplied, the document in question is compiled. Available flags:
If no arguments are supplied, a menu is displayed offering a choice of auxiliary tasks. + --help --> display this usage guide
+ --no-alert --> disable gotify alert (--silent also works)
+ --menu --> enter "menu" mode where auxiliary commands can be run (--aux)
This script treats certain filenames in a special manner: This script treats certain filenames in a special manner:
+ "thesis" --> triggers a chain of special commands, see source code. + "thesis" --> triggers a chain of special commands, see source code.
In addition, the internal execution of this script is modified by the existence of In addition, the internal execution of this script is modified by the existence of
certain files in the working directory: certain files in the working directory:
+ .knitme --> use knitr::knit() instead of pgfSweave(). + ./.knitme --> use knitr::knit() instead of pgfSweave().
+ .latexmkrc --> apply RC file to latexmk command. + ./.latexmkrc --> apply RC file to latexmk command.
+ vc --> run vc script (integrates git with LaTeX, deprecated by gitinfo2, kept for backwards support). + ./vc --> run vc script (integrates git with LaTeX, deprecated by gitinfo2, kept for backwards support).
EOF EOF
exit exit
@ -35,35 +37,12 @@ EOF
# keep track of runtime of entire script # keep track of runtime of entire script
starttime=$(date +%s) starttime=$(date +%s)
# in future, consider integrating this color setup with ~/.local/bin/echo-colours.sh # load colours (this script depends on colours being defined!)
setup_colors() { # TO-DO: to make this dependency non-critical, consider making all invocations of colour
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then # optional (depending on whether colours.sh was found, or a CLI flag perhaps)
NOFORMAT='\033[0m' if [ -f "/home/taha/.local/bin/echo-colours.sh" ]; then
# text color . "/home/taha/.local/bin/echo-colours.sh"
Black='\033[0;30m' Red='\033[0;31m' Green='\033[0;32m' Yellow='\033[0;33m' Blue='\033[0;34m' Purple='\033[0;35m' Cyan='\033[0;36m' White='\033[0;37m'
# bold text and color
BBlack='\033[1;30m' BRed='\033[1;31m' BGreen='\033[1;32m' BYellow='\033[1;33m' BBlue='\033[1;34m' BPurple='\033[1;35m' BCyan='\033[1;36m' BWhite='\033[1;37m'
# underline and color
UBlack='\033[4;30m' URed='\033[4;31m' UGreen='\033[4;32m' UYellow='\033[4;33m' UBlue='\033[4;34m' UPurple='\033[4;35m' UCyan='\033[4;36m' UWhite='\033[4;37m'
# text on background color
On_Black='\033[40m' On_Red='\033[41m' On_Green='\033[42m' On_Yellow='\033[43m' On_Blue='\033[44m' On_Purple='\033[45m' On_Cyan='\033[46m' On_White='\033[47m'
# high intensity color
IBlack='\033[0;90m' IRed='\033[0;91m' IGreen='\033[0;92m' IYellow='\033[0;93m' IBlue='\033[0;94m' IPurple='\033[0;95m' ICyan='\033[0;96m' IWhite='\033[0;97m'
# bold high intensity color
BIBlack='\033[1;90m' BIRed='\033[1;91m' BIGreen='\033[1;92m' BIYellow='\033[1;93m' BIBlue='\033[1;94m' BIPurple='\033[1;95m' BICyan='\033[1;96m' BIWhite='\033[1;97m'
# text on high intensity background color
On_IBlack='\033[0;100m' On_IRed='\033[0;101m' On_IGreen='\033[0;102m' On_IYellow='\033[0;103m' On_IBlue='\033[0;104m' On_IPurple='\033[0;105m' On_ICyan='\033[0;106m' On_IWhite='\033[0;107m'
else
NOFORMAT=''
Black='' Red='' Green='' Yellow='' Blue='' Purple='' Cyan='' White=''
BBlack='' BRed='' BGreen='' BYellow='' BBlue='' BPurple='' BCyan='' BWhite=''
UBlack='' URed='' UGreen='' UYellow='' UBlue='' UPurple='' UCyan='' UWhite=''
On_Black='' On_Red='' On_Green='' On_Yellow='' On_Blue='' On_Purple='' On_Cyan='' On_White=''
IBlack='' IRed='' IGreen='' IYellow='' IBlue='' IPurple='' ICyan='' IWhite=''
BIBlack='' BIRed='' BIGreen='' BIYellow='' BIBlue='' BIPurple='' BICyan='' BIWhite=''
On_IBlack='' On_IRed='' On_IGreen='' On_IYellow='' On_IBlue='' On_IPurple='' On_ICyan='' On_IWhite=''
fi fi
}
msg() { msg() {
echo >&2 -e "${1-}" echo >&2 -e "${1-}"
@ -71,7 +50,7 @@ msg() {
# examples: # examples:
# die "Some message (exiting with status 1)" # die "Some message (exiting with status 1)"
# die "Some message (exiting with status -->)" 0 # die "Some message (exiting with status -->)" 0 # this is not working
die() { die() {
local msg=$1 local msg=$1
local code=${2-1} # default exit status 1 local code=${2-1} # default exit status 1
@ -85,7 +64,8 @@ parse_params() {
case "${1-}" in case "${1-}" in
-h | --help) usage ;; -h | --help) usage ;;
-v | --verbose) set -x ;; -v | --verbose) set -x ;;
--no-color) NO_COLOR=1 ;; --aux | --menu) show_menu=true ;;
--no-alert | --silent) disable_alert=true ;;
-?*) die "Unknown option: $1" ;; -?*) die "Unknown option: $1" ;;
*) break ;; *) break ;;
esac esac
@ -94,19 +74,20 @@ parse_params() {
args=("$@") args=("$@")
# Check number of arguments # If no args were given, show aux menu mode
# this script can be run with one argument is process mode or with zero arguments in post-processing mode # note that flags don't count as args, so as long as no jobname was given
[[ ${#args[@]} -gt 1 ]] && die "More than one argument not supported" # (irrespective of provided flags), aux menu will be entered
# we use maintrack variable to keep track of whether auxiliary menu should be entered [[ ${#args[@]} -eq 0 ]] && show_menu=true
[[ ${#args[@]} -eq 1 ]] && maintrack=true
return 0 return 0
} }
maintrack=false # I'm not really happy with this variable *name* show_menu=false
# gotify alert is enabled by default (assuming the job takes longer than X seconds)
disable_alert=false
parse_params "$@" parse_params "$@"
setup_colors # setup_colors
clear clear
@ -180,7 +161,7 @@ aux_xdy="*.xdy" # glossaries (xindy)
auxfiles="${aux_acn} ${aux_acr} ${aux_alg} ${aux_aux} ${aux_bbl} ${aux_blg} ${aux_dep} ${aux_dpth} ${aux_fdb} ${aux_fig} ${aux_fls} ${aux_glg} ${aux_glo} ${aux_gls} ${aux_ist} ${aux_lob} ${aux_lof} ${aux_log} ${aux_lol} ${aux_lor} ${aux_los} ${aux_lot} ${aux_maf} ${aux_out} ${aux_lox} ${aux_make} ${aux_map} ${aux_mtc} ${aux_run} ${aux_slg} ${aux_slo} ${aux_sls} ${aux_tikz} ${aux_tdo} ${aux_toc} ${aux_xdy}" auxfiles="${aux_acn} ${aux_acr} ${aux_alg} ${aux_aux} ${aux_bbl} ${aux_blg} ${aux_dep} ${aux_dpth} ${aux_fdb} ${aux_fig} ${aux_fls} ${aux_glg} ${aux_glo} ${aux_gls} ${aux_ist} ${aux_lob} ${aux_lof} ${aux_log} ${aux_lol} ${aux_lor} ${aux_los} ${aux_lot} ${aux_maf} ${aux_out} ${aux_lox} ${aux_make} ${aux_map} ${aux_mtc} ${aux_run} ${aux_slg} ${aux_slo} ${aux_sls} ${aux_tikz} ${aux_tdo} ${aux_toc} ${aux_xdy}"
if $maintrack; then if [[ $show_menu == "false" ]]; then
# Check if the argument contains a filetype # Check if the argument contains a filetype
# (assumes a complete filename was passed) # (assumes a complete filename was passed)
jobfilename=${args[0]} jobfilename=${args[0]}
@ -346,13 +327,13 @@ if $maintrack; then
# Run pdflatex, bibtex, and company # Run pdflatex, bibtex, and company
# Leaving this if-else for historical reasons, and also to print the message # Leaving this if-else for historical reasons, and also to print the message
if $ltxmkrc; then if $ltxmkrc; then
msg "${On_Cyan}<cheRTeX> Calling LaTeXMK, detected .latemxkrc file${NOFORMAT}" msg "${On_Cyan}<cheRTeX> Calling LaTeXMK, detected .latemxkrc file${Color_Off}"
simpledelay.sh 2 simpledelay.sh 2
# note: latexmk does not need us to invoke "-r .latexmkrc", it finds and uses # note: latexmk does not need us to invoke "-r .latexmkrc", it finds and uses
# the RC file automatically (as evidenced by latexmk's output) # the RC file automatically (as evidenced by latexmk's output)
latexmk -pdf -bibtex $jobname latexmk -pdf -bibtex $jobname
else else
msg "${On_Cyan}<cheRTeX> Calling LaTeXMK${NOFORMAT}" msg "${On_Cyan}<cheRTeX> Calling LaTeXMK${Color_Off}"
simpledelay.sh 2 simpledelay.sh 2
latexmk -pdf -bibtex $jobname latexmk -pdf -bibtex $jobname
fi fi
@ -435,7 +416,7 @@ else
fi fi
fi fi
die "All done. Exiting..." 0 die "All done. Exiting..."
fi fi
@ -451,7 +432,7 @@ runtime=$(( $endtime - $starttime ))
# send push message to Gotify server # send push message to Gotify server
# if runtime is longer than X minutes (suitable limit perhaps 3 min) # if runtime is longer than X minutes (suitable limit perhaps 3 min)
if (( $runtime > 70 )); then if (( $runtime > 180 )) && [[ $disable_alert == "false" ]]; then
# POST request to Gotify server works without needing Gotify CLI on this box # POST request to Gotify server works without needing Gotify CLI on this box
# NOTE, multi-line bash command fails if interrupted by comment lines! # NOTE, multi-line bash command fails if interrupted by comment lines!
# Hide CURL response (-o /dev/null) and progress bar (--silent) # Hide CURL response (-o /dev/null) and progress bar (--silent)
@ -465,16 +446,16 @@ if (( $runtime > 70 )); then
msg "Push notification sent to Gotify" msg "Push notification sent to Gotify"
fi fi
msg "${On_Cyan}-------------------------------------${NOFORMAT}" msg "${On_Cyan}-------------------------------------${Color_Off}"
# the padding for runtime makes the formatting work # the padding for runtime makes the formatting work
# three digits for seconds is enough for just above 15 minutes # three digits for seconds is enough for just above 15 minutes
printf "${On_Cyan}=== chertex.sh completed in %03d s ===${NOFORMAT}\n" $runtime 1>&2 printf "${On_Cyan}=== chertex.sh completed in %03d s ===${Color_Off}\n" $runtime 1>&2
if [[ $cetcest == "CET" ]]; then if [[ $cetcest == "CET" ]]; then
msg "${On_Cyan}=== $(date) ===${NOFORMAT}" msg "${On_Cyan}=== $(date) ===${Color_Off}"
else else
msg "${On_Cyan}=== $(date) ===${NOFORMAT}" msg "${On_Cyan}=== $(date) ===${Color_Off}"
fi fi
msg "${On_Cyan}-------------------------------------${NOFORMAT}" msg "${On_Cyan}-------------------------------------${Color_Off}"
simpledelay.sh 3 simpledelay.sh 3
exit 0 exit 0

Loading…
Cancel
Save