forked from jbraeuer/nexus-oss-rpms
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathnexus-oss-rpm
executable file
·86 lines (76 loc) · 1.87 KB
/
nexus-oss-rpm
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
#!/bin/bash
SCRIPT=$(basename ${0})
help() {
echo ""
echo "Script to build Sonatype Nexus OSS RPMs"
echo ""
echo "Syntax: "
echo ""
echo "${SCRIPT} [-v <MAJOR_VERSION>]"
echo ""
echo "Where: "
echo " -v Sonatype Nexus OSS major version (currently 2 or 3 supported)."
echo " 2 is default if parameter is not present"
echo ""
}
function check_create_dir() {
if [ ! -d "./${1}" ]; then
mkdir "./${1}"
fi
}
function create_build_env() {
check_create_dir BUILD
check_create_dir BUILDROOT
check_create_dir RPMS
check_create_dir SOURCES
check_create_dir SPECS
check_create_dir SRPMS
}
function get_sources() {
if [ ! -f "./SOURCES/${2}" ]; then
echo "Downloading ${1} to "./SOURCES/${2}"..."
curl -L "${1}" -o "./SOURCES/${2}"
fi
}
function build_rpm() {
rpmbuild --quiet --define "_topdir `pwd`" -ba "${1}"
return ${?}
}
get_url_source_from_spec() {
local NAME=$(sed -rn 's/^Name:\s*(.*)/\1/p' ${1})
echo $(sed -rn 's/^Source0:\s*(.*)/\1/p' ${1}|sed -e "s/%{name}/${NAME}/g")
}
while getopts ":v:h" opts; do
case "${opts}" in
v) VERSION=${OPTARG};;
h) help
exit 0;;
*) echo "Invalid syntax. Use ${SCRIPT} -h"
exit 1;;
esac
done
shift $((OPTIND-1))
case ${VERSION} in
3) SPEC='SPECS/nexus3-oss.spec'
URL="$(get_url_source_from_spec ${SPEC})"
TGZ="$(basename ${URL})";;
2|'') SPEC='SPECS/nexus-oss.spec'
URL="$(get_url_source_from_spec ${SPEC})"
TGZ="$(basename ${URL})";;
*) echo "Invalid version. Use ${SCRIPT} -h"
exit 1;;
esac
echo "### Creating build environment..."
create_build_env
echo "### Downloading sources..."
get_sources ${URL} ${TGZ}
echo "### Building RPMs..."
build_rpm ${SPEC}
if [ $? -eq 0 ]; then
echo "### Binary RPMs available at ${PWD}/RPMS"
echo "### Source RPMs available at ${PWD}/SRPMS"
exit 0
else
echo There are errors. Check your log.
exit 1
fi