+ ## Set dir_tmp_parent to default or fallback otherwise
+ if [[ -d "$dirTmpDefault" ]]; then
+ dir_tmp_parent="$dirTmpDefault";
+ elif [[ -d /tmp ]]; then
+ yell "WARNING:$dirTmpDefault not available. Falling back to /tmp .";
+ dir_tmp_parent="/tmp";
+ else
+ yell "ERROR:No valid working directory available. Exiting.";
+ exit 1;
+ fi;
+ fi;
+ ## Set dir_tmp using dir_tmp_parent and nonce (scriptTimeStart)
+ dir_tmp="$dir_tmp_parent"/"$scriptTimeStart""..bkgpslog" && vbm "DEBUG:Set dir_tmp to:$dir_tmp"; # Note: removed at end of main().
+ vbm "Finished magicInitWorkingDir() function.";
+} # Sets working dir
+magicInitCheckTar() {
+ # Desc: Initializes or checks output tar
+ # input: vars: dirOut, bufferTTL, cmd_encrypt_suffix, cmd_compress_suffix
+ # input: vars: scriptHostname
+ # output: vars: pathout_tar
+ # depends: Bash 5.0.3, vbm(), dateShort(), checkMakeTar(), magicWriteVersion()
+
+ vbm "Starting magicInitCheckTar() function.";
+ # Form pathout_tar
+ pathout_tar="$dirOut"/"$(dateShort "$(date --date="$bufferTTL seconds ago" --iso-8601=seconds)")".."$scriptHostname""$label""$cmd_compress_suffix""$cmd_encrypt_suffix".tar && \
+ vbm "STATUS:Set pathout_tar to:$pathout_tar";
+ # Validate pathout_tar as tar.
+ checkMakeTar "$pathout_tar";
+ ## Add VERSION file if checkMakeTar had to create a tar (exited 1) or replace one (exited 2)
+ vbm "exit status before magicWriteVersion:$?"
+ if [[ $? -eq 1 ]] || [[ $? -eq 2 ]]; then magicWriteVersion; fi
+ vbm "Finished magicInitCheckTar() function.";
+} # Initialize tar, set pathout_tar
+magicParseCompressionArg() {
+ # Desc: Parses compression arguments specified by '-c' option
+ # Input: vars: optionCompress
+ # Output: cmd_compress, cmd_compress_suffix
+ # Depends: processArguments(), vbm(), checkapp(), gzip 1.9
+
+ vbm "Starting magicParseCompressionArg() function.";
+ if [[ "$optionCompress" = "true" ]]; then # Check if compression option active
+ if checkapp gzip; then # Check if gzip available
+ cmd_compress="gzip " && vbm "cmd_compress:$cmd_compress";
+ cmd_compress_suffix=".gz" && vbm "cmd_compress_suffix:$cmd_compress_suffix";
+ else
+ yell "ERROR:Compression enabled but \"gzip\" not found. Exiting."; exit 1;
+ fi;
+ else
+ cmd_compress="tee /dev/null " && vbm "cmd_compress:$cmd_compress";
+ cmd_compress_suffix="" && vbm "cmd_compress_suffix:$cmd_compress_suffix";
+ vbm "DEBUG:Compression not enabled.";
+ fi;
+ vbm "Starting magicParseCompressionArg() function.";
+} # Form compression cmd string and filename suffix
+magicParseCustomTTL() {
+ # Desc: Set user-specified TTLs for buffer and script
+ # Usage: magicParseCustomTTL
+ # Input: vars: argCustomBufferTTL (integer), argCustomScriptTTL_TE (string)
+ # Input: vars: optionCustomBufferTTL, optionCustomScriptTTL_TE
+ # Input: vars: bufferTTL (integer), scriptTTL_TE (string)
+ # Output: bufferTTL (integer), scriptTTL_TE (string)
+ # Depends: Bash 5.0.3, yell(), vbm(), validateInput(), showUsage()
+
+ vbm "Starting magicParseCustomTTL() function.";
+ # React to '-b, --buffer-ttl' option
+ if [[ "$optionCustomBufferTTL" = "true" ]]; then
+ ## T: Check if argCustomBufferTTL is an integer
+ if validateInput "$argCustomBufferTTL" "integer"; then
+ ### T: argCustomBufferTTL is an integer
+ bufferTTL="$argCustomBufferTTL" && vbm "Custom bufferTTL from -b:$bufferTTL";
+ else
+ ### F: argcustomBufferTTL is not an integer
+ yell "ERROR:Invalid integer argument for custom buffer time-to-live."; showUsage; exit 1;
+ fi;
+ ## F: do not change bufferTTL
+ fi;
+
+ # React to '-B, --script-ttl' option
+ if [[ "$optionCustomScriptTTL_TE" = "true" ]]; then
+ ## T: Check if argCustomScriptTTL is a time element (ex: "day", "hour")
+ if validateInput "$argCustomScriptTTL_TE" "time_element"; then
+ ### T: argCustomScriptTTL is a time element
+ scriptTTL_TE="$argCustomScriptTTL_TE" && vbm "Custom scriptTTL_TE from -B:$scriptTTL_TE";
+ else
+ ### F: argcustomScriptTTL is not a time element
+ yell "ERROR:Invalid time element argument for custom script time-to-live."; showUsage; exit 1;
+ fi;
+ ## F: do not change scriptTTL_TE
+ fi;
+ vbm "Starting magicParseCustomTTL() function.";
+} # Sets custom script or buffer TTL if specified
+magicParseLabel() {
+ # Desc: Parses -l option to set label
+ # In : optionLabel, argLabel
+ # Out: vars: label
+ # Depends: Bash 5.0.3, vbm(), yell()
+
+ vbm "STATUS:Started magicParseLabel() function.";
+ # Do nothing if optionLabel not set to true.
+ if [[ ! "$optionLabel" = "true" ]]; then
+ vbm "STATUS:optionlabel not set to 'true'. Returning early.";
+ return;
+ fi;
+ # Set label if optionLabel is true
+ if [[ "$optionLabel" = "true" ]]; then
+ label="_""$argLabel";
+ vbm "STATUS:Set label:$label";
+ fi;
+ vbm "STATUS:Finished magicParseLabel() function.";
+} # Set label used in output file name
+magicParseProcessStrings() {
+ # Desc: Processes user-supplied process strings into process commands for appendFileTar().
+ # Usage: magicParseProcessStrings
+ # In : vars: optionProcString optionNoStoreRaw optionStoreRaw argRawFileExt
+ # arry: argProcStrings, argProcFileExts
+ # Out: arry: procStrings, procFileExts
+ # Depends Bash 5.0.3, yell(), vbm()
+ local rawFileExt
+
+ vbm "STATUS:Starting magicParseProcessStrings() function.";
+ vbm "var:optionProcString:$optionProcString";
+ vbm "var:optionNoStoreRaw:$optionNoStoreRaw";
+ vbm "var:optionStoreRaw:$optionStoreRaw";
+ vbm "var:argRawFileExt:$argRawFileExt";
+ vbm "ary:argProcStrings:${argProcStrings[*]}";
+ vbm "ary:argProcFileExts:${argProcFileExts[*]}"
+ # Validate input
+ ## Validate argRawFileExt
+ if [[ "$argRawFileExt" =~ ^[.][[:alnum:]]*$ ]]; then
+ rawFileExt="$argRawFileExt";
+ fi;
+
+ # Add default stdin output file entries for procStrings, procFileExts
+ ## Check if user specified that no raw stdin be saved.
+ if [[ ! "$optionNoStoreRaw" = "true" ]]; then
+ ### T: --no-store-raw not set. Store raw. Append procStrings with cat.
+ #### Append procStrings array
+ procStrings+=("cat ");
+ #### Check if --store-raw set.
+ if [[ "$optionStoreRaw" = "true" ]]; then
+ ##### T: --store-raw set. Append procFileExts with user-specified file ext
+ procFileExts+=("$rawFileExt");