diff --git a/.gitignore b/.gitignore
index ddc59d4..a86e608 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
-status/*
\ No newline at end of file
+status/*
+config
\ No newline at end of file
diff --git a/config b/config
deleted file mode 100644
index 558f41d..0000000
--- a/config
+++ /dev/null
@@ -1,2 +0,0 @@
-putty rsync://mirrors4.tuna.tsinghua.edu.cn/putty /tmp/putty
-github-raw rsync://mirrors4.tuna.tsinghua.edu.cn/github-raw /tmp/github-raw
diff --git a/config.example b/config.example
new file mode 100644
index 0000000..67a67ff
--- /dev/null
+++ b/config.example
@@ -0,0 +1,2 @@
+putty rsync://mirrors4.tuna.tsinghua.edu.cn/putty /tmp/putty
+github-raw/subfolder rsync://mirrors4.tuna.tsinghua.edu.cn/github-raw /tmp/github-raw
diff --git a/status/index.html b/status/index.html
index 38c3cd8..da7c74b 100644
--- a/status/index.html
+++ b/status/index.html
@@ -77,21 +77,20 @@
if (name.length == 0) {
continue;
}
- $.get(name + ".log", function (data) {
+ safe_name = name.replace(/\//g, "_");
+ $.get(safe_name + ".log", function (data) {
var data = data.split("\n");
- data[0] =
- "" + data[0] + "";
+ line_header =
+ "
" + name + " | ";
for (j in data) {
if (data[j] != "") {
data[j] = "" + data[j] + " | ";
}
}
$("#mirror_list").append(
- "" +
- data.join("") +
- "
"
+ "" +
+ line_header + data.join("") +
+ "
"
);
console.log(data);
});
diff --git a/sync.sh b/sync.sh
index fe10f9d..3525f59 100755
--- a/sync.sh
+++ b/sync.sh
@@ -9,12 +9,11 @@ touch "$STATUS_INDEX"
presync() {
local name="$1"
local log_file="$STATUS_FOLDER"/$name.log
- grep -qxF -- "$name" "$STATUS_INDEX" || echo "$name" >> "$STATUS_INDEX"
if [[ -f "$log_file" ]]; then
- sed -i "4c syncing..." "$log_file"
- sed -i "3c $(date +'%Y-%m-%d %H:%M:%S')" "$log_file"
+ sed -i "3c syncing..." "$log_file"
+ sed -i "2c $(date +'%Y-%m-%d %H:%M:%S')" "$log_file"
else
- echo -e "${name}\n0\n0\niniting..." > "$log_file"
+ echo -e "0\n0\niniting..." > "$log_file"
fi
}
@@ -22,33 +21,43 @@ postsync() {
local name="$1"
local status="$2"
local dst="$3"
- 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
+ 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
}
locked() {
local name="$1"
- sed -i '4 s/$/?/' "$STATUS_FOLDER"/$name.log
+ sed -i '3 s/$/?/' "$STATUS_FOLDER"/$name.log
}
do_sync() {
local name="$1"
+ local safe_name="${name//\//_}"
local src="$2"
local dst="$3"
- local lock_file="/tmp/mirror-$name.lock"
+ local lock_file="/tmp/mirror-$safe_name.lock"
if [ ! -f "$lock_file" ];
then
touch "$lock_file"
- presync "$name"
- mkdir -p "$(dirname "$dst")"
- rsync -avzthP --stats --delete --bwlimit=6000 "$src" "$dst"
- postsync "$name" $? "$dst"
+ presync "$safe_name"
+ mkdir -p "$(dirname "$dst")"
+ rsync -avzthP --stats --delete --bwlimit=6000 "$src" "$dst"
+ postsync "$safe_name" $? "$dst"
rm "$lock_file"
else
- locked "$name"
+ locked "$safe_name"
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
do_sync $p
done < "$THIS_DIR"/config