-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcvcbulkcommit
executable file
·127 lines (105 loc) · 3.58 KB
/
cvcbulkcommit
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
################################################################################
# Loading configuration
################################################################################
CVCINTERNAL_SCRIPTROOT=$(dirname "$0")
source "${CVCINTERNAL_SCRIPTROOT}/config"
################################################################################
# Documentation
################################################################################
# Return code reference
# 1 Syntax error in invocation
# 2 Missing argument
# 3 Target directory does not exist
# 16 Internal error
# Show usage
function usage {
echo "This script runs cvccommit for all the CVC files of a directory, thus"
echo "allowing to quickly update metadata for whole albums."
echo ""
echo "Usage: cvcbulkcommit [-f] [-h] [-l <lang>] [-v] <directory>"
echo ""
echo "Options:"
echo "-f Overwrite preexisting cvc files."
echo "-h Show this message."
echo "-l <lang> Specify a language filter (cvccommit -l option)."
echo "-v Verbose mode."
echo ""
echo "Arguments:"
echo "<directory> A directory containing CVC files."
}
################################################################################
# Option and argument parsing
################################################################################
# Default settings
extraArgs=""
# Calling option parser
while getopts ":fhl:v" option; do
case "${option}" in
# -f: Force mode
f)
extraArgs+="-f "
;;
# -h: Help
h)
usage
exit
;;
# -l: Language filter
l)
extraArgs+="-l ${OPTARG}"
;;
# -v: Verbose mode
v)
VERBOSE=1
extraArgs+="-v "
;;
# Syntax error
\?)
>&2 echo "ERROR: Invalid option: -${OPTARG}"
usage
[[ "${BASH_SOURCE[0]}" != "${0}" ]] && return 1 || exit 1
;;
# Syntax error
:)
>&2 echo "ERROR: Option -${OPTARG} requires an argument."
usage
[[ "${BASH_SOURCE[0]}" != "${0}" ]] && return 1 || exit 1
;;
# Any other value is an internal error
*)
>&2 echo "ERROR: Internal getopts error."
[[ "${BASH_SOURCE[0]}" != "${0}" ]] && return 16 || exit 16
;;
esac
done
shift $((OPTIND-1))
# Checking whether a directory was supplied as an argument.
if [ -z "$1" ]
then
>&2 echo "ERROR: No directory specified."
usage
[[ "${BASH_SOURCE[0]}" != "${0}" ]] && return 2 || exit 2
fi
################################################################################
# Additional checks
################################################################################
# Abstracting supplied arguments. We remove the trailing /
targetDirectory="${1%/}"
# Checking whether the supplied directory does exist
if [ ! -d "${targetDirectory}" ]
then
>&2 echo "ERROR: Directory '${targetDirectory}' does not exist."
[[ "${BASH_SOURCE[0]}" != "${0}" ]] && return 3 || exit 3
fi
################################################################################
# Calling cvccommit
################################################################################
# Initializing file counter
fileCount=0
for cvcFile in "${targetDirectory}/"*.${CFG_FileExtensions_CVC}
do
((fileCount+=1))
[ "${VERBOSE}" ] && echo "Processing file #${fileCount}: ${cvcFile}..."
"${CFG_CVCTools_CVCCommit}" ${extraArgs} "${cvcFile}"
done