-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHatH_sync.sh
81 lines (70 loc) · 1.96 KB
/
HatH_sync.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
remoteHost="US_HentaiAtHome_ByteVirt_47323"
if [ ! -s filelist.txt ]
then
rm -rvf filelist.txt incorrectfilelist.txt
cd cache || exit
find ./ -type d -empty -delete
find ./ -type d -empty -delete
for dir1 in *
do
for dir2 in "$dir1"/*
do
for filedir in "$dir2"/*
do
filename=$(basename "$filedir")
filesha=$(echo "$filename" | awk -F '-' '{print $1}')
shasum=$(sha1sum "./$filedir" | awk '{print $1}')
if [ "$shasum" == "$filesha" ]
then
echo "$filedir" >> ../filelist.txt
else
echo "$filedir" >> ../incorrectfilelist.txt
echo "$filedir is bad"
fi
done
done
done
cd ../
fi
while true
do
start=$(date +%s)
ssh "$remoteHost" "
mkdir -p cache
cd cache
find ./ -type d -empty -delete
find ./ -type d -empty -delete
for dir1 in *
do
for dir2 in \"\$dir1\"/*
do
for filedir in \"\$dir2\"/*
do
filename=\$(basename \"\$filedir\")
filesha=\$(echo \"\$filename\" | awk -F '-' '{print \$1}')
shasum=\$(sha1sum \"./\$filedir\" | awk '{print \$1}')
if [ \"\$shasum\" == \"\$filesha\" ]
then
echo \"\$filedir\"
else
rm -rf \"\$filedir\"
fi
done
done
done
" > remotefilelist.txt
rm -rvf needupload.txt
cat filelist.txt remotefilelist.txt remotefilelist.txt | sort | uniq -u > needupload.txt
if [ ! -s needupload.txt ]
then
break
fi
tar c -T needupload.txt | ssh "$remoteHost" "cd cache && tar xv"
loopend=$(date +%s)
if [ $((loopend - start)) -lt 600 ]
then
echo "sleeping"
sleep $((600 - loopend + start))
fi
done