#!/usr/bin/env bash # shellcheck disable=SC2034 # variable not used # shellcheck disable=SC1090 # follow non constant source enableErrorCheck() { # Do not allow use of unbound variables. # Use ${VAR:-} if possibly unbound set -o nounset } disableErrorCheck() { # Do allow the use of unbound vars. set +o nounset } # Exit on error. Append "|| true" if you expect an error. set -o errexit # Exit on error inside any functions or subshells. set -o errtrace enableErrorCheck # Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip` set -o pipefail # Turn on traces, useful while debugging but commented out by default # set -o xtrace ## Globals { readonly sqr_version=16 readonly sqr_versionMajor=0 readonly sqr_versionMinor=0 readonly sqr_versionString="${sqr_version}.${sqr_versionMajor}.${sqr_versionMinor}" ## Seq readonly seq_name="${_sqn_alias:-${0##*/}}" readonly seq_dir="$(cd -- "$(dirname -- "${0}")" && pwd)" readonly seq_origin="$(cd -- "$(dirname -- "$(readlink -f -- "${0}")")" && pwd)" readonly seq_file="$(basename -- "${0}")" readonly seq_fileName="${seq_file%%.*}" readonly seq_self="${seq_origin}/${seq_file}" # shellcheck disable=SC2015 # && || is not if else readonly seq_invocation="$(printf '%q' "${0}")$( (($#)) && printf ' %q' "$@" || true)" readonly seq_template="seqTemplate.sh" readonly _seq_configDirName=".seqs" _seq_configured=0 _seq_configEdit=0 _seq_profileList= _seq_stepReturn=255 seq_args= seq_configFile= # Filled by initSeqConfig seq_profileName= seq_configRoot="${HOME:-"$(pwd)"}/${_seq_configDirName}" # May be overwritten by seq seq_configName="${seq_fileName}.cfg" seq_configTemplate="${0%.*}.cfg.example" ## Sequencer readonly sqr_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" readonly sqr_file="$(basename -- "${BASH_SOURCE[0]}")" readonly sqr_name="${sqr_file%%.*}" readonly sqr_origin="$(cd -- "$(dirname -- \ "$(readlink -f -- "${BASH_SOURCE[0]}")")" && pwd)" sqr_args= sqr_missingConf=missingConf.log _sqr_contextHelp=0 _sqr_contextExe=0 _sqr_debug=0 _sqr_dry=0 _sqr_editor= _sqr_errno=0 _sqr_interactive=1 _sqr_single=0 readonly _sqr_stepMax=512 _sqr_verbose=0 # Part of a pipe or output to terminal _sqr_term=0 && [ -t 1 ] && _sqr_term=1 readonly _sqr_term _sqr_colorAlways=0 ## Terminal colors col_black='\033[0;30m' col_darkgrey='\033[1;30m' col_red='\033[0;31m' col_lightred='\033[1;31m' col_green='\033[0;32m' col_lightgreen='\033[1;32m' col_orange='\033[0;33m' col_yellow='\033[1;33m' col_blue='\033[0;34m' col_lightblue='\033[1;34m' col_purple='\033[0;35m' col_lightpurple='\033[1;35m' col_cyan='\033[0;36m' col_lightcyan='\033[1;36m' col_lightgray='\033[0;37m' col_white='\033[1;37m' ## No Color col_off='\033[0m' col() { local colVar="col_${1:-"off"}" ((_sqr_term)) || ((_sqr_colorAlways)) && echo "${!colVar}" true } } helpSequencer() { cat < 0 - silent \${LOG_TIME} 1 - Show time stamps before log outputs \${sqr_args} String of all given options \${seq_configRoot} Path to user specific seq configuration directory \${seq_configFile} Path to user specific seq configuration file Will be empty if unused \${seq_profileName} Profile string selected with -p argument sequencer.sh build-in functions: USAGE_API echo -e "$(col green) addConf $(col off)" cat <) to a destination file. If the CONFIGFILE exists, a backup (name_%Y%m%d-%H%M%S.bck) is saved at the same location. If -s fails or -m, "$(realpath "${sqr_missingConf}")" is created with the conflicts to be resolved by the user. -c : create a new file -a : append to existing file -s : skip if CONFIGFILE exists (no backup and entry in missing conf) -m : only add content to missing conf and warn user -e : enable interpretation of backslash escapes (ignored for -f) -f : is a file Text or file (-f) to create or added to Target file to be created or modified. USAGE_API echo -e "$(col green) ask [OPTION] [QUESTION] [DEFAULT]$(col off)" cat < [DESCRIPTION]$(col off)" cat < : Name without \$ [DESCRIPTION] : Additional text for error output USAGE_API echo -e "$(col green) endReturn [OPTIONS] [MESSAGE]$(col off)" cat <$(col off)" cat <,<,|). Supporting: dry-run (-d): only print command without execution verbose (-v): print command before execution USAGE_API echo -e "$(col green) exep \"[COMMAND STRING(s)]\"$(col off)" cat < \\'out put.log\\' exep echo hello world \\> out\\\\ put.log exep "echo hello world > 'out put.log'" exep "echo hello world > out\\ put.log" Important: - Shell commands cd, read, ... won't work because [COMMAND STRING(s)] is started in a new shell. - All apostrophes need to be esacped since the command line is given as string. USAGE_API echo -e "$(col green) exists [OPTIONS] [ELEMENT]$(col off)" cat < [TEMPLATE]$(col off)" cat <$(col off)" cat <