From: Steven Baltakatei Sandoval Date: Mon, 21 Jun 2021 20:44:17 +0000 (+0000) Subject: Merge branch 'master' of https://zdv2.bktei.com/gitweb/baltakatei-exdev into develop X-Git-Tag: 0.4.6^0 X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/10d2c1f3504d98aa8129b2fd846a523790aba810?hp=bd4ff344cc3dcaefca30e4ebdca956cd3d92b3b2 Merge branch 'master' of https://zdv2.bktei.com/gitweb/baltakatei-exdev into develop --- diff --git a/sysutils/tick_minute.sh b/sysutils/tick_minute.sh new file mode 100755 index 0000000..ff8cecc --- /dev/null +++ b/sysutils/tick_minute.sh @@ -0,0 +1,139 @@ +#!/bin/bash + +# Desc: Outputs to stdout the current iso-8601 timestamp (minute accuracy) +# Usage: tick_minute.sh +# Example tick_minute.sh + +#==BEGIN Define script parameters== +#===BEGIN Declare variables=== +declare -Ag appRollCall # Associative array for storing app status +declare -Ag fileRollCall # Associative array for storing file status +declare -Ag dirRollCall # Associative array for storing dir status +declare exitFlag +#===END Declare variables=== + + +#===BEGIN Declare local script functions=== +yell() { echo "$0: $*" >&2; } # Yell, Die, Try Three-Fingered Claw technique; # Ref/Attrib: https://stackoverflow.com/a/25515370 +die() { yell "$*"; exit 111; } +try() { "$@" || die "cannot $*"; } +checkapp() { + # Desc: If arg is a command, save result in assoc array 'appRollCall' + # Usage: checkapp arg1 arg2 arg3 ... + # Version: 0.1.1 + # Input: global assoc. array 'appRollCall' + # Output: adds/updates key(value) to global assoc array 'appRollCall' + # Depends: bash 5.0.3 + local returnState + + #===Process Args=== + for arg in "$@"; do + if command -v "$arg" 1>/dev/null 2>&1; then # Check if arg is a valid command + appRollCall[$arg]="true"; + if ! [ "$returnState" = "false" ]; then returnState="true"; fi; + else + appRollCall[$arg]="false"; returnState="false"; + fi; + done; + + #===Determine function return code=== + if [ "$returnState" = "true" ]; then + return 0; + else + return 1; + fi; +} # Check that app exists +displayMissing() { + # Desc: Displays missing apps, files, and dirs + # Usage: displayMissing + # Version 0.1.1 + # Input: associative arrays: appRollCall, fileRollCall, dirRollCall + # Output: stderr: messages indicating missing apps, file, or dirs + # Depends: bash 5, checkAppFileDir() + local missingApps value appMissing missingFiles fileMissing + local missingDirs dirMissing + + #==BEGIN Display errors== + #===BEGIN Display Missing Apps=== + missingApps="Missing apps :"; + #for key in "${!appRollCall[@]}"; do echo "DEBUG:$key => ${appRollCall[$key]}"; done + for key in "${!appRollCall[@]}"; do + value="${appRollCall[$key]}"; + if [ "$value" = "false" ]; then + #echo "DEBUG:Missing apps: $key => $value"; + missingApps="$missingApps""$key "; + appMissing="true"; + fi; + done; + if [ "$appMissing" = "true" ]; then # Only indicate if an app is missing. + echo "$missingApps" 1>&2; + fi; + unset value; + #===END Display Missing Apps=== + + #===BEGIN Display Missing Files=== + missingFiles="Missing files:"; + #for key in "${!fileRollCall[@]}"; do echo "DEBUG:$key => ${fileRollCall[$key]}"; done + for key in "${!fileRollCall[@]}"; do + value="${fileRollCall[$key]}"; + if [ "$value" = "false" ]; then + #echo "DEBUG:Missing files: $key => $value"; + missingFiles="$missingFiles""$key "; + fileMissing="true"; + fi; + done; + if [ "$fileMissing" = "true" ]; then # Only indicate if an app is missing. + echo "$missingFiles" 1>&2; + fi; + unset value; + #===END Display Missing Files=== + + #===BEGIN Display Missing Directories=== + missingDirs="Missing dirs:"; + #for key in "${!dirRollCall[@]}"; do echo "DEBUG:$key => ${dirRollCall[$key]}"; done + for key in "${!dirRollCall[@]}"; do + value="${dirRollCall[$key]}"; + if [ "$value" = "false" ]; then + #echo "DEBUG:Missing dirs: $key => $value"; + missingDirs="$missingDirs""$key "; + dirMissing="true"; + fi; + done; + if [ "$dirMissing" = "true" ]; then # Only indicate if an dir is missing. + echo "$missingDirs" 1>&2; + fi; + unset value; + #===END Display Missing Directories=== + + #==END Display errors== +} # Display missing apps, files, dirsw +main() { + # Desc: main program + # Input: var: arg1: path + # var: appRollCall checkapp() dependency + # var: exitFlag indicates to script if exit required + # Output: stdout: iso-8601 date string + # Depends: try() + + # Validate input + ## Check argument count (must be 0) + if [[ $# -gt 0 ]]; then yell "ERROR:Too many arguments:$#"; exitFlag="true"; fi; + + ## Check Apps + if ! checkapp date echo; then yell "ERROR:Missing App"; exitFlag="true"; fi; + + ## Report errors + displayMissing; + if [[ $exitFlag == "true" ]]; then exit 1; fi; + + # Form output + output="$(date +%Y-%m-%dT%H:%M%z)"; #iso-8601 string (e.g. 2021-05-28T19:18+0000) + + # Write output + echo "$output"; +} + +#===END Declare local script functions=== +#==END Define script parameters== + +try main "$@"; diff --git a/sysutils/tick_second.sh b/sysutils/tick_second.sh new file mode 100755 index 0000000..e85a865 --- /dev/null +++ b/sysutils/tick_second.sh @@ -0,0 +1,139 @@ +#!/bin/bash + +# Desc: Outputs to stdout the current iso-8601 timestamp (second accuracy) +# Usage: tick_second.sh +# Example tick_second.sh + +#==BEGIN Define script parameters== +#===BEGIN Declare variables=== +declare -Ag appRollCall # Associative array for storing app status +declare -Ag fileRollCall # Associative array for storing file status +declare -Ag dirRollCall # Associative array for storing dir status +declare exitFlag +#===END Declare variables=== + + +#===BEGIN Declare local script functions=== +yell() { echo "$0: $*" >&2; } # Yell, Die, Try Three-Fingered Claw technique; # Ref/Attrib: https://stackoverflow.com/a/25515370 +die() { yell "$*"; exit 111; } +try() { "$@" || die "cannot $*"; } +checkapp() { + # Desc: If arg is a command, save result in assoc array 'appRollCall' + # Usage: checkapp arg1 arg2 arg3 ... + # Version: 0.1.1 + # Input: global assoc. array 'appRollCall' + # Output: adds/updates key(value) to global assoc array 'appRollCall' + # Depends: bash 5.0.3 + local returnState + + #===Process Args=== + for arg in "$@"; do + if command -v "$arg" 1>/dev/null 2>&1; then # Check if arg is a valid command + appRollCall[$arg]="true"; + if ! [ "$returnState" = "false" ]; then returnState="true"; fi; + else + appRollCall[$arg]="false"; returnState="false"; + fi; + done; + + #===Determine function return code=== + if [ "$returnState" = "true" ]; then + return 0; + else + return 1; + fi; +} # Check that app exists +displayMissing() { + # Desc: Displays missing apps, files, and dirs + # Usage: displayMissing + # Version 0.1.1 + # Input: associative arrays: appRollCall, fileRollCall, dirRollCall + # Output: stderr: messages indicating missing apps, file, or dirs + # Depends: bash 5, checkAppFileDir() + local missingApps value appMissing missingFiles fileMissing + local missingDirs dirMissing + + #==BEGIN Display errors== + #===BEGIN Display Missing Apps=== + missingApps="Missing apps :"; + #for key in "${!appRollCall[@]}"; do echo "DEBUG:$key => ${appRollCall[$key]}"; done + for key in "${!appRollCall[@]}"; do + value="${appRollCall[$key]}"; + if [ "$value" = "false" ]; then + #echo "DEBUG:Missing apps: $key => $value"; + missingApps="$missingApps""$key "; + appMissing="true"; + fi; + done; + if [ "$appMissing" = "true" ]; then # Only indicate if an app is missing. + echo "$missingApps" 1>&2; + fi; + unset value; + #===END Display Missing Apps=== + + #===BEGIN Display Missing Files=== + missingFiles="Missing files:"; + #for key in "${!fileRollCall[@]}"; do echo "DEBUG:$key => ${fileRollCall[$key]}"; done + for key in "${!fileRollCall[@]}"; do + value="${fileRollCall[$key]}"; + if [ "$value" = "false" ]; then + #echo "DEBUG:Missing files: $key => $value"; + missingFiles="$missingFiles""$key "; + fileMissing="true"; + fi; + done; + if [ "$fileMissing" = "true" ]; then # Only indicate if an app is missing. + echo "$missingFiles" 1>&2; + fi; + unset value; + #===END Display Missing Files=== + + #===BEGIN Display Missing Directories=== + missingDirs="Missing dirs:"; + #for key in "${!dirRollCall[@]}"; do echo "DEBUG:$key => ${dirRollCall[$key]}"; done + for key in "${!dirRollCall[@]}"; do + value="${dirRollCall[$key]}"; + if [ "$value" = "false" ]; then + #echo "DEBUG:Missing dirs: $key => $value"; + missingDirs="$missingDirs""$key "; + dirMissing="true"; + fi; + done; + if [ "$dirMissing" = "true" ]; then # Only indicate if an dir is missing. + echo "$missingDirs" 1>&2; + fi; + unset value; + #===END Display Missing Directories=== + + #==END Display errors== +} # Display missing apps, files, dirsw +main() { + # Desc: main program + # Input: var: arg1: path + # var: appRollCall checkapp() dependency + # var: exitFlag indicates to script if exit required + # Output: stdout: iso-8601 date string + # Depends: try() + + # Validate input + ## Check argument count (must be 0) + if [[ $# -gt 0 ]]; then yell "ERROR:Too many arguments:$#"; exitFlag="true"; fi; + + ## Check Apps + if ! checkapp date echo; then yell "ERROR:Missing App"; exitFlag="true"; fi; + + ## Report errors + displayMissing; + if [[ $exitFlag == "true" ]]; then exit 1; fi; + + # Form output + output="$(date +%Y-%m-%dT%H:%M:%S%z)"; #iso-8601 string (e.g. 2021-05-28T19:30:57+0000) + + # Write output + echo "$output"; +} + +#===END Declare local script functions=== +#==END Define script parameters== + +try main "$@"; diff --git a/unitproc/bkvideo2webm b/unitproc/bkvideo2webm new file mode 100755 index 0000000..41e9e29 --- /dev/null +++ b/unitproc/bkvideo2webm @@ -0,0 +1,19 @@ +#/bin/bash +# Desc: Convert video file to webm +# Usage: bkvideo2webm.sh [ file ] +# Example: +# $ for file in ./*; do bkvideo2webm "$file"; done; +# Ref/Attrib: Geert Van Pamel, original author; date accessed: 2021-06-12; url: https://commons.wikimedia.org/wiki/Help:Converting_video +# Version 0.1.2 +# Depends: ffmpeg version 4.1.6-1 (see https://tracker.debian.org/pkg/ffmpeg ) + +# Parameters: +# P1: input file name + +if [[ -z "$1" ]]; then echo "Input file missing"; exit; fi; + +input="$1"; +output=$(basename "$1").webm + +ffmpeg -i "$input" -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -row-mt 1 -an -f webm -y /dev/null; +ffmpeg -i "$input" -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 -row-mt 1 -c:a libopus "$output";