From 0d2a94546f97a9e9c94472f85db7ee904570ac12 Mon Sep 17 00:00:00 2001 From: 6543 Date: Fri, 8 Feb 2019 18:51:30 +0100 Subject: [PATCH] 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 --- tools/db/import-md5-list | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tools/db/import-md5-list b/tools/db/import-md5-list index 1216e89..b95adce 100755 --- a/tools/db/import-md5-list +++ b/tools/db/import-md5-list @@ -26,7 +26,7 @@ { #get options & args readonly mode=$(echo $1 | tr -d '-') - readonly md5="$2" + readonly md5list="$2" moviedir="$3" } @@ -45,9 +45,9 @@ function help() { echo " modes:" echo " -a add files of md5-file to db" echo " -r remove files of md5-file from db" - echo " -d mark files from md5-file ad deleted" + echo " -d mark files from md5-file ad deleted" echo " -ee export md5 of existing files" - echo " -ed export md5 of deleted fiels" + echo " -ed export md5 of deleted fiels" echo "" echo " moviedir: Is optional if it is already in the global config" @@ -56,8 +56,8 @@ function help() { [ "$mode" == "help" ] && help ##check & prepair args -[ "${mode:0:1}" == "e" ] && touch "$md5" -[ -f "$md5" ] || { echo "md5 \"$md5\" do not exist"; exit 1; } # check md5 +[ "${mode:0:1}" == "e" ] && touch "$md5list" +[ -f "$md5list" ] || { echo "md5list \"$md5list\" do not exist"; exit 1; } # check md5 [ -z "$moviedir" ] && [ -f "$globalconf" ] && { # if (no argument) and (globalconf exist) 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' @@ -72,22 +72,24 @@ moviedir=""$(echo $moviedir | sed 's|/$||g')"" ## functions 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 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 name=$(echo $relrevpath | cut -d '/' -f 1 | 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: ";'()" - } + else + db_query "UPDATE File SET TTSync=$TTSYNC_EXIST WHERE MD5='$md5' AND Folder='$folder' AND Name='$name';" + fi done exit 0 } 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 path=$(echo $line | cut -c 33- | sed 's/^\ //g') 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() { - 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 path=$(echo $line | cut -c 33- | sed 's/^\ //g') 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() { - 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 } 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 }