From ec06c94bb9c4f5f7485f3295d878db4cdcba142e Mon Sep 17 00:00:00 2001 From: Feng Yu Date: Thu, 22 Sep 2016 21:52:20 +0800 Subject: [PATCH 1/3] make lxc-images support LXD/LXC 2.0 --- lxc-images.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lxc-images.sh b/lxc-images.sh index b18cf9b..6b74c0d 100755 --- a/lxc-images.sh +++ b/lxc-images.sh @@ -1,5 +1,5 @@ #!/bin/bash -# requires: lftp wget +# requires: lftp wget jq BASE_URL="${TUNASYNC_UPSTREAM_URL:-"http://images.linuxcontainers.org/"}" @@ -16,5 +16,13 @@ function sync_lxc_images() { sync_lxc_images "${BASE_URL}/images" "${TUNASYNC_WORKING_DIR}/images" mkdir -p "${TUNASYNC_WORKING_DIR}/meta/1.0" -wget -O "${TUNASYNC_WORKING_DIR}/meta/1.0/index-system" "${BASE_URL}/meta/1.0/index-system" -wget -O "${TUNASYNC_WORKING_DIR}/meta/1.0/index-user" "${BASE_URL}/meta/1.0/index-user" +wget -c -T5 -O "${TUNASYNC_WORKING_DIR}/meta/1.0/index-system" "${BASE_URL}/meta/1.0/index-system" +wget -c -T5 -O "${TUNASYNC_WORKING_DIR}/meta/1.0/index-user" "${BASE_URL}/meta/1.0/index-user" + +mkdir -p "${TUNASYNC_WORKING_DIR}/streams/v1" +wget -c -T5 -O "${TUNASYNC_WORKING_DIR}/streams/v1/index.json" "${BASE_URL}/streams/v1/index.json" + +jq -r '.index.images.path' "${TUNASYNC_WORKING_DIR}/streams/v1/index.json" | while read line; do + [ ! -d "$(dirname $line)" ] && mkdir -p "$(dirname $line)" + wget -c -T5 -O "${TUNASYNC_WORKING_DIR}/${line}" "${BASE_URL}/${line}" +done From bf3de49dffc2d633bc2276d76ce33618372789e3 Mon Sep 17 00:00:00 2001 From: Feng Yu Date: Thu, 22 Sep 2016 22:03:57 +0800 Subject: [PATCH 2/3] Add missing ${TUNASYNC_WORKING_DIR} variable. --- lxc-images.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxc-images.sh b/lxc-images.sh index 6b74c0d..baf196b 100755 --- a/lxc-images.sh +++ b/lxc-images.sh @@ -23,6 +23,6 @@ mkdir -p "${TUNASYNC_WORKING_DIR}/streams/v1" wget -c -T5 -O "${TUNASYNC_WORKING_DIR}/streams/v1/index.json" "${BASE_URL}/streams/v1/index.json" jq -r '.index.images.path' "${TUNASYNC_WORKING_DIR}/streams/v1/index.json" | while read line; do - [ ! -d "$(dirname $line)" ] && mkdir -p "$(dirname $line)" + [ ! -d "${TUNASYNC_WORKING_DIR}/$(dirname $line)" ] && mkdir -p "${TUNASYNC_WORKING_DIR}/$(dirname $line)" wget -c -T5 -O "${TUNASYNC_WORKING_DIR}/${line}" "${BASE_URL}/${line}" done From 54a0507609a27088e488cb9db67046c22d1b1094 Mon Sep 17 00:00:00 2001 From: Feng Yu Date: Thu, 22 Sep 2016 22:18:13 +0800 Subject: [PATCH 3/3] Modify jq cmd for parse index.json file. --- lxc-images.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxc-images.sh b/lxc-images.sh index baf196b..9e230c5 100755 --- a/lxc-images.sh +++ b/lxc-images.sh @@ -22,7 +22,7 @@ wget -c -T5 -O "${TUNASYNC_WORKING_DIR}/meta/1.0/index-user" "${BASE_URL}/meta/1 mkdir -p "${TUNASYNC_WORKING_DIR}/streams/v1" wget -c -T5 -O "${TUNASYNC_WORKING_DIR}/streams/v1/index.json" "${BASE_URL}/streams/v1/index.json" -jq -r '.index.images.path' "${TUNASYNC_WORKING_DIR}/streams/v1/index.json" | while read line; do +jq -r '.index[].path' "${TUNASYNC_WORKING_DIR}/streams/v1/index.json" | while read line; do [ ! -d "${TUNASYNC_WORKING_DIR}/$(dirname $line)" ] && mkdir -p "${TUNASYNC_WORKING_DIR}/$(dirname $line)" wget -c -T5 -O "${TUNASYNC_WORKING_DIR}/${line}" "${BASE_URL}/${line}" done