commit 8d2a28228f97de0483217e20c2f2192f29c17341 Author: 6543 <6543@obermui.de> Date: Tue Mar 5 17:40:59 2019 +0100 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2bbabee --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/transport +/.Trash-* diff --git a/2cp b/2cp new file mode 100644 index 0000000..e69de29 diff --git a/calc_md5.sh b/calc_md5.sh new file mode 100644 index 0000000..f10d5c4 --- /dev/null +++ b/calc_md5.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +cd /mnt/export + +#sort & del dublicates +sed -i '/^$/d' md5.txt +cat md5.txt | sort -k 2 | uniq > md5.txt_tmp +cat md5.txt_tmp > md5.txt + +cat md5.txt_tmp | while read line; do + #get md5 + md5=$(echo $line | cut -c -32) + + #get path of file + file=$( echo $line | cut -c 34-) + + #wenn datei existiert + if [ -f "$file" ]; then + # do nothing + echo > /dev/null + else + echo "rm $line" + sed -i "/$md5/d" md5.txt + fi + +done + +#search for new files +find /mnt/export/transport -type f | grep -v "/.Trash-" | sort | while read line; do + #save fiel path + result=$(grep "$line" md5.txt); [ -z "$result" ] && { + #wenn kein eintrag in liste... + echo "new $line" + md5sum "$line" >> md5.txt_add + } +done +[ -f md5.txt_add ] && { + cat md5.txt_add >> md5.txt + rm md5.txt_add +} + +#sort & del dublicates +cat md5.txt | sort -k 2 | uniq > md5.txt_tmp +rm md5.txt && mv md5.txt_tmp md5.txt diff --git a/cp_sh b/cp_sh new file mode 100644 index 0000000..f54cf6b --- /dev/null +++ b/cp_sh @@ -0,0 +1,58 @@ +#!/bin/bash +# @autor 6543@transport.de +# @date 2019-01-09 +# @version 0.2 + +function free_disk() { + df "$1" | grep '/dev/' | sed -r -e "s/[\t\ ]+/ /g" | cut -d ' ' -f 4 +} + +md5="2cp" +aim="/mnt/export/transport" + + +md5_tmp=`mktemp` +freenow=0 + +cat "$md5" > "$md5_tmp" +cat "$md5_tmp" | while read line; do + file_orig="$(echo $line | cut -c 33- | sed -r -e "s/^[\ ]//g")" + file_size=$(du "$file_orig" | cut -f 1) + file_md5=$(echo $line | cut -c -32) + file_aim_dir=$(echo $file_orig | rev | cut -d '/' -f 2- | rev | sed 's/data\/Filme/mnt\/export\/transport/g') + file_aim=$(echo $file_orig | sed 's/data\/Filme/mnt\/export\/transport/g') + + [ "$file_orig" == "$file_aim" ] && { echo Script ERROR; exit 255; } + + freenow=$(free_disk "$aim") + #add puffer + freenow=$((freenow-10240)) + + if [ -f "$file_orig" ]; then + + if [ "$freenow" -ge "$file_size" ]; then + + mkdir -p "$file_aim_dir" + [ -f "$file_aim" ] && rm "$file_aim" + + file_md5_new=$(cat "$file_orig" | tee "$file_aim" | md5sum | cut -c -32) + + if [ "${file_md5_new}" == "${file_md5}" ]; then + echo "$file_md5 $file_aim" >> /mnt/export/md5.txt + sed -i "/$file_md5/d" "$md5" + else + echo "Error: Hash mismatch: \"NEW:${file_md5_new} OLD:${file_md5}\" $file_aim" + sed -i "/$file_md5/d" "$md5" + fi + + else + echo "To Big: $file_md5 $file_orig" + fi + + else + echo "Error: Not Exist: $file_orig" + sed -i "/$file_md5/d" "$md5" + fi +done + +rm "$md5_tmp" diff --git a/md5.txt b/md5.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/md5.txt @@ -0,0 +1 @@ +