Added flag that disables Gotify notification

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

@ -11,22 +11,24 @@ set -euo pipefail
usage() {
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.
Takes zero or one arguments. The argument must be a filename with the extension "Rnw".
Compiles R Sweave documents using knitr and LaTeXMK.
Filename extension must be .Rnw.
If an argument is supplied, the document in question is compiled.
If no arguments are supplied, a menu is displayed offering a choice of auxiliary tasks.
Available flags:
+ --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:
+ "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:
+ .knitme --> use knitr::knit() instead of pgfSweave().
+ .latexmkrc --> apply RC file to latexmk command.
+ vc --> run vc script (integrates git with LaTeX, deprecated by gitinfo2, kept for backwards support).
+ ./.knitme --> use knitr::knit() instead of pgfSweave().
+ ./.latexmkrc --> apply RC file to latexmk command.
+ ./vc --> run vc script (integrates git with LaTeX, deprecated by gitinfo2, kept for backwards support).
EOF
exit
@ -35,35 +37,12 @@ EOF
# keep track of runtime of entire script
starttime=$(date +%s)
# in future, consider integrating this color setup with ~/.local/bin/echo-colours.sh
setup_colors() {
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
NOFORMAT='\033[0m'
# text color
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
}
# load colours (this script depends on colours being defined!)
# TO-DO: to make this dependency non-critical, consider making all invocations of colour
# optional (depending on whether colours.sh was found, or a CLI flag perhaps)
if [ -f "/home/taha/.local/bin/echo-colours.sh" ]; then
. "/home/taha/.local/bin/echo-colours.sh"
fi
msg() {
echo >&2 -e "${1-}"
@ -71,7 +50,7 @@ msg() {
# examples:
# 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() {
local msg=$1
local code=${2-1} # default exit status 1
@ -85,28 +64,30 @@ parse_params() {
case "${1-}" in
-h | --help) usage ;;
-v | --verbose) set -x ;;
--no-color) NO_COLOR=1 ;;
--aux | --menu) show_menu=true ;;
--no-alert | --silent) disable_alert=true ;;
-?*) die "Unknown option: $1" ;;
*) break ;;
esac
shift
done
args=("$@")
# Check number of arguments
# this script can be run with one argument is process mode or with zero arguments in post-processing mode
[[ ${#args[@]} -gt 1 ]] && die "More than one argument not supported"
# we use maintrack variable to keep track of whether auxiliary menu should be entered
[[ ${#args[@]} -eq 1 ]] && maintrack=true
# If no args were given, show aux menu mode
# note that flags don't count as args, so as long as no jobname was given
# (irrespective of provided flags), aux menu will be entered
[[ ${#args[@]} -eq 0 ]] && show_menu=true
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 "$@"
setup_colors
# setup_colors
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}"
if $maintrack; then
if [[ $show_menu == "false" ]]; then
# Check if the argument contains a filetype
# (assumes a complete filename was passed)
jobfilename=${args[0]}
@ -238,9 +219,9 @@ if $maintrack; then
assetpathtarget="$assetpathtarget/${asset_array[1]}"
# also redefine $asset so we keep only the asset path
asset="${asset_array[0]}"
# create the local subdir inside assets/<current/
# create the local subdir inside assets/<current/
mkdir -p "$assetpathtarget" # -p suppresses error if dir already exists
fi
fi
msg "<thesis> Copying $asset to $assetpathtarget"
# cp but don't overwrite existing files
cp --preserve=timestamps --no-clobber --recursive $asset $assetpathtarget
@ -267,7 +248,7 @@ if $maintrack; then
photoslastrun="$path_thesis/assets/photos/.lowres/lastrun"
if [ ! -f "$photoslastrun" ]; then
# if, for some reason, the lastrun file does not exist
# copy over everything and then create the file
# copy over everything and then create the file
# (except for the .lowres tree itself, and any assets.external files)
rsync -av "$path_thesis/assets/photos/" "$path_thesis/assets/photos/.lowres/" --exclude ".lowres/" --exclude "assets.external"
touch "$photoslastrun"
@ -346,13 +327,13 @@ if $maintrack; then
# Run pdflatex, bibtex, and company
# Leaving this if-else for historical reasons, and also to print the message
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
# 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)
latexmk -pdf -bibtex $jobname
else
msg "${On_Cyan}<cheRTeX> Calling LaTeXMK${NOFORMAT}"
msg "${On_Cyan}<cheRTeX> Calling LaTeXMK${Color_Off}"
simpledelay.sh 2
latexmk -pdf -bibtex $jobname
fi
@ -435,7 +416,7 @@ else
fi
fi
die "All done. Exiting..." 0
die "All done. Exiting..."
fi
@ -451,7 +432,7 @@ runtime=$(( $endtime - $starttime ))
# send push message to Gotify server
# 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
# NOTE, multi-line bash command fails if interrupted by comment lines!
# Hide CURL response (-o /dev/null) and progress bar (--silent)
@ -465,16 +446,16 @@ if (( $runtime > 70 )); then
msg "Push notification sent to Gotify"
fi
msg "${On_Cyan}-------------------------------------${NOFORMAT}"
msg "${On_Cyan}-------------------------------------${Color_Off}"
# the padding for runtime makes the formatting work
# 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
msg "${On_Cyan}=== $(date) ===${NOFORMAT}"
msg "${On_Cyan}=== $(date) ===${Color_Off}"
else
msg "${On_Cyan}=== $(date) ===${NOFORMAT}"
msg "${On_Cyan}=== $(date) ===${Color_Off}"
fi
msg "${On_Cyan}-------------------------------------${NOFORMAT}"
msg "${On_Cyan}-------------------------------------${Color_Off}"
simpledelay.sh 3
exit 0

Loading…
Cancel
Save