Added exit codes
This commit is contained in:
parent
1393aad7c0
commit
5c7c754dc3
@ -26,6 +26,12 @@ Log levels:
|
||||
5 | Fatal
|
||||
6 | No logging
|
||||
|
||||
Exit Codes:
|
||||
1 Dependencies not met
|
||||
2 Invalid Argument
|
||||
3 Source Unreachable
|
||||
4 Destination Unreachable
|
||||
|
||||
```
|
||||
|
||||
## Licence
|
||||
|
@ -16,6 +16,7 @@ GetOptions() {
|
||||
VerboseOutput 5 "\`getopt --test\` failed"
|
||||
VerboseOutput 5 "Sorry, It seems that your shell is not supported"
|
||||
VerboseOutput 5 "If you're using MacOS or another unix-like system, please install GNU getopt"
|
||||
ExecTime
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -93,6 +94,7 @@ Usage() {
|
||||
echo " -d, --dest <destination> The destionation folder of the music"
|
||||
echo " -v, --verbose <0-6> Set log level"
|
||||
echo " -h, --help Display this help text"
|
||||
echo ""
|
||||
echo "Log levels:"
|
||||
echo " 0 | Verbose"
|
||||
echo " 1 | Debug"
|
||||
@ -102,6 +104,12 @@ Usage() {
|
||||
echo " 5 | Fatal"
|
||||
echo " 6 | No logging"
|
||||
echo ""
|
||||
echo "Exit Codes:"
|
||||
echo " 1 Dependencies not met"
|
||||
echo " 2 Invalid Argument"
|
||||
echo " 3 Source Unreachable"
|
||||
echo " 4 Destination Unreachable"
|
||||
echo ""
|
||||
}
|
||||
|
||||
VerboseOutput() {
|
||||
@ -156,6 +164,12 @@ ConvertFiles() {
|
||||
mkdir -p /tmp/converted
|
||||
while read -r line
|
||||
do
|
||||
if [[ ! -f "${source}/$file" ]]; then
|
||||
VerboseOutput 5 "Source-file ${source}/$file Unreachable"
|
||||
ExecTime
|
||||
exit 3
|
||||
fi
|
||||
|
||||
VerboseOutput 1 "Converting: $line"
|
||||
if [[ "/tmp/converted/$line" = */* ]]; then
|
||||
mkdir -p "/tmp/converted/${line%/*}";
|
||||
@ -174,8 +188,17 @@ CopyFiles() {
|
||||
while read -r line
|
||||
do
|
||||
if [[ ! -f "$dest" ]]; then
|
||||
VerboseOutput 5 "Destination not reachable (anymore)"
|
||||
VerboseOutput 5 "Destination unreachable"
|
||||
ExecTime
|
||||
exit 4
|
||||
fi
|
||||
|
||||
if [[ ! -f "$line" ]]; then
|
||||
VerboseOutput 5 "Source-file ${source}/$file Unreachable"
|
||||
ExecTime
|
||||
exit 3
|
||||
fi
|
||||
|
||||
VerboseOutput 1 "Copying: $line"
|
||||
if [[ "$dest/$line" = */* ]]; then
|
||||
mkdir -p "$dest/${line%/*}";
|
||||
@ -192,6 +215,12 @@ CleanUp() {
|
||||
VerboseOutput 1 "Done"
|
||||
}
|
||||
|
||||
ExecTime() {
|
||||
termin=$(date +"%s")
|
||||
difftimelps=$(($termin-$begin))
|
||||
VerboseOutput 1 "$(($difftimelps / 60)) minutes and $(($difftimelps % 60)) seconds elapsed for Script Execution."
|
||||
}
|
||||
|
||||
GetOptions $@
|
||||
if [[ $help == true ]]; then
|
||||
Usage
|
||||
@ -208,7 +237,4 @@ fi
|
||||
ConvertFiles
|
||||
CopyFiles
|
||||
CleanUp
|
||||
|
||||
termin=$(date +"%s")
|
||||
difftimelps=$(($termin-$begin))
|
||||
VerboseOutput 1 "$(($difftimelps / 60)) minutes and $(($difftimelps % 60)) seconds elapsed for Script Execution."
|
||||
ExecTime
|
Loading…
Reference in New Issue
Block a user