mirror of
https://github.com/DictXiong/dxsync.git
synced 2026-10-16 01:38:17 +08:00
Compare commits
5 Commits
460c7c0b3b
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 4ece102919 | |||
| 631da6652a | |||
| 718274af9d | |||
| 71cfa14596 | |||
|
|
66a1fdf2a9 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
status/*
|
status/*
|
||||||
|
config
|
||||||
2
config
2
config
@@ -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
|
|
||||||
2
config.example
Normal file
2
config.example
Normal file
@@ -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
|
||||||
@@ -42,14 +42,14 @@
|
|||||||
<script src="https://tools.beardic.cn/js/pagemap.min.js"></script>
|
<script src="https://tools.beardic.cn/js/pagemap.min.js"></script>
|
||||||
<script src="https://tools.beardic.cn/js/page.js"></script>
|
<script src="https://tools.beardic.cn/js/page.js"></script>
|
||||||
|
|
||||||
<title>ibd.ink / mirrors</title>
|
<title>Status of Mirrors</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<section class="container md-shadow">
|
<section class="container md-shadow">
|
||||||
<article>
|
<article>
|
||||||
<header>
|
<header>
|
||||||
<h1>ibd.ink / mirrors: Status</h1>
|
<h1><span id="hostname"></span>/mirrors: status</h1>
|
||||||
</header>
|
</header>
|
||||||
<table align="center">
|
<table align="center">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -70,28 +70,28 @@
|
|||||||
</section>
|
</section>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
$("#hostname").text(window.location.hostname);
|
||||||
$.get("index", function(data){
|
$.get("index", function(data){
|
||||||
list = data.split('\n')
|
const list = data.split('\n')
|
||||||
for (i in list) {
|
for (i in list) {
|
||||||
name=list[i]
|
const name=list[i]
|
||||||
if (name.length == 0) {
|
if (name.length == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$.get(name + ".log", function (data) {
|
const safe_name = name.replace(/\//g, "_");
|
||||||
|
$.get(safe_name + ".log", function (data) {
|
||||||
var data = data.split("\n");
|
var data = data.split("\n");
|
||||||
data[0] =
|
const line_header =
|
||||||
"<a href='../" + data[0] + "'>" + data[0] + "</a>";
|
"<td><a href='../" + name + "'>" + name + "</a></td>";
|
||||||
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='" +
|
"<tr id='" + safe_name + "'>" +
|
||||||
name +
|
line_header + data.join("") +
|
||||||
"'>" +
|
"</tr>"
|
||||||
data.join("") +
|
|
||||||
"</tr>"
|
|
||||||
);
|
);
|
||||||
console.log(data);
|
console.log(data);
|
||||||
});
|
});
|
||||||
|
|||||||
40
sync.sh
40
sync.sh
@@ -9,12 +9,11 @@ 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 "4c syncing..." "$log_file"
|
sed -i "3c syncing..." "$log_file"
|
||||||
sed -i "3c $(date +'%Y-%m-%d %H:%M:%S')" "$log_file"
|
sed -i "2c $(date +'%Y-%m-%d %H:%M:%S')" "$log_file"
|
||||||
else
|
else
|
||||||
echo -e "${name}\n0\n0\niniting..." > "$log_file"
|
echo -e "0\n0\niniting..." > "$log_file"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,33 +21,50 @@ postsync() {
|
|||||||
local name="$1"
|
local name="$1"
|
||||||
local status="$2"
|
local status="$2"
|
||||||
local dst="$3"
|
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() {
|
locked() {
|
||||||
local name="$1"
|
local name="$1"
|
||||||
sed -i '4 s/$/?/' "$STATUS_FOLDER"/$name.log
|
sed -i '3 s/$/?/' "$STATUS_FOLDER"/$name.log
|
||||||
}
|
}
|
||||||
|
|
||||||
do_sync() {
|
do_sync() {
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
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-$name.lock"
|
local lock_file="/tmp/mirror-$safe_name.lock"
|
||||||
if [ ! -f "$lock_file" ];
|
if [ ! -f "$lock_file" ];
|
||||||
then
|
then
|
||||||
touch "$lock_file"
|
touch "$lock_file"
|
||||||
presync "$name"
|
presync "$safe_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 "$name" $? "$dst"
|
postsync "$safe_name" $? "$dst"
|
||||||
rm "$lock_file"
|
rm "$lock_file"
|
||||||
else
|
else
|
||||||
locked "$name"
|
locked "$safe_name"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
append_index() {
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
echo "$1" >> "$STATUS_INDEX"
|
||||||
|
}
|
||||||
|
|
||||||
|
rm "$STATUS_INDEX"
|
||||||
|
touch "$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
|
||||||
|
|||||||
Reference in New Issue
Block a user