tool db/import-md5-lsit: differ var md5 (list) and md5 (single hash)

+ update TTSync at add fct if entry already exist
+ repair help msg
This commit is contained in:
6543 2019-02-08 18:51:30 +01:00
parent 27f2792b10
commit 0d2a94546f

View File

@ -26,7 +26,7 @@


{ #get options & args { #get options & args
readonly mode=$(echo $1 | tr -d '-') readonly mode=$(echo $1 | tr -d '-')
readonly md5="$2" readonly md5list="$2"
moviedir="$3" moviedir="$3"
} }


@ -56,8 +56,8 @@ function help() {
[ "$mode" == "help" ] && help [ "$mode" == "help" ] && help


##check & prepair args ##check & prepair args
[ "${mode:0:1}" == "e" ] && touch "$md5" [ "${mode:0:1}" == "e" ] && touch "$md5list"
[ -f "$md5" ] || { echo "md5 \"$md5\" do not exist"; exit 1; } # check md5 [ -f "$md5list" ] || { echo "md5list \"$md5list\" do not exist"; exit 1; } # check md5
[ -z "$moviedir" ] && [ -f "$globalconf" ] && { # if (no argument) and (globalconf exist) [ -z "$moviedir" ] && [ -f "$globalconf" ] && { # if (no argument) and (globalconf exist)
if [ -z "$(grep "moviedir=" "$globalconf" )" ]; then # and (moviedir is NOT in globalconf) if [ -z "$(grep "moviedir=" "$globalconf" )" ]; then # and (moviedir is NOT in globalconf)
echo 'neither "movie folder" is set in global config nor given as argument' echo 'neither "movie folder" is set in global config nor given as argument'
@ -72,22 +72,24 @@ moviedir=""$(echo $moviedir | sed 's|/$||g')""


## functions ## functions
function md5_in_add() { function md5_in_add() {
cat $md5 | while read line; do #for each line in md5 cat $md5list | while read line; do #for each line in md5
local md5=$(echo $line | cut -c -32) local md5=$(echo $line | cut -c -32)
local path=$(echo $line | cut -c 33- | sed 's/^\ //g') local path=$(echo $line | cut -c 33- | sed 's/^\ //g')
local relrevpath=$(echo $path | sed "s|^$moviedir||g" | sed 's|^/||g' | sed 's|/$||g' | rev) local relrevpath=$(echo $path | sed "s|^$moviedir||g" | sed 's|^/||g' | sed 's|/$||g' | rev)
local name=$(echo $relrevpath | cut -d '/' -f 1 | rev) local name=$(echo $relrevpath | cut -d '/' -f 1 | rev)
local folder=$(echo $relrevpath | cut -d '/' -f 2- | rev) local folder=$(echo $relrevpath | cut -d '/' -f 2- | rev)
[ "$(db_query "SELECT COUNT(ID) FROM File WHERE MD5='$md5' AND Folder='$folder' AND Name='$name';")" == "0" ] && { #wenn KEIN gleicher Eintrag Vorhanden if [ "$(db_query "SELECT COUNT(ID) FROM File WHERE MD5='$md5' AND Folder='$folder' AND Name='$name';")" == "0" ]; then #wenn KEIN gleicher Eintrag Vorhanden
db_query "INSERT INTO File (MD5, Folder, Name, TTSync) VALUES ('$md5', '$folder', '$name', $TTSYNC_EXIST );" #-> handle in future: ";'()" db_query "INSERT INTO File (MD5, Folder, Name, TTSync) VALUES ('$md5', '$folder', '$name', $TTSYNC_EXIST );" #-> handle in future: ";'()"
} else
db_query "UPDATE File SET TTSync=$TTSYNC_EXIST WHERE MD5='$md5' AND Folder='$folder' AND Name='$name';"
fi
done done


exit 0 exit 0
} }


function md5_rm() { function md5_rm() {
cat $md5 | while read line; do #for each line in md5 cat $md5list | while read line; do #for each line in md5
local md5=$(echo $line | cut -c -32) local md5=$(echo $line | cut -c -32)
local path=$(echo $line | cut -c 33- | sed 's/^\ //g') local path=$(echo $line | cut -c 33- | sed 's/^\ //g')
local relrevpath=$(echo $path | sed "s|^$moviedir||g" | sed 's|^/||g' | sed 's|/$||g' | rev) local relrevpath=$(echo $path | sed "s|^$moviedir||g" | sed 's|^/||g' | sed 's|/$||g' | rev)
@ -100,7 +102,7 @@ function md5_rm() {
} }


function md5_in_del() { function md5_in_del() {
cat $md5 | while read line; do #for each line in md5 cat $md5list | while read line; do #for each line in md5
local md5=$(echo $line | cut -c -32) local md5=$(echo $line | cut -c -32)
local path=$(echo $line | cut -c 33- | sed 's/^\ //g') local path=$(echo $line | cut -c 33- | sed 's/^\ //g')
local relrevpath=$(echo $path | sed "s|^$moviedir||g" | sed 's|^/||g' | sed 's|/$||g' | rev) local relrevpath=$(echo $path | sed "s|^$moviedir||g" | sed 's|^/||g' | sed 's|/$||g' | rev)
@ -118,12 +120,12 @@ function md5_in_del() {
} }


function md5_out_exist() { function md5_out_exist() {
db_query "SELECT CONCAT(MD5, ' ', ' ' ,'$moviedir/', Folder, '/', Name) FROM File WHERE TTSync=$TTSYNC_EXIST OR TTSync=$TTSYNC_BACKUP;" >> $md5 db_query "SELECT CONCAT(MD5, ' ', ' ' ,'$moviedir/', Folder, '/', Name) FROM File WHERE TTSync=$TTSYNC_EXIST OR TTSync=$TTSYNC_BACKUP;" >> $md5list
exit 0 exit 0
} }


function md5_out_del() { function md5_out_del() {
db_query "SELECT CONCAT(MD5, ' ', ' ' ,'$moviedir/', Folder, '/', Name) FROM File WHERE TTSync=$TTSYNC_DEL;" >> $md5 db_query "SELECT CONCAT(MD5, ' ', ' ' ,'$moviedir/', Folder, '/', Name) FROM File WHERE TTSync=$TTSYNC_DEL;" >> $md5list
exit 0 exit 0
} }