From 4aee64d3fe588188da1d493fc6d5283f27cf2869 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Sat, 1 Dec 2018 18:40:13 +0100 Subject: [PATCH] Added posibility to not convert --- README.MD | 1 + music-sync.sh | 57 ++++++++++++++++++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/README.MD b/README.MD index 8dce52a..5e00777 100644 --- a/README.MD +++ b/README.MD @@ -15,6 +15,7 @@ Options: -s, --source The source folder of the music -d, --dest The destionation folder of the music -t, --temp The temporary cache for converted files (default: /tmp/converted) + -c, --convert Convert files before syncing -v, --verbose <0-6> Set log level (default: 2) -h, --help Display this help text diff --git a/music-sync.sh b/music-sync.sh index 459e4dc..cc804aa 100755 --- a/music-sync.sh +++ b/music-sync.sh @@ -5,36 +5,42 @@ begin=$(date +"%s") set -o errexit -o pipefail -o noclobber -o nounset source="-" dest="-" +convert=false verbose=2 help=false temp="/tmp/converted" CheckDeps() { - # Check getopt - ! getopt --test > /dev/null - if [[ ${PIPESTATUS[0]} -ne 4 ]]; then - 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 + if [[ $1 == 0 ]]; then + # Check getopt + ! getopt --test > /dev/null + if [[ ${PIPESTATUS[0]} -ne 4 ]]; then + 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 fi - # Check lame - if [[ ! $(lame --version 2>/dev/null) ]]; then - VerboseOutput 5 "\`lame --version\` failed" - VerboseOutput 5 "Sorry, It seems that lame is not installed on your system" - VerboseOutput 5 "Please install lame from your repositories and make sure it is available in your \$PATH" - ExecTime - exit 1 + if [[ $1 == 1 ]]; then + # Check lame + echo $convert + if [[ $convert == true && ! $(lamek --version 2>/dev/null) ]]; then + VerboseOutput 5 "\`lame --version\` failed" + VerboseOutput 5 "Sorry, It seems that lame is not installed on your system" + VerboseOutput 5 "Please install lame from your repositories and make sure it is available in your \$PATH" + ExecTime + exit 1 + fi fi } GetOptions() { # https://stackoverflow.com/a/29754866 - OPTIONS=s:d:t:v::h - LONGOPTS=source:,dest:,temp:,verbose::,help + OPTIONS=s:d:t:cv::h + LONGOPTS=source:,dest:,temp:,convert,verbose::,help # -use ! and PIPESTATUS to get exit code with errexit set # -temporarily store output to be able to check for errors @@ -78,6 +84,10 @@ GetOptions() { temp="$2" shift 2 ;; + -c|--convert) + convert=true + shift + ;; --) shift break @@ -114,6 +124,7 @@ Usage() { echo " -s, --source The source folder of the music" echo " -d, --dest The destionation folder of the music" echo " -t, --temp 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 " -h, --help Display this help text" echo "" @@ -281,8 +292,9 @@ ExitHandler() { trap 'ExitHandler' SIGINT trap 'ErrorHandler $BASH_COMMAND' ERR -CheckDeps +CheckDeps 0 GetOptions $@ +CheckDeps 1 if [[ $help == true ]]; then Usage exit @@ -296,7 +308,14 @@ if [[ ! -f /tmp/music-sync-filelist ]]; then CleanUp exit 0 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 CleanUp ExecTime