Added exit codes

This commit is contained in:
Jeroen De Meerleer 2018-11-30 17:36:54 +01:00
parent 1393aad7c0
commit 5c7c754dc3
2 changed files with 38 additions and 6 deletions

View File

@ -26,6 +26,12 @@ Log levels:
5 | Fatal 5 | Fatal
6 | No logging 6 | No logging
Exit Codes:
1 Dependencies not met
2 Invalid Argument
3 Source Unreachable
4 Destination Unreachable
``` ```
## Licence ## Licence

View File

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