Added error handlers
This commit is contained in:
parent
a0d0d30989
commit
c9b24e4ec2
@ -32,6 +32,7 @@ Exit Codes:
|
||||
2 Invalid Argument
|
||||
3 Source Unreachable
|
||||
4 Destination Unreachable
|
||||
5 Command failed
|
||||
|
||||
```
|
||||
|
||||
|
@ -131,6 +131,7 @@ Usage() {
|
||||
echo " 2 Invalid Argument"
|
||||
echo " 3 Source Unreachable"
|
||||
echo " 4 Destination Unreachable"
|
||||
echo " 5 Command failed"
|
||||
echo ""
|
||||
}
|
||||
|
||||
@ -243,14 +244,18 @@ CopyFiles() {
|
||||
if [[ "$dest/$line" = */* ]]; then
|
||||
mkdir -p "$dest/${line%/*}";
|
||||
fi;
|
||||
|
||||
cp -f $temp/$line $dest/$line 1>/dev/null 2>/dev/null
|
||||
|
||||
done < "/tmp/music-sync-filelist"
|
||||
VerboseOutput 2 "Copied: $line"
|
||||
}
|
||||
|
||||
CleanUp() {
|
||||
VerboseOutput 1 "Cleaning Up"
|
||||
if [[ -f /tmp/music-sync-filelist ]]; then
|
||||
rm "/tmp/music-sync-filelist"
|
||||
fi
|
||||
VerboseOutput 1 "Done"
|
||||
}
|
||||
|
||||
@ -260,6 +265,21 @@ ExecTime() {
|
||||
VerboseOutput 1 "$(($difftimelps / 60)) minutes and $(($difftimelps % 60)) seconds elapsed for Script Execution."
|
||||
}
|
||||
|
||||
ErrorHandler() {
|
||||
VerboseOutput 5 "Error while executing $1"
|
||||
CleanUp
|
||||
exit 5
|
||||
}
|
||||
|
||||
ExitHandler() {
|
||||
VerboseOutput 5 "Aborted"
|
||||
CleanUp
|
||||
exit 0
|
||||
}
|
||||
|
||||
trap 'ExitHandler' SIGINT
|
||||
trap 'ErrorHandler $BASH_COMMAND' ERR
|
||||
|
||||
CheckDeps
|
||||
GetOptions $@
|
||||
if [[ $help == true ]]; then
|
||||
@ -272,6 +292,7 @@ fi
|
||||
CreateFileList $source $dest ""
|
||||
if [[ ! -f /tmp/music-sync-filelist ]]; then
|
||||
VerboseOutput 2 "Nothing to do!"
|
||||
CleanUp
|
||||
exit 0
|
||||
fi
|
||||
ConvertFiles
|
||||
|
Loading…
Reference in New Issue
Block a user