diff --git a/imagebuild/tinyipa/build-tinyipa.sh b/imagebuild/tinyipa/build-tinyipa.sh index e66def612..fac6ebef5 100755 --- a/imagebuild/tinyipa/build-tinyipa.sh +++ b/imagebuild/tinyipa/build-tinyipa.sh @@ -2,9 +2,10 @@ set -ex WORKDIR=$(readlink -f 0ドル | xargs dirname) +source ${WORKDIR}/tc-mirror.sh BUILDDIR="$WORKDIR/tinyipabuild" BUILD_AND_INSTALL_TINYIPA=${BUILD_AND_INSTALL_TINYIPA:-false} -TINYCORE_MIRROR_URL=${TINYCORE_MIRROR_URL:-"http://repo.tinycorelinux.net"} +TINYCORE_MIRROR_URL=${TINYCORE_MIRROR_URL:-} CHROOT_PATH="/tmp/overides:/usr/local/sbin:/usr/local/bin:/apps/bin:/usr/sbin:/usr/bin:/sbin:/bin" CHROOT_CMD="sudo chroot $BUILDDIR /usr/bin/env -i PATH=$CHROOT_PATH http_proxy=$http_proxy https_proxy=$https_proxy no_proxy=$no_proxy" @@ -32,6 +33,9 @@ fi # Download and Cache Tiny Core Files ############################################## +# Find a working TC mirror if none is explicitly provided +choose_tc_mirror + cd $WORKDIR/build_files wget -N $TINYCORE_MIRROR_URL/7.x/x86_64/release/distribution_files/corepure64.gz wget -N $TINYCORE_MIRROR_URL/7.x/x86_64/release/distribution_files/vmlinuz64 diff --git a/imagebuild/tinyipa/finalise-tinyipa.sh b/imagebuild/tinyipa/finalise-tinyipa.sh index 41c96cce2..459723a49 100755 --- a/imagebuild/tinyipa/finalise-tinyipa.sh +++ b/imagebuild/tinyipa/finalise-tinyipa.sh @@ -2,10 +2,11 @@ set -ex WORKDIR=$(readlink -f 0ドル | xargs dirname) +source ${WORKDIR}/tc-mirror.sh BUILDDIR="$WORKDIR/tinyipabuild" FINALDIR="$WORKDIR/tinyipafinal" BUILD_AND_INSTALL_TINYIPA=${BUILD_AND_INSTALL_TINYIPA:-true} -TINYCORE_MIRROR_URL=${TINYCORE_MIRROR_URL:-"http://repo.tinycorelinux.net"} +TINYCORE_MIRROR_URL=${TINYCORE_MIRROR_URL:-} ENABLE_SSH=${ENABLE_SSH:-false} SSH_PUBLIC_KEY=${SSH_PUBLIC_KEY:-} PYOPTIMIZE_TINYIPA=${PYOPTIMIZE_TINYIPA:-true} @@ -19,6 +20,10 @@ TC_CHROOT_CMD="sudo chroot --userspec=$TC:$STAFF $FINALDIR /usr/bin/env -i PATH= echo "Finalising tinyipa:" +# Find a working TC mirror if none is explicitly provided +choose_tc_mirror + + if $ENABLE_SSH ; then echo "Validating location of public SSH key" if [ -n "$SSH_PUBLIC_KEY" ]; then diff --git a/imagebuild/tinyipa/tc-mirror.sh b/imagebuild/tinyipa/tc-mirror.sh new file mode 100644 index 000000000..902243114 --- /dev/null +++ b/imagebuild/tinyipa/tc-mirror.sh @@ -0,0 +1,52 @@ + +#NOTE(pas-ha) +# The first URL is the official TC repo, +# the rest of the list is taken from +# http://wiki.tinycorelinux.net/wiki:mirrors +# as of time of this writing. +# Only HTTP mirrors were considered with the following ordering +# - those that were unavailable are moved to the bottom of the list +# - those that already responded with 404 are moved to the very bottom + +TC_MIRRORS="http://repo.tinycorelinux.net +http://distro.ibiblio.org/tinycorelinux +http://mirror.cedia.org.ec/tinycorelinux +http://mirror.epn.edu.ec/tinycorelinux +http://mirrors.163.com/tinycorelinux +http://kambing.ui.ac.id/tinycorelinux +http://ftp.nluug.nl/os/Linux/distr/tinycorelinux +http://ftp.vim.org/os/Linux/distr/tinycorelinux +http://www.gtlib.gatech.edu/pub/tinycore +http://tinycore.mirror.uber.com.au +http://l4u-00.jinr.ru/LinuxArchive/Ftp/tinycorelinux" + +function probe_url { + wget -q --spider --tries 1 --timeout 10 "1ドル" 2>&1 +} + +function choose_tc_mirror { + if [ -z ${TINYCORE_MIRROR_URL} ]; then + for url in ${TC_MIRRORS}; do + echo "Checking Tiny Core Linux mirror ${url}" + if probe_url ${url} ; then + echo "Check succeeded: ${url} is responding." + TINYCORE_MIRROR_URL=${url} + break + else + echo "Check failed: ${url} is not responding" + fi + done + if [ -z ${TINYCORE_MIRROR_URL} ]; then + echo "Failed to find working Tiny Core Linux mirror" + exit 1 + fi + else + echo "Probing provided Tiny Core Linux mirror ${TINYCORE_MIRROR_URL}" + if probe_url ${TINYCORE_MIRROR_URL} ; then + echo "Check succeeded: ${TINYCORE_MIRROR_URL} is responding." + else + echo "Check failed: ${TINYCORE_MIRROR_URL} is not responding" + exit 1 + fi + fi +}