Add resources mirror creation tool

This commit is contained in:
Gres 2020-04-14 21:15:26 +03:00
parent 9b2009ed6c
commit 7b1d7b9eeb
3 changed files with 79 additions and 0 deletions

13
share/mirror/Dockerfile Normal file
View File

@ -0,0 +1,13 @@
FROM alpine:latest
ADD entrypoint.sh /entrypoint.sh
RUN \
addgroup -g 1200 -S app && \
adduser -g 1200 -u 1200 -S app && \
apk add --upgrade --no-cache git zip && \
chmod +x /entrypoint.sh
USER app
VOLUME [ "/git", "/packed" ]
ENTRYPOINT ["/entrypoint.sh"]

View File

@ -0,0 +1,15 @@
version: '3'
services:
mirror:
build: .
image: gres/st_mirror
restart: always
container_name: st_mirror
logging:
driver: json-file
options:
max-size: "10m"
max-file: "5"
volumes:
- ./git:/git
- ./packed:/packed

51
share/mirror/entrypoint.sh Executable file
View File

@ -0,0 +1,51 @@
#!/bin/sh
pack() {
mkdir -p "$2"
for f in $(ls $1); do
source="$1/$f"
target="$2/$f"
if [ -d "$source" ]; then
pack "$source" "$target"
elif [ -f "$source" ]; then
if [ "$target.zip" -nt "$source" ]; then
echo "$source is up to date"
continue
fi
tmp=/tmp/archive.zip
echo "packing $source -> $tmp"
ls -l "$source"
zip -9 -j "$tmp" "$source"
echo "moving $tmp -> $target.zip"
mv "$tmp" "$target.zip"
chmod 444 "$target.zip"
ls -l "$target.zip"
fi
done
}
mirror() {
cur="$(pwd)"
url="$1"
dir="$2"
git_dir="/git/$dir"
pack_dir="/packed/$dir"
echo $url $git_dir $pack_dir
if [ -d $git_dir ]; then
echo "fetching"
cd $git_dir && git fetch --depth=1 origin master
else
echo "cloning"
git clone --depth=1 --single-branch "$url" $git_dir
fi
echo "packing"
pack "$git_dir" "$pack_dir"
}
while true; do
mirror 'git://anongit.freedesktop.org/libreoffice/dictionaries' 'dictionaries'
mirror 'https://github.com/tesseract-ocr/tessdata_best.git' 'tessdata_best'
echo "sleeping"
sleep 6h
done