update diff_cp

This commit is contained in:
6543 2023-02-27 03:13:22 +01:00
parent 398ec4f3f6
commit 4cedaaf1ec

View File

@ -1,15 +1,16 @@
#!/bin/bash #!/bin/bash
# @autor 6543@obermui.de # @autor 6543@obermui.de
# @date 2019-01-09 # @date 2023-02-27
# @version 0.2 # @version 0.3


function free() { function free() {
df "$1" | grep '/dev/' | sed -r -e "s/[\t\ ]+/ /g" | cut -d ' ' -f 4 df "$1" | grep '/dev/' | sed -r -e "s/[\t\ ]+/ /g" | cut -d ' ' -f 4
} }


md5="2cp" md5="2cp"
aim="/tmp/sdl/oberoed" aim="/data/Filme"

md5_success="cp.done.md5"
md5_conflict="cp.conflict.md5"


md5_tmp=`mktemp` md5_tmp=`mktemp`
freenow=0 freenow=0
@ -19,8 +20,8 @@ cat "$md5_tmp" | while read line; do
file_orig="$(echo $line | cut -c 33- | sed -r -e "s/^[\ ]//g")" file_orig="$(echo $line | cut -c 33- | sed -r -e "s/^[\ ]//g")"
file_size=$(du "$file_orig" | cut -f 1) file_size=$(du "$file_orig" | cut -f 1)
file_md5=$(echo $line | cut -c -32) file_md5=$(echo $line | cut -c -32)
file_aim_dir=$(echo $file_orig | rev | cut -d '/' -f 2- | rev | sed 's/data\/shares\/Filme/tmp\/sdl\/oberoed/g')
file_aim=$(echo $file_orig | sed 's/data\/shares\/Filme/tmp\/sdl\/oberoed/g') file_aim=$(echo $file_orig | sed 's/data\/shares\/Filme/tmp\/sdl\/oberoed/g')
file_aim_dir=$(echo $file_aim | rev | cut -d '/' -f 2- | rev)


[ "$file_orig" == "$file_aim" ] && { echo Script ERROR; exit 255; } [ "$file_orig" == "$file_aim" ] && { echo Script ERROR; exit 255; }


@ -33,26 +34,30 @@ cat "$md5_tmp" | while read line; do
if [ "$freenow" -ge "$file_size" ]; then if [ "$freenow" -ge "$file_size" ]; then


mkdir -p "$file_aim_dir" mkdir -p "$file_aim_dir"
[ -f "$file_aim" ] && rm "$file_aim" if [ -f "${file_aim}" ]; then

echo "${file_md5} ${file_aim}" >> ${md5_conflict}
file_md5_new=$(cat "$file_orig" | tee "$file_aim" | md5sum | cut -c -32) echo "ERROR: ${file_md5} already exist, skipping"

if [ "${file_md5_new}" == "${file_md5}" ]; then
echo "$file_md5 $file_aim" >> /tmp/sdl/md5.txt
sed -i "/$file_md5/d" "$md5"
else else
echo "Error: Hash mismatch: \"NEW:${file_md5_new} OLD:${file_md5}\" $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}" >> $md5_success
sed -i "/$file_md5/d" "$md5"
else
echo "ERROR: Hash mismatch: \"NEW:${file_md5_new} OLD:${file_md5}\" $file_aim"
rm "${file_aim}"
fi
fi fi


else else
echo "To Big: $file_md5 $file_orig" echo "WARNING: To Big: ${file_orig} (${file_size}), skipping"
fi fi


else else
echo "Error: Not Exist: $file_orig" echo "ERROR: Not Exist: ${file_orig}"
sed -i "/$file_md5/d" "$md5" sed -i "/$file_md5/d" "$md5"
fi fi
done done


rm "$md5_tmp" rm "${md5_tmp}"