Compare commits

..

No commits in common. "71cfa14596b87cb12f4d710cf21ec59b65ddb569" and "460c7c0b3b58b516a943a08690bffd04f2ec33aa" have entirely different histories.

5 changed files with 25 additions and 34 deletions

3
.gitignore vendored
View File

@ -1,2 +1 @@
status/* status/*
config

2
config Normal file
View File

@ -0,0 +1,2 @@
putty rsync://mirrors4.tuna.tsinghua.edu.cn/putty /tmp/putty
github-raw rsync://mirrors4.tuna.tsinghua.edu.cn/github-raw /tmp/github-raw

View File

@ -1,2 +0,0 @@
putty rsync://mirrors4.tuna.tsinghua.edu.cn/putty /tmp/putty
github-raw/subfolder rsync://mirrors4.tuna.tsinghua.edu.cn/github-raw /tmp/github-raw

View File

@ -71,26 +71,27 @@
<script> <script>
$.get("index", function(data){ $.get("index", function(data){
const list = data.split('\n') list = data.split('\n')
for (i in list) { for (i in list) {
const name=list[i] name=list[i]
if (name.length == 0) { if (name.length == 0) {
continue; continue;
} }
const safe_name = name.replace(/\//g, "_"); $.get(name + ".log", function (data) {
$.get(safe_name + ".log", function (data) {
var data = data.split("\n"); var data = data.split("\n");
const line_header = data[0] =
"<td><a href='../" + name + "'>" + name + "</a></td>"; "<a href='../" + data[0] + "'>" + data[0] + "</a>";
for (j in data) { for (j in data) {
if (data[j] != "") { if (data[j] != "") {
data[j] = "<td>" + data[j] + "</td>"; data[j] = "<td>" + data[j] + "</td>";
} }
} }
$("#mirror_list").append( $("#mirror_list").append(
"<tr id='" + safe_name + "'>" + "<tr id='" +
line_header + data.join("") + name +
"</tr>" "'>" +
data.join("") +
"</tr>"
); );
console.log(data); console.log(data);
}); });

33
sync.sh
View File

@ -9,11 +9,12 @@ touch "$STATUS_INDEX"
presync() { presync() {
local name="$1" local name="$1"
local log_file="$STATUS_FOLDER"/$name.log local log_file="$STATUS_FOLDER"/$name.log
grep -qxF -- "$name" "$STATUS_INDEX" || echo "$name" >> "$STATUS_INDEX"
if [[ -f "$log_file" ]]; then if [[ -f "$log_file" ]]; then
sed -i "3c syncing..." "$log_file" sed -i "4c syncing..." "$log_file"
sed -i "2c $(date +'%Y-%m-%d %H:%M:%S')" "$log_file" sed -i "3c $(date +'%Y-%m-%d %H:%M:%S')" "$log_file"
else else
echo -e "0\n0\niniting..." > "$log_file" echo -e "${name}\n0\n0\niniting..." > "$log_file"
fi fi
} }
@ -21,43 +22,33 @@ postsync() {
local name="$1" local name="$1"
local status="$2" local status="$2"
local dst="$3" local dst="$3"
echo -e "$(du -h --max-depth=0 "$dst" | awk '{print $1}')\n$(date +'%Y-%m-%d %H:%M:%S')\n${status}" > "$STATUS_FOLDER"/$name.log echo -e "${name}\n$(du -h --max-depth=0 "$dst" | awk '{print $1}')\n$(date +'%Y-%m-%d %H:%M:%S')\n${status}" > "$STATUS_FOLDER"/$name.log
} }
locked() { locked() {
local name="$1" local name="$1"
sed -i '3 s/$/?/' "$STATUS_FOLDER"/$name.log sed -i '4 s/$/?/' "$STATUS_FOLDER"/$name.log
} }
do_sync() { do_sync() {
local name="$1" local name="$1"
local safe_name="${name//\//_}"
local src="$2" local src="$2"
local dst="$3" local dst="$3"
local lock_file="/tmp/mirror-$safe_name.lock" local lock_file="/tmp/mirror-$name.lock"
if [ ! -f "$lock_file" ]; if [ ! -f "$lock_file" ];
then then
touch "$lock_file" touch "$lock_file"
presync "$safe_name" presync "$name"
mkdir -p "$(dirname "$dst")" mkdir -p "$(dirname "$dst")"
rsync -avzthP --stats --delete --bwlimit=6000 "$src" "$dst" rsync -avzthP --stats --delete --bwlimit=6000 "$src" "$dst"
postsync "$safe_name" $? "$dst" postsync "$name" $? "$dst"
rm "$lock_file" rm "$lock_file"
else else
locked "$safe_name" locked "$name"
fi fi
} }
append_index() {
echo "$1" >> "$STATUS_INDEX"
}
echo > "$STATUS_INDEX"
while read p || [[ -n $p ]]; do
append_index $p
done < "$THIS_DIR"/config
while read p || [[ -n $p ]]; do while read p || [[ -n $p ]]; do
do_sync $p do_sync $p
done < "$THIS_DIR"/config done < "$THIS_DIR"/config