Skip to content

Instantly share code, notes, and snippets.

@chrisberkhout
Last active November 21, 2016 17:49
Show Gist options
  • Save chrisberkhout/5308244 to your computer and use it in GitHub Desktop.
Save chrisberkhout/5308244 to your computer and use it in GitHub Desktop.
A script to mirror the OpenGeo APT repository on S3 (so you still have packages for your version of the suite when OpenGeo releases a new version). Depends on `wget` and `s3cmd`.
#!/bin/bash
repo_host="apt.opengeo.org"
repo_dir="suite/v3/ubuntu"
repo_release="lucid"
echo -n "===> Please enter a bucket name: "
read -e bucket
echo "===> Confirming you have s3cmd configured..."
s3cmd --version || s3cmd --configure
echo "===> Downloading a copy of $repo_host/$repo_dir..."
wget -m -np http://$repo_host/$repo_dir/
find $repo_host -name "index.html*" | xargs rm
find $repo_host -name ".DS_Store" | xargs rm
echo "===> Creating or emptying the S3 bucket '$bucket'..."
s3cmd mb s3://$bucket --verbose
s3cmd del s3://$bucket/ --recursive --force --verbose
echo "===> Uploading the copy of $repo_host/$repo_dir to the S3 bucket..."
find $repo_host -type f | cut -d / -f 2-999 | xargs -n1 -I% s3cmd put --acl-public $repo_host/% s3://$bucket/%
# Getting the public URL of the mirror
echo "This is a mirror of the OpenGeo APT repository on "`date "+%Y-%m-%d."` > README.txt.tmp
mirror_url=`s3cmd put --acl-public README.txt.tmp s3://$bucket/$repo_dir/README.txt | grep -o "http.*$repo_dir"`
rm README.txt.tmp
echo "===> Mirroring of files complete. You can manually delete the local copy of $repo_host."
echo "===> Your APT sources.list config should use this entry:"
echo ""
echo "deb $mirror_url $repo_release main"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment