|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Copyright (C) 2015 Red Hat, Inc. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +# Script to bundle multi-JDK Maven artifacts into a single directory |
| 19 | +# to publish into the new Sonatype Maven Central repository |
| 20 | +# using their web interface (https://central.sonatype.com/publishing) |
| 21 | +# Usage: |
| 22 | +# ./scripts/6.x-bundle.sh |
| 23 | + |
| 24 | +set -e |
| 25 | + |
| 26 | +xml_grep="xml_grep --text_only --cond" |
| 27 | +global_version=$($xml_grep '/project/version' "pom.xml" 2>/dev/null | tail -n1) |
| 28 | +echo "Generating Fabric8 Kubernetes Client bundle for version: $global_version" |
| 29 | + |
| 30 | +TMPDIR=$(mktemp -d) |
| 31 | +echo "Using temp directory: $TMPDIR" |
| 32 | + |
| 33 | +echo "Copying Maven artifacts..." |
| 34 | +find . -name pom.xml | while read -r pom; do |
| 35 | + dir=$(dirname "$pom") |
| 36 | + |
| 37 | + # Extract Maven coordinates |
| 38 | + groupId=$($xml_grep '/project/parent/groupId|/project/groupId' "$pom" 2>/dev/null | tail -n1) |
| 39 | + artifactId=$($xml_grep '/project/artifactId' "$pom" 2>/dev/null | tail -n1) |
| 40 | + version=$($xml_grep '/project/parent/version|/project/version' "$pom" 2>/dev/null | tail -n1) |
| 41 | + |
| 42 | + if [ -z "$groupId" ] || [ -z "$artifactId" ] || [ -z "$version" ]; then |
| 43 | + echo "Exiting due to missing coordinates in $pom (groupId: $groupId, artifactId: $artifactId, version: $version)" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + |
| 47 | + if [ "$version" != "$global_version" ]; then |
| 48 | + echo " - Skipping $artifactId version $version as it does not match global version $global_version" |
| 49 | + continue |
| 50 | + fi |
| 51 | + |
| 52 | + # Build nested directory path |
| 53 | + IFS='.' read -ra GROUP_PARTS <<< "$groupId" |
| 54 | + path="" |
| 55 | + for part in "${GROUP_PARTS[@]}"; do |
| 56 | + path="$path/$part" |
| 57 | + done |
| 58 | + path="$path/$artifactId/$version" |
| 59 | + target_path="$TMPDIR/$path" |
| 60 | + mkdir -p "$target_path" |
| 61 | + source_path="$(realpath ~/.m2/repository)$path" |
| 62 | + |
| 63 | + # Copy files from source directory |
| 64 | + if [ -d "$source_path" ]; then |
| 65 | + find "$source_path" -maxdepth 1 -type f -name "${artifactId}-*" ! -name "*.lastUpdated" -exec cp {} "$target_path/" \; |
| 66 | + else |
| 67 | + echo " - Source directory $source_path does not exist. Skipping." |
| 68 | + fi |
| 69 | +done |
| 70 | + |
| 71 | +echo "Copying BOM files..." |
| 72 | +BOMS="kubernetes-client-bom kubernetes-client-bom-with-deps" |
| 73 | +for bom in $BOMS; do |
| 74 | + bom_path="target/classes/$bom/target" |
| 75 | + if [ -d "$bom_path" ]; then |
| 76 | + target_path="$TMPDIR/io/fabric8/$bom/$global_version/" |
| 77 | + mkdir -p "$target_path" |
| 78 | + find "$bom_path" -maxdepth 1 -type f -exec cp {} "$target_path" \; |
| 79 | + else |
| 80 | + echo " - BOM directory $bom_path does not exist. Skipping." |
| 81 | + fi |
| 82 | +done |
| 83 | + |
| 84 | +echo "Generating checksums..." |
| 85 | +find "$TMPDIR" -type f | while read -r file; do |
| 86 | + if [[ ! "$file" =~ \.asc$ ]]; then |
| 87 | + md5sum "$file" | awk '{print $1}' > "$file.md5" |
| 88 | + sha1sum "$file" | awk '{print $1}' > "$file.sha1" |
| 89 | + sha256sum "$file" | awk '{print $1}' > "$file.sha256" |
| 90 | + fi |
| 91 | +done |
| 92 | + |
| 93 | +echo "Verifying signatures..." |
| 94 | +find "$TMPDIR" -type f -name "*.asc" | while read -r signed_file; do |
| 95 | + output=$(gpg --verify "$signed_file" 2>&1 || true) |
| 96 | + if echo "$output" | grep -q 'Good signature from "FuseSource'; then |
| 97 | + : # NO OP |
| 98 | + else |
| 99 | + echo "Signature verification failed for $signed_file: $output" |
| 100 | + exit 1 |
| 101 | + fi |
| 102 | +done |
| 103 | + |
| 104 | +echo "Creating ZIP archive..." |
| 105 | +(cd "$TMPDIR" && zip -rq "kubernetes-client-${global_version}-bundle.zip" .) |
| 106 | + |
| 107 | +echo "Done. Files are in $TMPDIR" |
0 commit comments