From d95a7ea54f9c57b0fc97c5536c07bd391e94fabd Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 7 Feb 2019 17:02:29 +0100 Subject: [PATCH] - add db_query function - add db_exist_md5 function - creat basic structure of script --- tools/db/import-md5-list | 111 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 108 insertions(+), 3 deletions(-) diff --git a/tools/db/import-md5-list b/tools/db/import-md5-list index d7b0f1f..adca8a6 100644 --- a/tools/db/import-md5-list +++ b/tools/db/import-md5-list @@ -5,10 +5,115 @@ ## Options/Parameter # $1: -# -a | add files of md5-file to db -# -r | remove files of md5-file from db -# -d | mark files from md5-file ad deleted +# -a | add files of md5-file to db +# -r | remove files of md5-file from db +# -d | mark files from md5-file ad deleted +# -ee | export md5 of existing files +# -ed | export md5 of deleted fiels # # $2: # [$3]: +mode=$(echo $1 | tr -d '-') +md5="$2" +moviedir="$3" +globalconf="/etc/tt/global" + +#db +dbname="tt_test" +dbhost="localhost" +dbuser="root" +dbpwd="" + +function help() { + #help menue + echo "$0 is part of the TerabyteTerminator Project" + echo "" + echo "import-md5-list [moviedir]" + 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 " -ee export md5 of existing files" + echo " -ed export md5 of deleted fiels" + echo "" + echo " moviedir: Is optional if it is already in the global config" + + exit 0 +} +if [ "$mode" == "help" ] && help + +##check & prepair args +[ -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) + echo 'neither "movie folder" is set in global config nor given as argument' + exit 2 + else # and (moviedir is in globalconf) + moviedir="$(grep "moviedir=" "$globalconf" | cut -d '=' -f 2)" + fi +} +[ -d "$moviedir" ] || { echo "moviedir \"$moviedir\" do not exist"; exit 3; } # check moviedir + +## functions +function md5_in_add() { + exit 0 +} + +function md5_rm() { + exit 0 +} + +function md5_in_del() { + exit 0 +} + +function md5_out_exist() { + exit 0 +} + +function md5_out_del() { + exit 0 +} + +# help functions + +# db_query -> result +function db_query() { + echo $@ | mysql -h$dbhost -u$dbuser -p$dbpwd $dbname +} + +# db_exist_md5 -> true/false 0/1 +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 0 + else + echo false + return 1 + fi +} + +case "$mode" in + "a") #in_add + md5_in_add + ;; + "r") #rm + md5_rm + ;; + "d") + md5_in_del + ;; + "ee" | "e" ) + md5_out_exist + ;; + "ed" ) + md5_out_exist + ;; + *) + echo "wrong arguments" + echo "" + help + ;; +esac \ No newline at end of file