From 0dd75d38f74ddb424506549606a1e4a809b8589b Mon Sep 17 00:00:00 2001 From: bigeagle Date: Sun, 19 Jun 2016 18:05:30 +0800 Subject: [PATCH] update virtualbox syncing script: standalone packages included --- virtualbox.sh | 67 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 11 deletions(-) diff --git a/virtualbox.sh b/virtualbox.sh index 8853b27..e24c7ba 100755 --- a/virtualbox.sh +++ b/virtualbox.sh @@ -1,5 +1,5 @@ #!/bin/bash -# requires: wget, yum-utils +# requires: wget, yum-utils, timeout, md5sum set -e set -o pipefail @@ -9,6 +9,7 @@ _here=`dirname $(realpath $0)` [ -z "${LOADED_APT_DOWNLOAD}" ] && (echo "failed to load apt-download"; exit 1) +BASE_URL="http://download.virtualbox.org/virtualbox" BASE_PATH="${TUNASYNC_WORKING_DIR}" RPM_PATH="${BASE_PATH}/rpm" @@ -32,25 +33,69 @@ for releasever in ${EL_VERSIONS[@]}; do cat <> ${cfg} [el${releasever}] name=Oracle Linux / RHEL / CentOS-5 / x86_64 - VirtualBox -baseurl=http://download.virtualbox.org/virtualbox/rpm/el/$releasever/x86_64 +baseurl=${BASE_URL}/rpm/el/$releasever/x86_64 repo_gpgcheck=0 gpgcheck=0 enabled=1 EOF done -reposync -c $cfg -d -p ${RPM_PATH} -e $cache_dir -for releasever in ${EL_VERSIONS[@]}; do -createrepo --update -v -c $cache_dir -o ${RPM_PATH}/el$releasever ${RPM_PATH}/el$releasever -done +if [[ -z ${DRY_RUN:-} ]]; then + reposync -c $cfg -d -p ${RPM_PATH} -e $cache_dir + for releasever in ${EL_VERSIONS[@]}; do + createrepo --update -v -c $cache_dir -o ${RPM_PATH}/el$releasever ${RPM_PATH}/el$releasever + done +fi rm $cfg # === download deb packages ==== -base_url="http://download.virtualbox.org/virtualbox/debian" +if [[ ! -z ${DRY_RUN:-} ]]; then + export APT_DRY_RUN=1 +fi + for version in ${APT_VERSIONS[@]}; do - apt-download-binary ${base_url} "$version" "contrib" "amd64" "${APT_PATH}" || true - apt-download-binary ${base_url} "$version" "non-free" "amd64" "${APT_PATH}" || true - apt-download-binary ${base_url} "$version" "contrib" "i386" "${APT_PATH}" || true - apt-download-binary ${base_url} "$version" "non-free" "i386" "${APT_PATH}" || true + apt-download-binary "${BASE_URL}/debian" "$version" "contrib" "amd64" "${APT_PATH}" || true + apt-download-binary "${BASE_URL}/debian" "$version" "non-free" "amd64" "${APT_PATH}" || true + apt-download-binary "${BASE_URL}/debian" "$version" "contrib" "i386" "${APT_PATH}" || true + apt-download-binary "${BASE_URL}/debian" "$version" "non-free" "i386" "${APT_PATH}" || true done echo "Debian and ubuntu finished" + +# === download standalone packages ==== + +LATEST_VERSION=`curl -s ${BASE_URL}/LATEST.TXT` +LATEST_PATH="${BASE_PATH}/${LATEST_VERSION}" +echo ${LATEST_VERSION} > ${PATH_PATH}/LATEST.TXT +mkdir -p ${LATEST_PATH} +timeout -s INT 300 wget -O "${LATEST_PATH}/MD5SUMS" "${BASE_URL}/${LATEST_VERSION}/MD5SUMS" + +while read line; do + read -a tokens <<< $line + pkg_checksum=${tokens[0]} + filename=${tokens[1]} + filename=${filename/\*/} + + dest_filename="${LATEST_PATH}/${filename}" + pkg_url="${BASE_URL}/${LATEST_VERSION}/${filename}" + + declare downloaded=false + + if [ -f ${dest_filename} ]; then + echo "${pkg_checksum} ${dest_filename}" | md5sum -c - && { + downloaded=true + echo "Skipping ${pkg_filename}" + } + fi + while [ $downloaded != true ]; do + echo "downloading ${pkg_url} to ${dest_filename}" + if [[ -z ${DRY_RUN:-} ]]; then + wget ${WGET_OPTIONS:-} -N -c -q -O ${dest_filename} ${pkg_url} && { + # two space for md5sum/sha1sum/sha256sum check format + echo "${pkg_checksum} ${dest_filename}" | md5sum -c - && downloaded=true + } + else + downloaded=true + fi + done +done < "${LATEST_PATH}/MD5SUMS" +echo "Virtualbox ${LATEST_VERSION} finished"