-
Notifications
You must be signed in to change notification settings - Fork 2
/
release.sh
executable file
·223 lines (208 loc) · 7.17 KB
/
release.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/bash
# Exit on error
set -e
# Treat using unset variables as an error
set -u
function usage () {
echo "$( basename $0 ) [--snapshot] --version <version> [--file <file>|--all-files]"
echo " [--bintray-user --bintray-password --bintray-url --bintray-deb-repo --bintray-rpm-repo --bintray-deb-options --bintray-rpm-options]"
}
# Basic option handling
while (( $# > 0 ))
do
opt="$1"
case $opt in
--help)
usage
exit 0
;;
--snapshot)
SNAPSHOT="-snapshots"
;;
--version)
VERSION="$2"
shift
;;
--bintray-user)
BIN_USER=$2
shift
;;
--bintray-password)
BIN_PASS=$2
shift
;;
--bintray-url)
BIN_URL=$2
shift
;;
--bintray-deb-repo)
BIN_DEB_REPO=$2
shift
;;
--bintray-rpm-repo)
BIN_RPM_REPO=$2
shift
;;
--bintray-deb-options)
BIN_DEB_OPTIONS=$2
shift
;;
--bintray-rpm-options)
BIN_RPM_OPTIONS=$2
shift
;;
--deb-file)
if [[ ! -z ${FILELIST_DEB:-} ]]; then
echo "Error: --deb-file and --all-files or --all-debs are mutually exclusive"
usage
exit 4
fi
FILELIST_DEB="$2"
shift
;;
--rpm-file)
if [[ ! -z ${FILELIST_RPM:-} ]]; then
echo "Error: --rpm-file and --all-files or --all-rpms are mutually exclusive"
usage
exit 4
fi
FILELIST_RPM="$2"
shift
;;
--all-files)
if [[ (! -z ${FILELIST_DEB:-} ||
! -z ${FILELIST_RPM:-}) ]]; then
echo "Error: --all-files and --file, --all-debs or --all-rpms are mutually exclusive"
usage
exit 4
fi
FILELIST_DEB=$( echo *.deb )
FILELIST_RPM=$( echo *.rpm )
;;
--all-debs)
if [[ ! -z ${FILELIST_DEB:-} ]]; then
echo "Error: --all-debs and --deb-file or --all-files are mutually exclusive"
usage
exit 4
fi
FILELIST_DEB=$( echo *.deb )
;;
--all-rpms)
if [[ ! -z ${FILELIST_RPM:-} ]]; then
echo "Error: --all-rpms and --rpm-file or --all-files are mutually exclusive"
usage
exit 4
fi
FILELIST_RPM=$( echo *.rpm )
;;
--maven-path)
MVN_PATH=$2
;;
--*)
echo "Invalid option: '$opt'"
usage
exit 1
;;
*)
# end of long options
break
;;
esac
shift # do this after the case statements, so the first param is not lost!
done
# ensure maven is set, if not default
if [[ -z ${MVN_PATH:-} ]]; then
MVN_PATH="mvn"
fi
if [[ ( ! -z "${FILELIST_DEB:-}" || ! -z "${FILELIST_RPM:-}" ) && ! -z "${VERSION:-}" ]]; then
# Variables (I'd say global - but they're all like that in shell)
# TODO: Make these variables able to be passed in as options
MVN_URL=${MVN_URL:-"https://nexus.adaptavist.com/content/repositories/"}
MVN_REPOID=${MVN_REPOID:-"nexus"}
MVN_GROUPID=${MVN_GROUPID:-"com.adaptavist.mama.avst-app"}
MVN_REPO=${MVN_REPO:-"adaptavist"}
if [[ ! -z "${SNAPSHOT:-}" ]]; then
MVN_REPO="adaptavist${SNAPSHOT:-}"
VERSION="${VERSION}-SNAPSHOT"
fi
# default the bintray variables if they have not been passed in as args
BIN_URL=${BIN_URL:-"https://api.bintray.com/content/adaptavist"}
BIN_DEB_REPO=${BIN_DEB_REPO:-"ubuntu"}
BIN_RPM_REPO=${BIN_RPM_REPO:-"rpm"}
BIN_DEB_OPTIONS=${BIN_DEB_OPTIONS:-";publish=1;deb_component=main;deb_distribution=ubuntu;deb_architecture=i386,amd64"}
BIN_RPM_OPTIONS=${BIN_RPM_OPTIONS:-"?publish=1"}
echo "Publishing \"${FILELIST_DEB}\" artefacts"
for FILE in ${FILELIST_DEB}; do
#TODO: Only does .debs for now
echo "Publishing \"${FILE}\" to Nexus"
MVN_DESC=$( dpkg --info ${FILE} | fgrep Description | sed -e's/[^:]*: //' )
MVN_ARTIFACT=$( echo ${FILE} | sed -e's/_.*//' )
CMD="${MVN_PATH} org.apache.maven.plugins:maven-deploy-plugin:2.8.1:deploy-file \
-Durl=${MVN_URL}/${MVN_REPO} \
-DrepositoryId=${MVN_REPOID} \
-Dfile=${FILE} \
-DgroupId=${MVN_GROUPID} \
-DartifactId=${MVN_ARTIFACT} \
-Dversion=${VERSION} \
-Dclassifier=all \
-Dpackaging=deb \
-DgeneratePom=true \
-DgeneratePom.description=\"${MVN_DESC}\""
echo "Running: >>>>${CMD}<<<<<"
eval ${CMD}
# ** BINTRAY release **
# TODO: currently uploading a file for a package that does not exist on bintray will fail, add code to create if not present
# run bintray release if this is not a snapshot build
if [[ -z "${SNAPSHOT:-}" ]]; then
# if we have not got a bintray user/pass do not attempt the upload
if [[ ! -z ${BIN_USER:-} && ! -z ${BIN_PASS:-} ]]; then
echo "Publishing \"${FILE}\" to Bintray"
BINTRAY_PACKAGE=$( echo ${FILE} | sed -e's/_.*//' )
BIN_CMD="curl -T ${FILE} -u${BIN_USER}:${BIN_PASS} '${BIN_URL}/${BIN_DEB_REPO}/${BINTRAY_PACKAGE}/${VERSION}/${FILE}${BIN_DEB_OPTIONS}'"
echo "Running: >>>>${BIN_CMD}<<<<<"
eval $BIN_CMD
else
echo "SKipping publishing \"${FILE}\" to Bintray, as there are no auth details!"
fi
fi
done
echo "Publishing \"${FILELIST_RPM}\" artefacts"
for FILE in ${FILELIST_RPM}; do
echo "Publishing \"${FILE}\" to Nexus"
MVN_DESC=$( rpm -q -i -p ${FILE} | fgrep Summary | sed -e's/[^:]*: //' )
MVN_ARTIFACT=$( echo ${FILE} | sed -e's/_.*//' )
CMD="${MVN_PATH} org.apache.maven.plugins:maven-deploy-plugin:2.8.1:deploy-file \
-Durl=${MVN_URL}/${MVN_REPO} \
-DrepositoryId=${MVN_REPOID} \
-Dfile=${FILE} \
-DgroupId=${MVN_GROUPID} \
-DartifactId=${MVN_ARTIFACT} \
-Dversion=${VERSION} \
-Dclassifier=all \
-Dpackaging=rpm \
-DgeneratePom=true \
-DgeneratePom.description=\"${MVN_DESC}\""
echo "Running: >>>>${CMD}<<<<<"
eval ${CMD}
# ** BINTRAY release **
# TODO: currently uploading a file for a package that does not exist on bintray will fail, add code to create if not present
# run bintray release if this is not a snapshot build
if [[ -z "${SNAPSHOT:-}" ]]; then
# if we have not got a bintray user/pass do not attempt the upload
if [[ ! -z ${BIN_USER:-} && ! -z ${BIN_PASS:-} ]]; then
echo "Publishing \"${FILE}\" to Bintray"
BINTRAY_PACKAGE=$( echo ${FILE} | sed -e's/-[0-9].*//' )
BIN_CMD="curl -T ${FILE} -u${BIN_USER}:${BIN_PASS} '${BIN_URL}/${BIN_RPM_REPO}/${BINTRAY_PACKAGE}/${VERSION}/${FILE}${BIN_RPM_OPTIONS}'"
echo "Running: >>>>${BIN_CMD}<<<<<"
eval $BIN_CMD
else
echo "SKipping publishing \"${FILE}\" to Bintray, as there are no auth details!"
fi
fi
done
exit 0
else
echo "Invalid usage: filename and version must be provided"
usage
exit 10
fi