# Script Metadata
scriptName="bklog"; # Define basename of script file.
-scriptVersion="0.1.8"; # Define version of script.
+scriptVersion="0.1.9"; # Define version of script.
scriptURL="https://gitlab.com/baltakatei/ninfacyzga-01"; # Define wesite hosting this script.
scriptTimeStart="$(date +%Y%m%dT%H%M%S.%N)"; # YYYYmmddTHHMMSS.NNNNNNNNN
scriptHostname=$(hostname); # Save hostname of system running this script.
# Parse '-t' option (user-specified temporary working dir)
## Set dir_tmp_parent to user-specified value if specified
local dir_tmp_parent
-
+
+ vbm "Starting magicInitWorkingDir() function.";
if [[ "$optionTmpDir" = "true" ]]; then
if [[ -d "$argTempDirPriority" ]]; then
dir_tmp_parent="$argTempDirPriority";
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
# 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";
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
+ 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
+ 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
+ fi;
+ vbm "Starting magicParseCompressionArg() function.";
} # Form compression cmd string and filename suffix
magicParseCustomTTL() {
# Desc: Set user-specified TTLs for buffer and script
# 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
yell "ERROR:Invalid time element argument for custom script time-to-live."; showUsage; exit 1;
fi;
## F: do not change scriptTTL_TE
- fi;
+ fi;
+ vbm "Starting magicParseCustomTTL() function.";
} # Sets custom script or buffer TTL if specified
magicParseLabel() {
# Desc: Parses -l option to set label
# Depends: processArguments(), yell(), vbm(), checkapp(), checkAgePubkey(), validateInput()
local recipients
+ vbm "Starting magicParseRecipientArgs() function.";
# Check if encryption option active.
if [[ "$optionEncrypt" = "true" ]] && [[ "$optionRecipients" = "true" ]]; then
if checkapp age; then # Check that age is available.
yell "ERROR:\\'-e\\' set but no \\'-r\\' or \\'-R\\' set."; exit 1; fi;
# Catch case if '-r' or '-R' set but '-e' is not
if [[ ! "$optionEncrypt" = "true" ]] && [[ "$optionRecipients" = "true" ]]; then
- yell "ERROR:\\'-r\\' or \\'-R\\' set but \\'-e\\' is not set."; exit 1; fi;
+ yell "ERROR:\\'-r\\' or \\'-R\\' set but \\'-e\\' is not set."; exit 1; fi;
+ vbm "Finished magicParseRecipientArgs() function.";
} # Populate recPubKeysValid with argRecPubKeys; form encryption cmd string and filename suffix
magicParseRecipientDir() {
# Desc: Updates recPubKeysValid with pubkeys in dir specified by '-R' option ("recipient directory")
local recipientDir recFileLine updateRecipients
declare -a candRecPubKeysValid
+ vbm "Starting magicParseRecipientDir() function.";
# Check that '-e' and '-R' set
if [[ "$optionEncrypt" = "true" ]] && [[ "$optionRecDir" = "true" ]]; then
### Check that argRecDir is a directory.
# Handle case if '-R' set but '-e' not set
if [[ ! "$optionEncrypt" = "true" ]] && [[ "$optionRecDir" = "true" ]]; then
yell "ERROR: \\'-R\\' is set but \\'-e\\' is not set."; fi;
+ vbm "Finished magicParseRecipientDir() function.";
} # Update recPubKeysValid with argRecDir
magicSetScriptTTL() {
#Desc: Sets script_TTL seconds from provided time_element string argument
#Output: var: scriptTTL (integer seconds)
#Depends: timeUntilNextHour, timeUntilNextDay
local argTimeElement
-
+
+ vbm "Starting magicSetScriptTTL() function.";
argTimeElement="$1";
if [[ "$argTimeElement" = "day" ]]; then
# Set script lifespan to end at start of next day
else
yell "ERROR:Invalid argument for setScriptTTL function:$argTimeElement"; exit 1;
fi;
+ vbm "Finished magicSetScriptTTL() function.";
} # Set scriptTTL in seconds until next (day|hour).
magicWriteVersion() {
# Desc: Appends time-stamped VERSION to pathout_tar
# Output: appends tar (pathout_tar)
# Depends: bash 5.0.3, dateTimeShort(), appendArgTar()
local fileoutVersion contentVersion pubKeyIndex pubKeyIndex
-
+
+ vbm "Starting magicWriteVersion() function.";
# Set VERSION file name
fileoutVersion="$(dateTimeShort)..VERSION";
# Write contentVersion as file fileoutVersion and write-append to pathout_tar
appendArgTar "$contentVersion" "$fileoutVersion" "$pathout_tar" "$dir_tmp";
+ vbm "Finished magicWriteVersion() function.";
} # write version data to pathout_tar via appendArgTar()
magicProcessWriteBuffer() {
# Desc: process and write buffer