Fix reponames
[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="fd.io.${REPO_NAME}"
61     url="${BASEURL}${REPO_NAME}"
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=fd.io.${REPO_NAME}"
74     url="${BASEURL}${REPO_NAME}"
75
76     if grep -qE '\.s(rc\.)?rpm' <<<"$rpmfile"
77     then
78         rpmrelease=$(rpm -qp --queryformat="%{release}.src" "$rpmfile")
79     else
80         rpmrelease=$(rpm -qp --queryformat="%{release}.%{arch}" "$rpmfile")
81     fi
82     artifactId=$(rpm -qp --queryformat="%{name}" "$rpmfile")
83     version=$(rpm -qp --queryformat="%{version}" "$rpmfile")
84     push_file "$rpmfile" "$repoId" "$url" "${version}-${rpmrelease}" "$artifactId" rpm
85 }
86
87 if [ "${OS}" == "ubuntu1404" ]; then
88     # Find the files
89     JARS=$(find . -type f -iname '*.jar')
90     DEBS=$(find . -type f -iname '*.deb')
91     for i in $JARS
92     do
93         push_jar "$i"
94     done
95
96     for i in $DEBS
97     do
98         push_deb "$i"
99     done
100 elif [ "${OS}" == "ubuntu1604" ]; then
101     DEBS=$(find . -type f -iname '*.deb')
102     for i in $DEBS
103     do
104         push_deb "$i"
105     done
106 elif [ "${OS}" == "centos7" ]; then
107     # Find the files
108     RPMS=$(find . -type f -iname '*.rpm')
109     SRPMS=$(find . -type f -iname '*.srpm')
110     SRCRPMS=$(find . -type f -name '*.src.rpm')
111     for i in $RPMS $SRPMS $SRCRPMS
112     do
113         push_rpm "$i"
114     done
115 fi
116 # vim: ts=4 sw=4 sts=4 et ft=sh :