1 Star 0 Fork 0

正版水民/tunasync-scripts

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lxc-images.sh 2.50 KB
一键复制 编辑 原始数据 按行查看 历史
z4yx 提交于 2020-03-09 22:47 . optimize pref. of lxc-images.sh
#!/bin/bash
# requires: lftp wget jq
set -e
set -o pipefail
BASE_URL="${TUNASYNC_UPSTREAM_URL:-"http://images.linuxcontainers.org"}"
function sync_lxc_images() {
repo_url="$1"
repo_dir="$2"
[[ ! -d "$repo_dir" ]] && mkdir -p "$repo_dir"
cd "$repo_dir"
lftp "${repo_url}" -e "mirror --verbose -P 5 ; bye"
echo "lftp returns $?"
}
echo "=== Downloading /meta/1.0 ==="
mkdir -p "${TUNASYNC_WORKING_DIR}/meta/1.0"
for i in index-system index-system.asc index-user index-user.asc; do
wget -O "${TUNASYNC_WORKING_DIR}/meta/1.0/$i.work-in-progress" "${BASE_URL}/meta/1.0/$i"
done
echo "=== Downloading /streams/v1 ==="
mkdir -p "${TUNASYNC_WORKING_DIR}/streams/v1"
wget -O "${TUNASYNC_WORKING_DIR}/streams/v1/index.json.work-in-progress" "${BASE_URL}/streams/v1/index.json"
jq -r '.index[].path' "${TUNASYNC_WORKING_DIR}/streams/v1/index.json.work-in-progress" | while read line; do
[[ ! -d "${TUNASYNC_WORKING_DIR}/$(dirname $line)" ]] && mkdir -p "${TUNASYNC_WORKING_DIR}/$(dirname $line)"
wget -O "${TUNASYNC_WORKING_DIR}/${line}.work-in-progress" "${BASE_URL}/${line}"
done
echo "=== Downloading images ==="
sync_lxc_images "${BASE_URL}/images" "${TUNASYNC_WORKING_DIR}/images"
images_json="${TUNASYNC_WORKING_DIR}/streams/v1/images.json.work-in-progress"
[[ -f "$images_json" ]] || exit 1
jq -r '.products[].versions[].items[].path' "$images_json" > /tmp/filelist.txt
cat /tmp/filelist.txt | while read line; do
# $line looks like 'images/ubuntu/xenial/armhf/default/20200219_07:42/rootfs.tar.xz'
if [[ ! -f "${TUNASYNC_WORKING_DIR}/${line}" ]]; then
echo "Error: ${TUNASYNC_WORKING_DIR}/${line} vanished"
exit 1
fi
done
echo "=== Replacing /meta/1.0 ==="
for i in index-system index-system.asc index-user index-user.asc; do
mv -f "${TUNASYNC_WORKING_DIR}/meta/1.0/$i.work-in-progress" "${TUNASYNC_WORKING_DIR}/meta/1.0/$i"
done
echo "=== Replacing /streams/v1 ==="
jq -r '.index[].path' "${TUNASYNC_WORKING_DIR}/streams/v1/index.json.work-in-progress" | while read line; do
mv -f "${TUNASYNC_WORKING_DIR}/${line}.work-in-progress" "${TUNASYNC_WORKING_DIR}/${line}"
done
mv -f "${TUNASYNC_WORKING_DIR}/streams/v1/index.json.work-in-progress" "${TUNASYNC_WORKING_DIR}/streams/v1/index.json"
echo "=== Removing old images ==="
cd "${TUNASYNC_WORKING_DIR}"
find images/ -maxdepth 5 -mindepth 5 -mtime +3 | while read line; do
# $line looks like 'images/ubuntu/xenial/armhf/default/20200217_07:42'
grep --quiet "$line" /tmp/filelist.txt || ( echo "Removing $line"; rm -rf "$line" )
done
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wyk0930/tunasync-scripts.git
[email protected]:wyk0930/tunasync-scripts.git
wyk0930
tunasync-scripts
tunasync-scripts
master

搜索帮助