From f898d4b5c19337835880b1531074c730f98ad054 Mon Sep 17 00:00:00 2001 From: 6543 Date: Fri, 8 Feb 2019 00:15:44 +0100 Subject: [PATCH] USE Const Vars - Highlight Const. (UPERCASE) - Add dumy md5 export fucntions --- tools/db/import-md5-list | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/tools/db/import-md5-list b/tools/db/import-md5-list index 100ae01..243bdfb 100755 --- a/tools/db/import-md5-list +++ b/tools/db/import-md5-list @@ -15,14 +15,18 @@ # [$3]: { #set enviroemnt - true=1 #like - false=0 #like - globalconf="/etc/tt/global" + readonly TRUE=1 #like + readonly FALSE=0 #like + readonly TTSYNC_EXIST=0 + readonly TTSYNC_BACKUP=1 + readonly TTSYNC_REMOTE=2 + readonly TTSYNC_DEL=3 + readonly globalconf="/etc/tt/global" } { #get options & args - mode=$(echo $1 | tr -d '-') - md5="$2" + readonly mode=$(echo $1 | tr -d '-') + readonly md5="$2" moviedir="$3" } @@ -52,6 +56,7 @@ function help() { if [ "$mode" == "help" ] && help ##check & prepair args +[ ${mode:0:1} == "e" ] && touch "$md5" [ -f "$md5" ] || { echo "md5 \"$md5\" 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) @@ -73,7 +78,7 @@ function md5_in_add() { relrevpath=$(echo $path | sed "s|^$moviedir||g" | sed 's|^/||g' | sed 's|/$||g' | rev) name=$(echo $relrevpath | cut -d '/' -f 1 | rev) folder=$(echo $relrevpath | cut -d '/' -f 2- | rev) - db_query "INSERT INTO File (MD5, Folder, Name) VALUES ('$md5', '$folder', '$name' );" #-> handle in future: ";'()" + db_query "INSERT INTO File (MD5, Folder, Name, TTSync) VALUES ('$md5', '$folder', '$name', $TTSYNC_EXIST );" #-> handle in future: ";'()" done exit 0 @@ -88,10 +93,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;" exit 0 } function md5_out_del() { + db_query "SELECT CONCAT(MD5, ' ', ' ' ,'$moviedir/', Folder, '/', Name) FROM File WHERE TTSync=$TTSYNC_DEL;" exit 0 } @@ -112,19 +119,16 @@ function db_exist_md5() { result=($(db_query "SELECT COUNT(md5) FROM File WHERE File.MD5 LIKE '$1';")) if [ "${result[2]}" -gt "0" ]; then echo true - return $true + return $TRUE else echo false - return $false + return $FALSE fi } # db_F-ID_getPath -> function db_id_getPath() { - local ID=$1 - local Folder=$(db_query "SELECT Folder FROM File WHERE ID=$ID;") - local Name=$(db_query "SELECT Name FROM File WHERE ID=$ID;") - echo "$moviedir/$Folder/$Name" + db_query "SELECT CONCAT('$moviedir/', Folder, '/', Name) FROM File WHERE ID=$1;" } case "$mode" in