Added posibility to not convert

This commit is contained in:
Jeroen De Meerleer 2018-12-01 18:40:13 +01:00
parent 3d108ecf7f
commit 4aee64d3fe
2 changed files with 39 additions and 19 deletions

View File

@ -15,6 +15,7 @@ Options:
-s, --source <source> The source folder of the music -s, --source <source> The source folder of the music
-d, --dest <destination> The destionation folder of the music -d, --dest <destination> The destionation folder of the music
-t, --temp <folder> The temporary cache for converted files (default: /tmp/converted) -t, --temp <folder> The temporary cache for converted files (default: /tmp/converted)
-c, --convert Convert files before syncing
-v, --verbose <0-6> Set log level (default: 2) -v, --verbose <0-6> Set log level (default: 2)
-h, --help Display this help text -h, --help Display this help text

View File

@ -5,36 +5,42 @@ begin=$(date +"%s")
set -o errexit -o pipefail -o noclobber -o nounset set -o errexit -o pipefail -o noclobber -o nounset
source="-" source="-"
dest="-" dest="-"
convert=false
verbose=2 verbose=2
help=false help=false
temp="/tmp/converted" temp="/tmp/converted"
CheckDeps() { CheckDeps() {
# Check getopt if [[ $1 == 0 ]]; then
! getopt --test > /dev/null # Check getopt
if [[ ${PIPESTATUS[0]} -ne 4 ]]; then ! getopt --test > /dev/null
VerboseOutput 5 "\`getopt --test\` failed" if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
VerboseOutput 5 "Sorry, It seems that your shell is not supported" VerboseOutput 5 "\`getopt --test\` failed"
VerboseOutput 5 "If you're using MacOS or another unix-like system, please install GNU getopt" VerboseOutput 5 "Sorry, It seems that your shell is not supported"
ExecTime VerboseOutput 5 "If you're using MacOS or another unix-like system, please install GNU getopt"
exit 1 ExecTime
exit 1
fi
fi fi
# Check lame if [[ $1 == 1 ]]; then
if [[ ! $(lame --version 2>/dev/null) ]]; then # Check lame
VerboseOutput 5 "\`lame --version\` failed" echo $convert
VerboseOutput 5 "Sorry, It seems that lame is not installed on your system" if [[ $convert == true && ! $(lamek --version 2>/dev/null) ]]; then
VerboseOutput 5 "Please install lame from your repositories and make sure it is available in your \$PATH" VerboseOutput 5 "\`lame --version\` failed"
ExecTime VerboseOutput 5 "Sorry, It seems that lame is not installed on your system"
exit 1 VerboseOutput 5 "Please install lame from your repositories and make sure it is available in your \$PATH"
ExecTime
exit 1
fi
fi fi
} }
GetOptions() { GetOptions() {
# https://stackoverflow.com/a/29754866 # https://stackoverflow.com/a/29754866
OPTIONS=s:d:t:v::h OPTIONS=s:d:t:cv::h
LONGOPTS=source:,dest:,temp:,verbose::,help LONGOPTS=source:,dest:,temp:,convert,verbose::,help
# -use ! and PIPESTATUS to get exit code with errexit set # -use ! and PIPESTATUS to get exit code with errexit set
# -temporarily store output to be able to check for errors # -temporarily store output to be able to check for errors
@ -78,6 +84,10 @@ GetOptions() {
temp="$2" temp="$2"
shift 2 shift 2
;; ;;
-c|--convert)
convert=true
shift
;;
--) --)
shift shift
break break
@ -114,6 +124,7 @@ Usage() {
echo " -s, --source <source> The source folder of the music" echo " -s, --source <source> The source folder of the music"
echo " -d, --dest <destination> The destionation folder of the music" echo " -d, --dest <destination> The destionation folder of the music"
echo " -t, --temp <folder> The temporary cache for converted files (default: /tmp/converted)" echo " -t, --temp <folder> The temporary cache for converted files (default: /tmp/converted)"
echo " -c, --convert Convert files before syncing"
echo " -v, --verbose <0-6> Set log level (default: 2)" echo " -v, --verbose <0-6> Set log level (default: 2)"
echo " -h, --help Display this help text" echo " -h, --help Display this help text"
echo "" echo ""
@ -281,8 +292,9 @@ ExitHandler() {
trap 'ExitHandler' SIGINT trap 'ExitHandler' SIGINT
trap 'ErrorHandler $BASH_COMMAND' ERR trap 'ErrorHandler $BASH_COMMAND' ERR
CheckDeps CheckDeps 0
GetOptions $@ GetOptions $@
CheckDeps 1
if [[ $help == true ]]; then if [[ $help == true ]]; then
Usage Usage
exit exit
@ -296,7 +308,14 @@ if [[ ! -f /tmp/music-sync-filelist ]]; then
CleanUp CleanUp
exit 0 exit 0
fi fi
ConvertFiles if [[ $convert == true ]]; then
ConvertFiles
else
if [[ $temp != "/tmp/converted" ]]; then
VerboseOutput 2 "Conversion not enabled. Ignoring cache folder"
fi
temp=$source
fi
CopyFiles CopyFiles
CleanUp CleanUp
ExecTime ExecTime