launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/scripts/release-public-tools/release-public-tools.sh (about) 1 #!/usr/bin/env bash 2 # Release public tools. 3 # 4 # Retrieve the published juju-core debs for a specific release. 5 # Extract the jujud from the packages. 6 # Generate the streams data. 7 # Publish to Canonistack, HP, AWS, and Azure. 8 # 9 # This script requires that the user has credentials to upload the tools 10 # to Canonistack, HP Cloud, AWS, and Azure 11 12 set -e 13 14 15 usage() { 16 echo usage: $0 RELEASE destination-directory 17 exit 1 18 } 19 20 21 check_deps() { 22 has_deps=1 23 which lftp || has_deps=0 24 which swift || has_deps=0 25 which s3cmd || has_deps=0 26 test -f ~/.juju/canonistacktoolsrc || has_deps=0 27 test -f ~/.juju/hptoolsrc || has_deps=0 28 test -f ~/.juju/awstoolsrc || has_deps=0 29 test -f ~/.juju/azuretoolsrc || has_deps=0 30 if [[ $has_deps == 0 ]]; then 31 echo "Install lftp, python-swiftclient, and s3cmd" 32 echo "Your ~/.juju dir must contain rc files to publish:" 33 echo " canonistacktoolsrc, hptoolsrc, awstoolsrc, azuretoolsrc" 34 exit 2 35 fi 36 } 37 38 39 build_tool_tree() { 40 if [[ ! -d $DEST_DEBS ]]; then 41 mkdir $DEST_DEBS 42 fi 43 if [[ ! -d $DEST_TOOLS ]]; then 44 mkdir -p $DEST_TOOLS 45 fi 46 if [[ ! -d $DEST_DIST ]]; then 47 mkdir $DEST_DIST 48 fi 49 } 50 51 52 retrieve_released_tools() { 53 # Retrieve previously released tools to ensure the metadata continues 54 # to work for historic releases. 55 source ~/.juju/awstoolsrc 56 s3cmd sync s3://juju-dist/tools/releases/ $DEST_TOOLS 57 } 58 59 60 retrieve_packages() { 61 # Retrieve the $RELEASE packages that contain jujud. 62 cd $DEST_DEBS 63 for archive in $UBUNTU_ARCH $STABLE_ARCH $DEVEL_ARCH; do 64 echo "checking $archive for $RELEASE." 65 lftp -c mirror -I "juju-core_${RELEASE}*.deb" $archive; 66 done 67 mv juju-core/*deb ./ 68 rm -r juju-core 69 } 70 71 72 get_version() { 73 # Defines $version. $version can be different than $RELEASE used to 74 # match the packages in the archives. 75 control_version=$1 76 version=$(echo "$control_version" | 77 sed -n 's/^\([0-9]\+\).\([0-9]\+\).\([0-9]\+\)-[0-9].*/\1.\2.\3/p') 78 if [ "${version}" == "" ] ; then 79 echo "Invalid version: $control_version" 80 exit 3 81 fi 82 } 83 84 85 get_series() { 86 # Defines $series. 87 control_version=$1 88 pkg_series=$(echo "$control_version" | 89 sed -e 's/~juju.//;' \ 90 -e 's/^.*~\(ubuntu[0-9][0-9]\.[0-9][0-9]\|[a-z]\+\).*/\1/') 91 series=${version_names["$pkg_series"]} 92 case "${series}" in 93 "precise" | "quantal" | "raring" | "saucy" ) 94 ;; 95 *) 96 echo "Invalid series: $control_version" 97 exit 3 98 ;; 99 esac 100 } 101 102 103 get_arch() { 104 # Defines $arch. 105 control_file=$1 106 arch=$(sed -n 's/^Architecture: \([a-z]\+\)/\1/p' $control_file) 107 case "${arch}" in 108 "amd64" | "i386" | "armel" | "armhf" ) 109 ;; 110 *) 111 echo "Invalid arch: $arch" 112 exit 3 113 ;; 114 esac 115 } 116 117 118 archive_tools() { 119 # Builds the jujud tgz for each series and arch. 120 cd $DESTINATION 121 WORK=$(mktemp -d) 122 mkdir ${WORK}/juju 123 packages=$(ls ${DEST_DEBS}/*.deb) 124 for package in $packages; do 125 echo "Extracting jujud from ${package}." 126 dpkg-deb -e $package ${WORK}/juju 127 control_file="${WORK}/juju/control" 128 control_version=$(sed -n 's/^Version: \(.*\)/\1/p' $control_file) 129 get_version $control_version 130 get_series $control_version 131 get_arch $control_file 132 tool="${DEST_TOOLS}/juju-${version}-${series}-${arch}.tgz" 133 echo "Creating $tool." 134 dpkg-deb -x $package ${WORK}/juju 135 bin_dir="${WORK}/juju/usr/bin" 136 lib_dir="${WORK}/juju/usr/lib/juju-${version}/bin" 137 if [[ -f "${bin_dir}/jujud" ]]; then 138 change_dir=$bin_dir 139 elif [[ -f "${lib_dir}/jujud" ]]; then 140 change_dir=$lib_dir 141 else 142 echo "jujud is not in /usr/bin or /usr/lib" 143 exit 4 144 fi 145 tar cvfz $tool -C $change_dir jujud 146 echo "Created ${tool}." 147 rm -r ${WORK}/juju/* 148 done 149 } 150 151 152 generate_streams() { 153 # Create the streams metadata and organised the tree for later publication. 154 cd $DESTINATION 155 ${GOPATH}/bin/juju sync-tools --all --dev \ 156 --source=${DESTINATION} --destination=${DEST_DIST} 157 # Support old tools location so that deployments can upgrade to new tools. 158 cp ${DEST_DIST}/tools/releases/*tgz ${DEST_DIST}/tools 159 echo "The tools are in ${DEST_DIST}." 160 } 161 162 163 publish_to_canonistack() { 164 echo "Phase 6.1: Publish to canonistack." 165 cd $DESTINATION 166 source ~/.juju/canonistacktoolsrc 167 ${GOPATH}/bin/juju --show-log \ 168 sync-tools -e public-tools-canonistack --dev --source=${DEST_DIST} 169 # This needed to allow old deployments upgrade. 170 cd ${DEST_DIST} 171 swift upload juju-dist tools/*.tgz 172 } 173 174 175 publish_to_hp() { 176 echo "Phase 6.2: Publish to HP Cloud." 177 cd $DESTINATION 178 source ~/.juju/hptoolsrc 179 ${GOPATH}/bin/juju --show-log \ 180 sync-tools -e public-tools-hp --dev --source=${DEST_DIST} 181 # Support old tools location so that deployments can upgrade to new tools. 182 cd ${DEST_DIST} 183 swift upload juju-dist tools/*.tgz 184 } 185 186 187 publish_to_aws() { 188 echo "Phase 6.3: Publish to AWS." 189 cd $DESTINATION 190 source ~/.juju/awstoolsrc 191 s3cmd sync ${DEST_DIST}/tools s3://juju-dist/ 192 } 193 194 195 publish_to_azure() { 196 # This command sets the tool name from the local path! The local path for 197 # each public file MUST match the destination path :(. 198 echo "Phase 6.4: Publish to Azure." 199 cd $DESTINATION 200 source ~/.juju/azuretoolsrc 201 cd ${DEST_DIST} 202 public_files=$(find tools -name *.tgz -o -name *.json) 203 for public_file in $public_files; do 204 echo "Uploading $public_file to Azure West US." 205 go run $GOPATH/src/launchpad.net/gwacl/example/storage/run.go \ 206 -account=${AZURE_ACCOUNT} -container=juju-tools \ 207 -location="West US" \ 208 -key=${AZURE_JUJU_TOOLS_KEY} \ 209 -filename=$public_file \ 210 addblock 211 done 212 } 213 214 215 # These are the archives that are search for matching releases. 216 UBUNTU_ARCH="http://archive.ubuntu.com/ubuntu/pool/universe/j/juju-core/" 217 STABLE_ARCH="http://ppa.launchpad.net/juju/stable/ubuntu/pool/main/j/juju-core/" 218 DEVEL_ARCH="http://ppa.launchpad.net/juju/devel/ubuntu/pool/main/j/juju-core/" 219 220 # Series names found in package versions need to be normalised. 221 declare -A version_names 222 version_names+=(["ubuntu12.04"]="precise") 223 version_names+=(["ubuntu12.10"]="quantal") 224 version_names+=(["ubuntu13.04"]="raring") 225 version_names+=(["ubuntu13.10"]="saucy") 226 version_names+=(["precise"]="precise") 227 version_names+=(["quantal"]="quantal") 228 version_names+=(["raring"]="raring") 229 version_names+=(["saucy"]="saucy") 230 231 test $# -eq 2 || usage 232 233 RELEASE=$1 234 DESTINATION=$(cd $2; pwd) 235 DEST_DEBS="${DESTINATION}/debs" 236 DEST_TOOLS="${DESTINATION}/tools/releases" 237 DEST_DIST="${DESTINATION}/juju-dist" 238 239 echo "Phase 0: Checking requirements." 240 check_deps 241 242 echo "Phase 1: Building collection and republication tree." 243 build_tool_tree 244 245 echo "Phase 2: Retrieving released tools." 246 retrieve_released_tools 247 248 echo "Phase 3: Retrieving juju-core packages from archives" 249 retrieve_packages 250 251 echo "Phase 4: Extracting jujud from packages and archiving tools." 252 archive_tools 253 254 echo "Phase 5: Generating streams data." 255 generate_streams 256 257 echo "Phase 6: Publishing tools." 258 publish_to_canonistack 259 publish_to_hp 260 publish_to_aws 261 publish_to_azure