From: Bastian Dehn Date: Sun, 16 Jul 2017 14:00:15 +0000 (+0200) Subject: change: all to main method X-Git-Tag: v1.0.0^2~101 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=b9e219f741587d5d5f02a78f10b4a79d59baba57;p=albentohandy.git change: all to main method --- diff --git a/albentohandy b/albentohandy index 86d56c9..c97772c 100755 --- a/albentohandy +++ b/albentohandy @@ -4,170 +4,174 @@ ### 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 "

" -currentDate -addInfo "albentohandy.sh is started

" -addInfo "

Foldende Alben wurden ausgewählt:

" -addInfo "

$(cat "$albumlist" | sed 's/$/
/')

" -# 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 "

" -currentDate -addInfo "flac -> mp3 start
" -# 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 -> mp3 finished

" - -# 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 "

" currentDate - addInfo "create sha256sum is start
" - 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

" -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

" + addInfo "

Foldende Alben wurden ausgewählt:

" + addInfo "

$(cat "$albumlist" | sed 's/$/
/')

" + # 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 "

" currentDate - addInfo "create $zipname start
" - curpath=$(pwd) - cd $WORK - 7z a -bd -mmt=off -mm=Copy $curpath/$zipname . - cd $curpath - printf "\n" + addInfo "flac -> mp3 start
" + # 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

" -fi + addInfo "flac -> mp3 finished

" + + # 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 "

" + currentDate + addInfo "create sha256sum is start
" + 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

" + 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 "

" + currentDate + addInfo "create $zipname start
" + curpath=$(pwd) + cd $WORK + 7z a -bd -mmt=off -mm=Copy $curpath/$zipname . + cd $curpath + printf "\n" + currentDate + addInfo "$zipname is created

" + 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 "

" + currentDate + addInfo "copy from $WORK to $dest start
" + mkdir --parents $dest + cp --recursive $WORK/* $dest + currentDate + addInfo "copy from $WORK to $dest finished

" + 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 "

" currentDate - addInfo "copy from $WORK to $dest start
" - mkdir --parents $dest - cp --recursive $WORK/* $dest - currentDate - addInfo "copy from $WORK to $dest finished

" -fi - -# delete the working directory -if ( [ $mkzip == true ] || [ $cptodest == true ] ) && [ $removework == true ]; then - printf "cleanup working directory\n\n" - rm --recursive $WORK -fi - -addInfo "

" -currentDate -addInfo "send email

" -closeMail -sendEmail + addInfo "send email

" + closeMail + sendEmail +} + +main $* exit 0