--wip-- [skip ci]

This commit is contained in:
xiongdian.me 2023-05-12 15:21:12 +08:00
parent 0690b9552b
commit 2bf281fe8e
7 changed files with 166 additions and 22 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
status/*

1
config Normal file
View File

@ -0,0 +1 @@
ubuntu-releases rsync://mirrors4.tuna.tsinghua.edu.cn/ubuntu-releases /tmp/mirrors/ubuntu-releases

View File

@ -1,3 +0,0 @@
#!/bin/zsh
sed -i '4 s/$/?/' /mnt/mirrors/status/${1//\//\-}.log

View File

@ -1,3 +0,0 @@
#! /bin/zsh
echo -e "${1}\n$(du -h --max-depth=0 /mnt/mirrors/$1 | awk '{print $1}')\n$(date +'%Y-%m-%d %H:%M:%S')\n${2}" > /mnt/mirrors/status/${1//\//\-}.log

View File

@ -1,4 +0,0 @@
#!/bin/zsh
sed -i "4c syncing..." /mnt/mirrors/status/${1//\//\-}.log
sed -i "3c $(date +'%Y-%m-%d %H:%M:%S')" /mnt/mirrors/status/${1//\//\-}.log

114
status/index.html Normal file
View File

@ -0,0 +1,114 @@
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
href="https://fonts.loli.net/css?family=Open+Sans:300,400,700|Ubuntu:300|Consolas"
rel="stylesheet"
type="text/css"
/>
<link
href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.min.css"
rel="stylesheet"
type="text/css"
/>
<link
href="https://tools.beardic.cn/css/page.css"
rel="stylesheet"
type="text/css"
/>
<link
rel="icon"
href="https://tools.beardic.cn/icon/favicon_32.png"
sizes="32x32"
/>
<link
rel="icon"
href="https://tools.beardic.cn/icon/favicon_192.png"
sizes="192x192"
/>
<link
rel="icon"
href="https://tools.beardic.cn/icon/favicon.png"
sizes="512x512"
/>
<link rel="apple-touch-icon-precomposed" href="/icon/favicon_180.png" />
<meta name="msapplication-TileImage" content="/icon/favicon_270.png" />
<script src="https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js"></script>
<script src="https://tools.beardic.cn/js/pagemap.min.js"></script>
<script src="https://tools.beardic.cn/js/page.js"></script>
<title>ibd.ink / mirrors</title>
</head>
<body>
<section class="container md-shadow">
<article>
<header>
<h1>ibd.ink / mirrors: Status</h1>
</header>
<table align="center">
<thead>
<tr>
<th>mirror</th>
<th>size</th>
<th>last update</th>
<th>status</th>
</tr>
</thead>
<tbody align="center" id="mirror_list">
<!-- <tr id="ubuntu"> </tr>
<tr id="ubuntu-releases"> </tr>
<tr id="CTAN"> </tr>
<tr id="docker-ce-linux-ubuntu"> </tr>
-->
</tbody>
</table>
<footer>
<p></p>
</footer>
</article>
</section>
<script>
var list = [
"ubuntu",
"ubuntu-releases",
"CTAN",
"docker-ce/linux/ubuntu",
];
for (i in list) {
(function (mirror) {
var secure_name = mirror.replace(/\//g, "-");
$.get(secure_name + ".log", function (data) {
var data = data.split("\n");
data[0] =
"<a href='../" + data[0] + "'>" + data[0] + "</a>";
for (i in data) {
if (data[i] != "") {
data[i] = "<td>" + data[i] + "</td>";
}
}
//$("#" + secure_name).html(data);
$("#mirror_list").append(
"<tr id='" +
secure_name +
"'>" +
data.join("") +
"</tr>"
);
console.log(data);
});
})(list[i]);
}
</script>
<div hidden id="bottom-bar">
<p>2023 - ©BearDic.cn</p>
</div>
</body>
</html>

62
sync.sh
View File

@ -1,15 +1,53 @@
#!/bin/zsh
#!/bin/bash
set -ex
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
for src in {CTAN,ubuntu,docker-ce/linux/ubuntu,ubuntu-releases}
do
if [ ! -f "/tmp/mirror-${src//\//\-}.lock" ];
then
touch /tmp/mirror-${src//\//\-}.lock
/home/root/programs/dxsync/presync.sh $src
rsync -4avzthP --stats --delete --bwlimit=6000 --log-file=/var/log/rsync-mirrors-${src//\//\-}.log rsync://mirrors4.tuna.tsinghua.edu.cn/$src /mnt/mirrors/$src
/home/root/programs/dxsync/postsync.sh ${src} $?
rm /tmp/mirror-${src//\//\-}.lock
STATUS_FOLDER="$THIS_DIR"/status
STATUS_INDEX="$STATUS_FOLDER"/index
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"
else
/home/root/programs/dxsync/locked.sh $src
echo -e "${name}\n0\n0\niniting..." > "$log_file"
fi
done
}
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
}
locked() {
local name="$1"
sed -i '4 s/$/?/' "$STATUS_FOLDER"/$name.log
}
do_sync() {
local name="$1"
local src="$2"
local dst="$3"
local lock_file="/tmp/mirror-$name.lock"
if [ ! -f "$lock_file" ];
then
touch "$lock_file"
presync "$name"
echo rsync -4avzthP --stats --delete --bwlimit=6000 "$src" "$dst"
postsync "$name" $?
rm "$lock_file"
else
locked "$name"
fi
}
while read p || [[ -n $p ]]; do
do_sync $p
done < "$THIS_DIR"/config