USE Const Vars

- Highlight Const. (UPERCASE)
 - Add dumy md5 export fucntions
This commit is contained in:
6543 2019-02-08 00:15:44 +01:00
parent e3298b9272
commit f898d4b5c1

View File

@ -15,14 +15,18 @@
# [$3]: <path to movie folder>

{ #set enviroemnt
true=1 #like <stdbool.h>
false=0 #like <stdbool.h>
globalconf="/etc/tt/global"
readonly TRUE=1 #like <stdbool.h>
readonly FALSE=0 #like <stdbool.h>
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 <F-ID> -> <Path>
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