From 83c550f8e15bf26c8c20c69b30077d4ffcefd11e Mon Sep 17 00:00:00 2001 From: Bryan Hong Date: Sat, 6 Feb 2016 21:53:00 -0800 Subject: [PATCH] add ability to add more ubuntu mirror components the original update_mirror.sh only allowed for mirroring the main repository. left out restricted, multiverse, etc. the component is now an array so it is easy to add additional components if you want to mirror more than just main --- assets/update_mirror.sh | 49 +++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/assets/update_mirror.sh b/assets/update_mirror.sh index a35e738..b7b53df 100755 --- a/assets/update_mirror.sh +++ b/assets/update_mirror.sh @@ -3,8 +3,16 @@ set -e # Automate the initial creation and update of an Ubuntu package mirror in aptly +# The variables (as set below) will create a mirror of the Ubuntu Trusty repo +# with just the main component, you can add other components like restricted +# universe etc by adding to the array (separated by spaces). + +# For more detail about each of the variables below refer to: +# https://help.ubuntu.com/community/Repositories/CommandLine + UBUNTU_RELEASE=trusty UPSTREAM_URL="http://archive.ubuntu.com/ubuntu/" +COMPONENTS=( main ) REPOS=( ${UBUNTU_RELEASE} ${UBUNTU_RELEASE}-updates ${UBUNTU_RELEASE}-security ) # Export the GPG Public key @@ -14,35 +22,44 @@ fi # Create repository mirrors if they don't exist set +e -for repo in ${REPOS[@]}; do - aptly mirror list -raw | grep "^${repo}$" - if [[ $? -ne 0 ]]; then - echo "Creating mirror of ${repo} repository." - aptly mirror create \ - -architectures=amd64 ${repo} ${UPSTREAM_URL} ${repo} main - fi +for component in ${COMPONENTS[@]}; do + for repo in ${REPOS[@]}; do + aptly mirror list -raw | grep "^${repo}-${component}$" + if [[ $? -ne 0 ]]; then + echo "Creating mirror of ${repo}-${component} repository." + aptly mirror create \ + -architectures=amd64 ${repo}-${component} ${UPSTREAM_URL} ${repo} ${component} + fi + done done set -e # Update all repository mirrors -for repo in ${REPOS[@]}; do - echo "Updating ${repo} repository mirror.." - aptly mirror update ${repo} +for component in ${COMPONENTS[@]}; do + for repo in ${REPOS[@]}; do + echo "Updating ${repo}-${component} repository mirror.." + aptly mirror update ${repo}-${component} + done done # Create snapshots of updated repositories -for repo in ${REPOS[@]}; do - echo "Creating snapshot of ${repo} repository mirror.." - aptly snapshot create ${repo}-`date +%Y%m%d%H` from mirror ${repo} +for component in ${COMPONENTS[@]}; do + for repo in ${REPOS[@]}; do + echo "Creating snapshot of ${repo}-${component} repository mirror.." + SNAPSHOTARRAY+="${repo}-${component}-`date +%Y%m%d%H` " + aptly snapshot create ${repo}-${component}-`date +%Y%m%d%H` from mirror ${repo}-${component} + done done +echo ${SNAPSHOTARRAY[@]} + +#### I STOPPED HERE + # Merge snapshots into a single snapshot with updates applied echo "Merging snapshots into one.." aptly snapshot merge -latest \ ${UBUNTU_RELEASE}-merged-`date +%Y%m%d%H` \ - ${UBUNTU_RELEASE}-`date +%Y%m%d%H` \ - ${UBUNTU_RELEASE}-updates-`date +%Y%m%d%H` \ - ${UBUNTU_RELEASE}-security-`date +%Y%m%d%H` + ${SNAPSHOTARRAY[@]} # Publish the latest merged snapshot set +e