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