From 2dc2ba05cd4e93cecde8776ab6d86d25ed2b5ddf Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 10 May 2019 18:56:56 +0200 Subject: [PATCH] WIP ... --- tools/db/update-file-state | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/tools/db/update-file-state b/tools/db/update-file-state index 6d4fec2..f2c87c9 100644 --- a/tools/db/update-file-state +++ b/tools/db/update-file-state @@ -9,16 +9,28 @@ { #set enviroemnt 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 TTSYNC_EXIST=0 #file exist local + readonly TTSYNC_BACKUP=1 #file exist local - backup exist + readonly TTSYNC_REMOTE=2 #file exists remote - not used jet + readonly TTSYNC_DEL=3 #local file deleted readonly globalconf="/etc/tt/global" } { #get options & args readonly mode=$(echo $1 | tr -d '-') moviedir="$1" + [ -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 + moviedir=""$(echo $moviedir | sed 's|/$||g')"" + [ -z "$moviedir" ] && exit 255 #catch case moviedir="/" + readonly DATE=$(date '+%Y-%m-%d') } { #db @@ -46,6 +58,17 @@ function main() { #cd to moviedir cd "$moviedir" + #erselle zwei dateilisten + list_tmp=$(mktemp -d) + db_query "SELECT CONCAT('$moviedir/', Folder, '/', Name) FROM File WHERE TTSync=$TTSYNC_EXIST OR TTSync=$TTSYNC_BACKUP;" > "$list_tmp/indb" + find "$moviedir" -type f > "$list_tmp/exist" + + #find new files + grep -vf "$list_tmp/indb" "$list_tmp/exist" > "$list_tmp/new" + + #all IDs wich an old check date: + #db_query "SELECT ID FROM File Where TTCheck < '$DATE' OR TTCheck IS NULL;" + ## dateiliste erstellen die mit DB abgeglichen wird ## alle die keien DB.PATH eintrag haben -> file_add @@ -110,7 +133,11 @@ function md5_out_del() { # file_size -> (du -b)/1024 [Kb] function file_size() { - echo $(($(du -b "$1" | cut -f 1)/1024)) + if [ -f "$1" ]; then + echo $(($(du -b "$1" | cut -f 1)/1024)) + else + echo 0 + fi } # db_query -> result