Update odlrelease script to trim only 2 directory paths
[releng/builder.git] / scripts / odlrelease
1 #!/bin/bash
2
3 # @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
4 ##############################################################################
5 # Copyright (c) 2015 The Linux Foundation and others.
6 #
7 # All rights reserved. This program and the accompanying materials
8 # are made available under the terms of the Eclipse Public License v1.0
9 # which accompanies this distribution, and is available at
10 # http://www.eclipse.org/legal/epl-v10.html
11 ##############################################################################
12
13 ARTIFACT_DIR=".sign-artifacts"
14 SIGNATURES_DIR="gpg-signatures"
15
16
17 function print_usage {
18     echo "Usage: $0 sign <url>"
19     echo ""
20     echo "    sign   : Downloads and Signs artifacts from Nexus"
21 }
22
23
24 # Downloads artifacts from a Nexus URL and creates gpg signatures for them
25 # and copies the signatures to a separate directory.
26 function sign {
27     echo "Signing artifacts..."
28
29     if [ -d "$ARTIFACT_DIR" ]; then
30         echo "$ARTIFACT_DIR directory exists. Clearing..."
31         rm -rf $ARTIFACT_DIR
32     fi
33
34     mkdir $ARTIFACT_DIR
35     cd $ARTIFACT_DIR
36
37     echo "Fetching artifacts from $URL"
38     # Fetch Artifacts
39     wget --recursive --execute robots=off --no-parent --quiet \
40         --no-host-directories --cut-dirs=2 \
41         $URL
42
43     # Remove files that don't need signing
44     find . -type f \
45             -name "*.asc" \
46             -o -name "*.sha1" \
47             -o -name "*.md5" \
48             -o -name "_maven.repositories*" \
49             -o -name "_remote.repositories*" \
50             -o -name "maven-metadata-local.xml*" \
51             -o -name "maven-metadata.xml*" \
52             -o -name "index.html*" | xargs rm
53
54     for f in `find . -type f ! -name "*.asc" ! -name "*.sha1" ! -name "*.md5"`
55     do
56         echo "Signing $f"
57         gpg --batch -abq $f
58     done
59
60     cd ..
61
62     if [ -d "$SIGNATURES_DIR" ]; then
63         echo "$SIGNATURES_DIR directory exists. Clearing..."
64         rm -rf $SIGNATURES_DIR
65     fi
66
67     rsync -avz --include '*/' --include '*.asc' --exclude '*' \
68            "${ARTIFACT_DIR}/org" "${SIGNATURES_DIR}"
69 }
70
71
72 if [ -z "$2" ]; then
73     print_usage
74     exit 1
75 fi
76
77 MODE=$1
78 URL=$2
79
80 if [ "$MODE" == "sign" ]; then
81     sign
82 else
83     echo "ERROR: Invalid mode."
84     print_usage
85     exit 1
86 fi