From 5681f6a5943548c31658363bfb7d72285ddefdad Mon Sep 17 00:00:00 2001
From: Bastian Dehn
Date: Tue, 17 Jan 2017 21:41:00 +0100
Subject: [PATCH] change: bash conventionen
syntax better read
remove: file extensions
---
Makefile | 12 ++++----
albentohandy.sh => albentohandy | 54 ++++++++++++---------------------
flactomp3v2.sh => flactomp3v2 | 6 ++--
notify.sh | 6 ++--
4 files changed, 29 insertions(+), 49 deletions(-)
rename albentohandy.sh => albentohandy (83%)
rename flactomp3v2.sh => flactomp3v2 (95%)
diff --git a/Makefile b/Makefile
index de646e5..8fe9b70 100644
--- a/Makefile
+++ b/Makefile
@@ -2,10 +2,10 @@ MANPATH=/usr/share/man/de/man1
BINPATH=/usr/bin
install:
- cp albentohandy.sh $(BINPATH)/albentohandy.sh
- chmod 755 $(BINPATH)/albentohandy.sh
- cp flactomp3v2.sh $(BINPATH)/flactomp3v2.sh
- chmod 755 $(BINPATH)/flactomp3v2.sh
+ cp albentohandy $(BINPATH)/albentohandy
+ chmod 755 $(BINPATH)/albentohandy
+ cp flactomp3v2 $(BINPATH)/flactomp3v2
+ chmod 755 $(BINPATH)/flactomp3v2
cp man/albentohandy.1 $(MANPATH)/albentohandy.1
cp notify.sh $(BINPATH)/notify.sh
chmod 755 $(BINPATH)/notify.sh
@@ -15,8 +15,8 @@ install:
cp man/flactomp3v2.conf.1 $(MANPATH)/flactomp3v2.conf.1
gzip $(MANPATH)/flactomp3v2.conf.1
uninstall:
- rm $(BINPATH)/albentohandy.sh
- rm $(BINPATH)/flactomp3v2.sh
+ rm $(BINPATH)/albentohandy
+ rm $(BINPATH)/flactomp3v2
rm $(BINPATH)/notify.sh
rm $(MANPATH)/albentohandy.1.gz
rm $(MANPATH)/albentohandy.conf.1.gz
diff --git a/albentohandy.sh b/albentohandy
similarity index 83%
rename from albentohandy.sh
rename to albentohandy
index 245a031..98d8fd3 100755
--- a/albentohandy.sh
+++ b/albentohandy
@@ -1,27 +1,24 @@
#!/bin/bash
work="$(pwd)/work.$$" # temporary working directory
-scriptpath="/usr/bin" # path to flactomp3v2.sh and notify.sh script
+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
+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.sh: convert flac's to mp3
-if [ ! -f $scriptpath/flactomp3v2.sh ]
-then
- printf "\nERROR\nflactomp3v2.sh do not found in %s\n" $scriptpath
+# 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
+if [ ! -f $scriptpath/notify.sh ]; then
printf "\nERROR\nnotify.sh do not found in %s\n" $scriptpath
exit 1
else
@@ -41,14 +38,12 @@ 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
+if [ -f $HOME/.flactomp3v2.conf ]; then
BASEFILE="--basefile $HOME/.flactomp3v2.conf --cleanup"
fi
# read parameters
-while getopts ":ci:m:S::rw:z:" optname
-do
+while getopts ":ci:m:S::rw:z:" optname; do
case "$optname" in
"c")
checksum=true
@@ -80,15 +75,13 @@ do
done
# check albumlist is set
-if [ ! -f "$albumlist" ]
-then
+if [ ! -f "$albumlist" ]; then
printf "\nalbumlist does not exists\n\n"
exit
fi
# create working directory
-if [ ! -d $work ]
-then
+if [ ! -d $work ]; then
mkdir $work
fi
@@ -100,8 +93,7 @@ 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
+for i in $(cat "$albumlist"); do
cp --recursive --symbolic-link $musicpath/$i $work/
done
@@ -111,7 +103,7 @@ 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 --eta --progress --noswap --sshlogin $parallelopts $scriptpath/flactomp3v2.sh {}
+find $work -name '*.flac' | sort | parallel $BASEFILE --eta --progress --noswap --sshlogin $parallelopts $scriptpath/flactomp3v2 {}
currentDate
addInfo "flac -> mp3 finished
"
@@ -121,8 +113,7 @@ find $work -name '*.flac' | sort | xargs rm
find $work -name 'cover*' | sort | xargs rm
# create sha256sum in working directory
-if [ $checksum == true ]
-then
+if [ $checksum == true ]; then
addInfo ""
currentDate
addInfo "create sha256sum is start
"
@@ -134,11 +125,9 @@ fi
# make zipfile in the current path
# content of zipfile is content of working directory
-if [ $mkzip == true ]
-then
+if [ $mkzip == true ]; then
printf "Phase %02d of %02d: create %s\n" $((curphase++)) $phase $zipname
- if [[ ! $zipname =~ .zip ]]
- then
+ if [[ ! $zipname =~ .zip ]]; then
zipname="${zipname}.zip"
fi
addInfo "
"
@@ -154,24 +143,19 @@ then
fi
# copy work directory to destination folder
-if [ $cptodest == true ]
-then
+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
"
- if [ ! -d $dest ]
- then
- mkdir --parents $dest
- fi
- cp -r $work/* $dest
+ 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
+if ( [ $mkzip == true ] || [ $cptodest == true ] ) && [ $removework == true ]; then
printf "cleanup working directory\n\n"
rm --recursive $work
fi
diff --git a/flactomp3v2.sh b/flactomp3v2
similarity index 95%
rename from flactomp3v2.sh
rename to flactomp3v2
index f16c721..5dd73c5 100755
--- a/flactomp3v2.sh
+++ b/flactomp3v2
@@ -6,8 +6,7 @@ MODE="j"
# check config exists
# config .flactomp3v2.conf can set BITRATE and MODE
-if [ -f $HOME/.flactomp3v2.conf ]
-then
+if [ -f $HOME/.flactomp3v2.conf ]; then
source $HOME/.flactomp3v2.conf
fi
@@ -36,8 +35,7 @@ eyed3Command="eyeD3 --v2 --to-v2.3 \
--set-user-text-frame=\"REPLAYGAIN_TRACK_PEAK:$RTP\" \
--set-user-text-frame=\"REPLAYGAIN_ALBUM_GAIN:$RAG\" \
--set-user-text-frame=\"REPLAYGAIN_ALBUM_PEAK:$RAP\""
-if [ -f ${INPUTFILE%/*}/cover.jpg ]
-then
+if [ -f ${INPUTFILE%/*}/cover.jpg ]; then
eyed3Command+=" --add-image=\"${INPUTFILE%/*}/cover.jpg\":FRONT_COVER"
fi
eyed3Command+=" --no-tagging-time-frame \
diff --git a/notify.sh b/notify.sh
index fefbe15..aab8d13 100755
--- a/notify.sh
+++ b/notify.sh
@@ -7,8 +7,7 @@ MESSAGE=""
# load all parameters to sendemail over smtp
# NOTIFY; FROMADDRESS; TOADDRESS; STMP; SMPTUSERNAME; SMTPPASSWORD(base64)
-if [ ! -f $HOME/.albentohandy.conf ]
-then
+if [ ! -f $HOME/.albentohandy.conf ]; then
printf "\nERROR\n.albentohandy.conf does not exist\n"
exit 1
else
@@ -18,8 +17,7 @@ fi
# send email to notify user
sendEmail()
{
-if [ $NOTIFY == true ]
-then
+if [ $NOTIFY == true ]; then
sendemail -f $FROMADDRESS -t $TOADDRESS \
-s $SMTP -xu $SMTPUSERNAME -xp $(echo $SMTPPASSWORD | base64 --decode) -o tls=yes \
-u "albentohandy" -o message-content-type=html -m "$MESSAGE"
--
2.47.3