-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoolchecker
83 lines (71 loc) · 2.4 KB
/
toolchecker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env bash
# check bash version up front, I use some pretty modern dumb tricks, apparently
if [ ${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 1
fi
# 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
VAR="${tool^^}"
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}"
fi
done
## 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 constantly
O_IFS="${IFS}"
## Helpful functions
fail() {
{ 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