4d370942bb88fcadfd2a48f399c1b107e045176e
[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 declare -A REPO_TARGET
14 REPOID_TARGET=(
15     [ubuntu1404]="${BASEREPOID}dev"
16     [ubuntu1604]="${BASEREPOID}ubuntu.xenial.main"
17     [centos7]="${BASEREPOID}yum"
18 )
19 declare -A REPOURL_TARGET
20 REPOURL_TARGET=(
21     [ubuntu1404]="${BASEURL}dev"
22     [ubuntu1604]="${BASEURL}ubuntu.xenial.main"
23     [centos7]="${BASEURL}yum"
24 )
25
26 function push_file ()
27 {
28     push_file=$1
29     repoId=$2
30     url=$3
31     version=$4
32     artifactId=$5
33     file_type=$6
34     classifier=$7
35
36     if [ "$classifier" ]; then
37         d_classifier="-Dclassifier=$7"
38     fi
39
40     # Disable checks for doublequote to prevent glob / splitting
41     # shellcheck disable=SC2086
42     $MVN org.apache.maven.plugins:maven-deploy-plugin:deploy-file \
43         -Dfile=$push_file -DrepositoryId=$repoId \
44         -Durl=$url -DgroupId=$GROUP_ID \
45         -Dversion=$version -DartifactId=$artifactId \
46         -Dtype=$file_type $d_classifier\
47         -gs $GLOBAL_SETTINGS_FILE -s $SETTINGS_FILE
48
49     # make sure the script bombs if we fail an upload
50     if [ "$?" != '0' ]; then
51         echo "ERROR: There was an error with the upload"
52         exit 1
53     fi
54 }
55
56 function push_jar ()
57 {
58     jarfile=$1
59     repoId="${BASEREPOID}snapshot"
60     url="${BASEURL}snapshot"
61
62     basefile=$(basename -s .jar "$jarfile")
63     artifactId=$(echo "$basefile" | cut -f 1 -d '-')
64     version=$(echo "$basefile" | cut -f 2 -d '-')
65
66     push_file "$jarfile" "$repoId" "$url" "${version}-SNAPSHOT" "$artifactId" jar
67 }
68
69 function push_deb ()
70 {
71     debfile=$1
72     repoId=${REPOID_TARGET[${OS}]}
73     url="${REPOURL_TARGET[${OS}]}"
74
75     basefile=$(basename -s .deb "$debfile")
76     artifactId=$(echo "$basefile" | cut -f 1 -d '_')
77     version=$(echo "$basefile" | cut -f 2- -d '_')
78
79     push_file "$debfile" "$repoId" "$url" "$version" "$artifactId" deb
80 }
81
82 function push_rpm ()
83 {
84     rpmfile=$1
85     repoId=${REPOID_TARGET[${OS}]}
86     url="${REPOURL_TARGET[${OS}]}"
87
88     if grep -qE '\.s(rc\.)?rpm' <<<"$rpmfile"
89     then
90         rpmrelease=$(rpm -qp --queryformat="%{release}.src" "$rpmfile")
91     else
92         rpmrelease=$(rpm -qp --queryformat="%{release}.%{arch}" "$rpmfile")
93     fi
94     artifactId=$(rpm -qp --queryformat="%{name}" "$rpmfile")
95     version=$(rpm -qp --queryformat="%{version}" "$rpmfile")
96     push_file "$rpmfile" "$repoId" "$url" "${version}-${rpmrelease}" "$artifactId" rpm
97 }
98
99 if [ "${OS}" == "ubuntu1404" ]; then
100     # Find the files
101     JARS=$(find . -type f -iname '*.jar')
102     DEBS=$(find . -type f -iname '*.deb')
103     for i in $JARS
104     do
105         push_jar "$i"
106     done
107
108     for i in $DEBS
109     do
110         push_deb "$i"
111     done
112 elif [ "${OS}" == "ubuntu1604" ]; then
113     DEBS=$(find . -type f -iname '*.deb')
114     for i in $DEBS
115     do
116         push_deb "$i"
117     done
118 elif [ "${OS}" == "centos7" ]; then
119     # Find the files
120     RPMS=$(find . -type f -iname '*.rpm')
121     SRPMS=$(find . -type f -iname '*.srpm')
122     SRCRPMS=$(find . -type f -name '*.src.rpm')
123     for i in $RPMS $SRPMS $SRCRPMS
124     do
125         push_rpm "$i"
126     done
127 fi
128 # vim: ts=4 sw=4 sts=4 et ft=sh :