Something went wrong. Try again.
My assorted media manipulation scripts
Something went wrong. Try again.
mediascripts toolchecker
3.9 kB · 121 lines
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122#!/usr/bin/env bash
[ $DEBUG ] && echo "<=> toolchecker checkin' for tools" && echo
# check bash version up front, I use some pretty modern dumb tricks, apparentlyif [ ${BASH_VERSION:0:1} -lt 4 ]; then echo "These scripts require bash version 4.0 or newer for arcane nonsense reasons." echo "Your bash version (${BASH_VERSION}) is too old." echo "If you are running macOS, Apple no longer ships modern bash for license reasons." echo "Consider installing a modern bash using Homebrew (https://brew.sh/) or Macports (https://macports.org)" exit 1fi
# see if a module collection was requested, if it was then we'll try to load up lmod and restore it# this is a convenience feature for me, a sicko, it is not a requirement# the scripts do not care if this works or notif [ -n "${MODULE_COLLECTION}" ]; then [ $DEBUG ] && echo "MODULE_COLLECTION: ${MODULE_COLLECTION}" env | grep BASH_FUNC_m &>/dev/null if [ $? -ne 0 ]; then [ -f /etc/profile.d/lmod.sh ] && source /etc/profile.d/lmod.sh fi ml restore "${MODULE_COLLECTION}" &>/dev/null if [ $? -eq 0 ]; then [ $DEBUG ] && echo "module collection '${MODULE_COLLECTION}' restored" [ $DEBUG ] && ml else [ $DEBUG ] && echo "could not restore module collection '${MODULE_COLLECTION}'" fifi
# Check for tool dependencies
## External tools[ -z "$TOOLS" ] && TOOLS=(ffmpeg ffprobe mkvpropedit mediainfo jq bc tr sed grep awk)
for tool in ${TOOLS[@]}; do [ "$tool" = "NONE" ] && break if [ "$tool" == "sed" ]; then sed --help &>/dev/null if [ $? -ne 0 ]; then gsed --help &>/dev/null if [ $? -eq 0 ]; then VAR="SED" tool="gsed" else echo "This tool requires GNU sed." echo "If you are on a Macintosh computer machine, you can install GNU sed via homebrew with: brew install gnu-sed" exit 1 fi else VAR="${tool^^}" fi else VAR="${tool^^}" fi if [ -z "${!VAR}" ]; then declare "$VAR"=`which $tool 2>/dev/null` if [ -z "${!VAR}" ]; then echo "$tool not found." exit 1 fi elif [ ! -x ${!VAR} ]; then echo "$tool not executable." exit 1 fi [ $DEBUG ] && echo "$VAR: ${!VAR}" if [ "$tool" = "ffmpeg" ]; then FFMPEG_PREFIX=`$FFMPEG -hide_banner -buildconf 2>&1 | grep prefix | awk -F= '{print $2}'` [ $DEBUG ] && echo "FFMPEG_PREFIX: ${FFMPEG_PREFIX}" fidone
## Utility scripts from this toolkit[ -z "$SCRIPTS" ] && SCRIPTS=(cropfinder stripcovers striptags addstats)[ -z "$SELF_DIR" ] && SELF_DIR=$(dirname realpath $0)
for script in ${SCRIPTS[@]}; do [ "$script" = "NONE" ] && break VAR="${script^^}" if [ -z "${!VAR}" ]; then declare "$VAR"=$(realpath $SELF_DIR/$script 2>/dev/null) if [ -z "${!VAR}" ]; then echo "$script not found." exit 1 fi elif [ ! -x ${!VAR} ]; then echo "$script not executable." exit 1 fi [ $DEBUG ] && echo "$VAR: ${!VAR}"done
## Save a copy of the IFS because I abuse it fucking constantlyO_IFS="${IFS}"
## Helpful functionsfail() { { set +x; }; 2>/dev/null printf '%s\n' "${1}" >&2 ## Send message to stderr. exit "${2-1}" ## Return a code specified by $2, or 1 by default.}
paramsmunge() { case ":${PARAMS}:" in *:"${1}":*) ;; *) if [ "$2" = "after" ] ; then PARAMS=$(echo ${PARAMS}:${1} | sed -e 's/^://g' -e 's/:$//g') else PARAMS=$(echo ${1}:${PARAMS} | sed -e 's/^://g' -e 's/:$//g') fi esac}
PARAMS=
[ $DEBUG ] && echo && echo "<=> toolchecker complete"[ $DEBUG ] && echo