]> gitweb.hhaalo.de Git - albentohandy.git/commitdiff
change: all to main method
authorBastian Dehn <hhaalo@arcor.de>
Sun, 16 Jul 2017 14:00:15 +0000 (16:00 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 16 Jul 2017 14:00:15 +0000 (16:00 +0200)
albentohandy

index 86d56c9a75f51db146a138cf74824ed8d56e06e5..c97772c7fbdb29dc7d13abaf1ca603dd3d743db5 100755 (executable)
 ### copy to other folder. It works on parallel, you can
 ### use it in a cluster with Parameter -S.
 
-WORK="$(pwd)/work.$$" # temporary working directory
-SCRIPTPATH="/usr/bin" # path to flactomp3v2 and notify.sh script
-MUSICPATH="/tmp/musikpath" # flac collection directory
-
-# check exist config and scripts
-# .albentohandy.conf: set SCRIPTPATH and MUSICPATH
-if [ -f $HOME/.albentohandy.conf ]; then
-       source $HOME/.albentohandy.conf
-else
-       printf "\nERROR\n%s/.albentohandy.conf does not exists\n" $HOME
-       exit 1
-fi
-# flactomp3v2: convert flac's to mp3
-if [ ! -f $SCRIPTPATH/flactomp3v2 ]; then
-       printf "\nERROR\nflactomp3v2 do not found in %s\n" $SCRIPTPATH
-       exit 1
-fi
-# notify.sh: functions send email
-if [ ! -f $SCRIPTPATH/notify.sh ]; then
-       printf "\nERROR\nnotify.sh do not found in %s\n" $SCRIPTPATH
-       exit 1
-else
-       source $SCRIPTPATH/notify.sh
-fi
-
-# set defaults
-albumlist="albumlist"
-parallelopts=":"
-curphase=1
-phase=3
-checksum=false
-mkzip=false
-removework=false
-cptodest=false
-
-# in cluster you have to same bitrate and
-# stereo mode of mp3's on every pc.
-# read more about basefile in man parallel
-if [ -f $HOME/.flactomp3v2.conf ]; then
-       BASEFILE="--basefile $HOME/.flactomp3v2.conf --cleanup"
-fi
-
-# read parameters
-while getopts ":ci:m:S::rw:z:" optname; do
-       case "$optname" in
-       "c")
-               checksum=true
-               ((phase++))
-               ;;
-       "i")
-               albumlist="$OPTARG"
-               ;;
-       "m")
-               cptodest=true
-               dest="$OPTARG"
-               ((phase++))
-               ;;
-       "S")
-               parallelopts="$OPTARG"
-               ;;
-       "r")
-               removework=true
-               ;;
-       "w")
-               WORK="$OPTARG"
-               ;;
-       "z")
-               mkzip=true
-               zipname="$OPTARG"
-               ((phase++))
-               ;;
-       esac
-done
-
-# check albumlist is set
-if [ ! -f "$albumlist" ]; then
-       printf "\nalbumlist does not exists\n\n"
-       exit
-fi
-
-# create working directory
-if [ ! -d $WORK ]; then
-       mkdir $WORK
-fi
-
-openMail
-addInfo "<p>"
-currentDate
-addInfo "albentohandy.sh is started</p>"
-addInfo "<p>Foldende Alben wurden ausgew&auml;hlt:</p>"
-addInfo "<p>$(cat "$albumlist" | sed 's/$/<br>/')</p>"
-# make symlinks of original flac's in working directory
-printf "\nPhase %02d of %02d: create symlinks of flac's to working directory %s\n" $((curphase++)) $phase "$WORK"
-for i in $(cat "$albumlist"); do
-       cp --recursive --symbolic-link $MUSICPATH/$i $WORK/
-done
-
-addInfo "<p>"
-currentDate
-addInfo "flac -&gt; mp3 start<br>"
-# convert flac to mp3
-# it is the longest phase
-printf "\nPhase %02d of %02d: flac -> mp3\n" $((curphase++)) $phase
-find $WORK -name '*.flac' | sort | parallel $BASEFILE --will-cite --ungroup --eta --progress --sshlogin $parallelopts $SCRIPTPATH/flactomp3v2 {}
-currentDate
-addInfo "flac -&gt; mp3 finished</p>"
-
-# removing flac and cover.jpg
-printf "\nPhase %02d of %02d: remove flac's and cover's\n\n" $((curphase++)) $phase
-find $WORK -name '*.flac' | sort | xargs rm
-find $WORK -name 'cover*' | sort | xargs rm
-
-# create sha256sum in working directory
-if [ $checksum == true ]; then
+main() {
+       WORK="$(pwd)/work.$$" # temporary working directory
+       SCRIPTPATH="/usr/bin" # path to flactomp3v2 and notify.sh script
+       MUSICPATH="/tmp/musikpath" # flac collection directory
+
+       # check exist config and scripts
+       # .albentohandy.conf: set SCRIPTPATH and MUSICPATH
+       if [ -f $HOME/.albentohandy.conf ]; then
+               source $HOME/.albentohandy.conf
+       else
+               printf "\nERROR\n%s/.albentohandy.conf does not exists\n" $HOME
+               exit 1
+       fi
+       # flactomp3v2: convert flac's to mp3
+       if [ ! -f $SCRIPTPATH/flactomp3v2 ]; then
+               printf "\nERROR\nflactomp3v2 do not found in %s\n" $SCRIPTPATH
+               exit 1
+       fi
+       # notify.sh: functions send email
+       if [ ! -f $SCRIPTPATH/notify.sh ]; then
+               printf "\nERROR\nnotify.sh do not found in %s\n" $SCRIPTPATH
+               exit 1
+       else
+               source $SCRIPTPATH/notify.sh
+       fi
+
+       # set defaults
+       albumlist="albumlist"
+       parallelopts=":"
+       curphase=1
+       phase=3
+       checksum=false
+       mkzip=false
+       removework=false
+       cptodest=false
+
+       # in cluster you have to same bitrate and
+       # stereo mode of mp3's on every pc.
+       # read more about basefile in man parallel
+       if [ -f $HOME/.flactomp3v2.conf ]; then
+               BASEFILE="--basefile $HOME/.flactomp3v2.conf --cleanup"
+       fi
+
+       # read parameters
+       while getopts ":ci:m:S::rw:z:" optname; do
+               case "$optname" in
+               "c")
+                       checksum=true
+                       ((phase++))
+                       ;;
+               "i")
+                       albumlist="$OPTARG"
+                       ;;
+               "m")
+                       cptodest=true
+                       dest="$OPTARG"
+                       ((phase++))
+                       ;;
+               "S")
+                       parallelopts="$OPTARG"
+                       ;;
+               "r")
+                       removework=true
+                       ;;
+               "w")
+                       WORK="$OPTARG"
+                       ;;
+               "z")
+                       mkzip=true
+                       zipname="$OPTARG"
+                       ((phase++))
+                       ;;
+               esac
+       done
+
+       # check albumlist is set
+       if [ ! -f "$albumlist" ]; then
+               printf "\nalbumlist does not exists\n\n"
+               exit
+       fi
+
+       # create working directory
+       if [ ! -d $WORK ]; then
+               mkdir $WORK
+       fi
+
+       openMail
        addInfo "<p>"
        currentDate
-       addInfo "create sha256sum is start<br>"
-       printf "Phase %02d of %02d: create sha256sum\n\n" $((curphase++)) $phase
-       find $WORK -name '*.mp3' | sort | xargs sha256sum | sed "s=$WORK/==" >> $WORK/sha256sum
-       currentDate
-       addInfo "sha256sum is created</p>"
-fi
-
-# make zipfile in the current path
-# content of zipfile is content of working directory
-if [ $mkzip == true ]; then
-       printf "Phase %02d of %02d: create %s\n" $((curphase++)) $phase $zipname
-       if [[ ! $zipname =~ .zip ]]; then
-               zipname="${zipname}.zip"
-       fi
+       addInfo "albentohandy.sh is started</p>"
+       addInfo "<p>Foldende Alben wurden ausgew&auml;hlt:</p>"
+       addInfo "<p>$(cat "$albumlist" | sed 's/$/<br>/')</p>"
+       # make symlinks of original flac's in working directory
+       printf "\nPhase %02d of %02d: create symlinks of flac's to working directory %s\n" $((curphase++)) $phase "$WORK"
+       for i in $(cat "$albumlist"); do
+               cp --recursive --symbolic-link $MUSICPATH/$i $WORK/
+       done
+
        addInfo "<p>"
        currentDate
-       addInfo "create $zipname start<br>"
-       curpath=$(pwd)
-       cd $WORK
-       7z a -bd -mmt=off -mm=Copy $curpath/$zipname .
-       cd $curpath
-       printf "\n"
+       addInfo "flac -&gt; mp3 start<br>"
+       # convert flac to mp3
+       # it is the longest phase
+       printf "\nPhase %02d of %02d: flac -> mp3\n" $((curphase++)) $phase
+       find $WORK -name '*.flac' | sort | parallel $BASEFILE --will-cite --ungroup --eta --progress --sshlogin $parallelopts $SCRIPTPATH/flactomp3v2 {}
        currentDate
-       addInfo "$zipname is created</p>"
-fi
+       addInfo "flac -&gt; mp3 finished</p>"
+
+       # removing flac and cover.jpg
+       printf "\nPhase %02d of %02d: remove flac's and cover's\n\n" $((curphase++)) $phase
+       find $WORK -name '*.flac' | sort | xargs rm
+       find $WORK -name 'cover*' | sort | xargs rm
+
+       # create sha256sum in working directory
+       if [ $checksum == true ]; then
+               addInfo "<p>"
+               currentDate
+               addInfo "create sha256sum is start<br>"
+               printf "Phase %02d of %02d: create sha256sum\n\n" $((curphase++)) $phase
+               find $WORK -name '*.mp3' | sort | xargs sha256sum | sed "s=$WORK/==" >> $WORK/sha256sum
+               currentDate
+               addInfo "sha256sum is created</p>"
+       fi
+
+       # make zipfile in the current path
+       # content of zipfile is content of working directory
+       if [ $mkzip == true ]; then
+               printf "Phase %02d of %02d: create %s\n" $((curphase++)) $phase $zipname
+               if [[ ! $zipname =~ .zip ]]; then
+                       zipname="${zipname}.zip"
+               fi
+               addInfo "<p>"
+               currentDate
+               addInfo "create $zipname start<br>"
+               curpath=$(pwd)
+               cd $WORK
+               7z a -bd -mmt=off -mm=Copy $curpath/$zipname .
+               cd $curpath
+               printf "\n"
+               currentDate
+               addInfo "$zipname is created</p>"
+       fi
+
+       # copy work directory to destination folder
+       if [ $cptodest == true ]; then
+               printf "Phase %02d of %02d: copy %s/ to destination %s\n\n" $((curphase++)) $phase $WORK $dest
+               addInfo "<p>"
+               currentDate
+               addInfo "copy from $WORK to $dest start<br>"
+               mkdir --parents $dest
+               cp --recursive $WORK/* $dest
+               currentDate
+               addInfo "copy from $WORK to $dest finished</p>"
+       fi
+
+       # delete the working directory
+       if ( [ $mkzip == true ] || [ $cptodest == true ] ) && [ $removework == true ]; then
+               printf "cleanup working directory\n\n"
+               rm --recursive $WORK
+       fi
 
-# copy work directory to destination folder
-if [ $cptodest == true ]; then
-       printf "Phase %02d of %02d: copy %s/ to destination %s\n\n" $((curphase++)) $phase $WORK $dest
        addInfo "<p>"
        currentDate
-       addInfo "copy from $WORK to $dest start<br>"
-       mkdir --parents $dest
-       cp --recursive $WORK/* $dest
-       currentDate
-       addInfo "copy from $WORK to $dest finished</p>"
-fi
-
-# delete the working directory
-if ( [ $mkzip == true ] || [ $cptodest == true ] ) && [ $removework == true ]; then
-       printf "cleanup working directory\n\n"
-       rm --recursive $WORK
-fi
-
-addInfo "<p>"
-currentDate
-addInfo "send email</p>"
-closeMail
-sendEmail
+       addInfo "send email</p>"
+       closeMail
+       sendEmail
+}
+
+main $*
 
 exit 0