mirror of
https://github.com/DictXiong/dxsync.git
synced 2026-10-16 01:38:17 +08:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4ece102919 | |||
| 631da6652a | |||
| 718274af9d | |||
| 71cfa14596 | |||
|
|
66a1fdf2a9 | ||
|
|
460c7c0b3b | ||
|
|
32f486603f | ||
| a4500ddc73 | |||
|
|
2bf281fe8e |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
status/*
|
||||||
|
config
|
||||||
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
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/zsh
|
|
||||||
|
|
||||||
sed -i '4 s/$/?/' /mnt/mirrors/status/${1//\//\-}.log
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
106
status/index.html
Normal file
106
status/index.html
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
<!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>Status of Mirrors</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<section class="container md-shadow">
|
||||||
|
<article>
|
||||||
|
<header>
|
||||||
|
<h1><span id="hostname"></span>/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">
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<footer>
|
||||||
|
<p></p>
|
||||||
|
</footer>
|
||||||
|
</article>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$("#hostname").text(window.location.hostname);
|
||||||
|
$.get("index", function(data){
|
||||||
|
const list = data.split('\n')
|
||||||
|
for (i in list) {
|
||||||
|
const name=list[i]
|
||||||
|
if (name.length == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const safe_name = name.replace(/\//g, "_");
|
||||||
|
$.get(safe_name + ".log", function (data) {
|
||||||
|
var data = data.split("\n");
|
||||||
|
const line_header =
|
||||||
|
"<td><a href='../" + name + "'>" + name + "</a></td>";
|
||||||
|
for (j in data) {
|
||||||
|
if (data[j] != "") {
|
||||||
|
data[j] = "<td>" + data[j] + "</td>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$("#mirror_list").append(
|
||||||
|
"<tr id='" + safe_name + "'>" +
|
||||||
|
line_header + data.join("") +
|
||||||
|
"</tr>"
|
||||||
|
);
|
||||||
|
console.log(data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div hidden id="bottom-bar">
|
||||||
|
<p>2023 - ©BearDic.cn</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
79
sync.sh
79
sync.sh
@@ -1,15 +1,70 @@
|
|||||||
#!/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}
|
STATUS_FOLDER="$THIS_DIR"/status
|
||||||
do
|
STATUS_INDEX="$STATUS_FOLDER"/index
|
||||||
if [ ! -f "/tmp/mirror-${src//\//\-}.lock" ];
|
touch "$STATUS_INDEX"
|
||||||
then
|
|
||||||
touch /tmp/mirror-${src//\//\-}.lock
|
presync() {
|
||||||
/home/root/programs/dxsync/presync.sh $src
|
local name="$1"
|
||||||
rsync -4avzthP --stats --delete --bwlimit=6000 --log-file=/var/log/rsync-mirrors-${src//\//\-}.log rsync://mirrors4.tuna.tsinghua.edu.cn/$src /mnt/mirrors/$src
|
local log_file="$STATUS_FOLDER"/$name.log
|
||||||
/home/root/programs/dxsync/postsync.sh ${src} $?
|
if [[ -f "$log_file" ]]; then
|
||||||
rm /tmp/mirror-${src//\//\-}.lock
|
sed -i "3c syncing..." "$log_file"
|
||||||
|
sed -i "2c $(date +'%Y-%m-%d %H:%M:%S')" "$log_file"
|
||||||
else
|
else
|
||||||
/home/root/programs/dxsync/locked.sh $src
|
echo -e "0\n0\niniting..." > "$log_file"
|
||||||
fi
|
fi
|
||||||
done
|
}
|
||||||
|
|
||||||
|
postsync() {
|
||||||
|
local name="$1"
|
||||||
|
local status="$2"
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
locked() {
|
||||||
|
local name="$1"
|
||||||
|
sed -i '3 s/$/?/' "$STATUS_FOLDER"/$name.log
|
||||||
|
}
|
||||||
|
|
||||||
|
do_sync() {
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
local name="$1"
|
||||||
|
local safe_name="${name//\//_}"
|
||||||
|
local src="$2"
|
||||||
|
local dst="$3"
|
||||||
|
|
||||||
|
local lock_file="/tmp/mirror-$safe_name.lock"
|
||||||
|
if [ ! -f "$lock_file" ];
|
||||||
|
then
|
||||||
|
touch "$lock_file"
|
||||||
|
presync "$safe_name"
|
||||||
|
mkdir -p "$(dirname "$dst")"
|
||||||
|
rsync -avzthP --stats --delete --bwlimit=6000 "$src" "$dst"
|
||||||
|
postsync "$safe_name" $? "$dst"
|
||||||
|
rm "$lock_file"
|
||||||
|
else
|
||||||
|
locked "$safe_name"
|
||||||
|
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
|
||||||
|
do_sync $p
|
||||||
|
done < "$THIS_DIR"/config
|
||||||
|
|||||||
Reference in New Issue
Block a user