Make rpm push handle SRPMs
[ci-management.git] / jjb / vpp / include-raw-vpp-maven-push.sh
1 #!/bin/bash
2
3 # Determine the path to maven
4 if [ -z "${MAVEN_SELECTOR}" ]; then
5     echo "ERROR: No Maven install detected!"
6     exit 1
7 fi
8
9 MVN="${HOME}/tools/hudson.tasks.Maven_MavenInstallation/${MAVEN_SELECTOR}/bin/mvn"
10 GROUP_ID="io.fd.${PROJECT}"
11 BASEURL="${NEXUSPROXY}/content/repositories/fd.io."
12 BASEREPOID='fdio-'
13
14 function push_file ()
15 {
16     push_file=$1
17     repoId=$2
18     url=$3
19     version=$4
20     artifactId=$5
21     file_type=$6
22     classifier=$7
23
24     if [ "$classifier" ]; then
25         d_classifier="-Dclassifier=$7"
26     fi
27
28     # Disable checks for doublequote to prevent glob / splitting
29     # shellcheck disable=SC2086
30     $MVN org.apache.maven.plugins:maven-deploy-plugin:deploy-file \
31         -Dfile=$push_file -DrepositoryId=$repoId \
32         -Durl=$url -DgroupId=$GROUP_ID \
33         -Dversion=$version -DartifactId=$artifactId \
34         -Dtype=$file_type $d_classifier\
35         -gs $GLOBAL_SETTINGS_FILE -s $SETTINGS_FILE
36
37     # make sure the script bombs if we fail an upload
38     if [ "$?" != '0' ]; then
39         echo "ERROR: There was an error with the upload"
40         exit 1
41     fi
42 }
43
44 function push_jar ()
45 {
46     jarfile=$1
47     repoId="${BASEREPOID}snapshot"
48     url="${BASEURL}snapshot"
49
50     basefile=$(basename -s .jar "$jarfile")
51     artifactId=$(echo "$basefile" | cut -f 1 -d '-')
52     version=$(echo "$basefile" | cut -f 2 -d '-')
53
54     push_file "$jarfile" "$repoId" "$url" "${version}-SNAPSHOT" "$artifactId" jar
55 }
56
57 function push_deb ()
58 {
59     debfile=$1
60     repoId="${BASEREPOID}dev"
61     url="${BASEURL}dev"
62
63     basefile=$(basename -s .deb "$debfile")
64     artifactId=$(echo "$basefile" | cut -f 1 -d '_')
65     version=$(echo "$basefile" | cut -f 2- -d '_')
66
67     push_file "$debfile" "$repoId" "$url" "$version" "$artifactId" deb
68 }
69
70 function push_rpm ()
71 {
72     rpmfile=$1
73     repoId="${BASEREPOID}yum"
74     url="${BASEURL}yum"
75
76     if grep -q srpm <<<"$rpmfile"
77     then
78         rpmtype=srpm
79         basefile=$(basename -s .srpm "$rpmfile")
80     else
81         rpmtype=rpm
82         basefile=$(basename -s .rpm "$rpmfile")
83     fi
84     artifactId=$(echo "$basefile" | cut -f 1 -d '_')
85     version=$(echo "$basefile" | cut -f 2- -d '_')
86     push_file "$rpmfile" "$repoId" "$url" "$version" "$artifactId" "$rpmtype"
87 }
88
89 if [ "${OS}" == "ubuntu1404" ]; then
90     # Find the files
91     JARS=$(find . -type f -iname '*.jar')
92     DEBS=$(find . -type f -iname '*.deb')
93     for i in $JARS
94     do
95         push_jar "$i"
96     done
97
98     for i in $DEBS
99     do
100         push_deb "$i"
101     done
102 elif [ "${OS}" == "centos7" ]; then
103     # Find the files
104     RPMS=$(find . -type f -iname '*.rpm')
105     SRPMS=$(find . -type f -iname '*.srpm')
106     for i in $RPMS $SRPMS
107     do
108         push_rpm "$i"
109     done
110 fi
111 # vim: ts=4 sw=4 sts=4 et ft=sh :