-
Notifications
You must be signed in to change notification settings - Fork 75
/
build_pkg.sh
executable file
·109 lines (97 loc) · 3.19 KB
/
build_pkg.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
#!/bin/bash
# Build a binary package of mercury. Supports deb and rpm.
usage() {
echo -e "$0 [ -h ] | [ -v version ] [ -t deb|rpm]\n"
echo -e "usage:\n"
echo "-h) prints usage information and exits"
echo "-v) specifies the version of the package to be built. MANDATORY and should be in the form of Major.Minor"
echo "-i) specifies the build iteration (optional)"
echo -e "-t) specifices which package to build (rpm, deb)\n"
}
while getopts "ht:v:i:" arg; do
case $arg in
h)
usage
exit
;;
v)
echo "-v was triggered with option ${OPTARG}"
VERSION=${OPTARG}
;;
i)
echo "-i was triggered with option ${OPTARG}"
ITERATION=${OPTARG}
;;
t)
echo "-t was triggered with option ${OPTARG}"
BUILDTYPE=${OPTARG}
;;
\?)
echo "error: invalid option -${OPTARG}"
usage
exit 1
;;
:)
echo "error: option -${OPTARG} requires an argument"
usage
exit 1
;;
esac
done
if [ $(($# + 1)) != "${OPTIND}" ]; then
echo "error: illegal option"
usage
exit 1
fi
if [ -z "$VERSION" ]; then
VERSION="$(cat VERSION)"
fi
if [ -z "$BUILDTYPE" ]; then
echo "-t deb|rpm must be specified" >&2
exit 1
fi
if [ -z "$ITERATION" ]; then
ITERATION="1"
fi
DESCRIPTION="Mercury: a tool for network metadata capture and analysis."
FPM_LINUX_OPTIONS="-v $VERSION --iteration $ITERATION\
-m mercury-interest@cisco.com --url https://github.com/cisco/mercury \
--after-install ./install_mercury/postinstall \
--config-files /etc/mercury/mercury.cfg \
--license BSD"
if [ "$BUILDTYPE" == "deb" ]; then
# determine libssl version, set SSL_LIB appropriately
#
if dpkg -s libssl1.1 > /dev/null; then
SSL_LIB=libssl1.1
PKG_NAME="mercury"
echo "found libssl1.1"
else
SSL_LIB=libssl3
PKG_NAME="mercury-u22"
echo "assuming libssl3"
fi
fpm -s dir -t deb -n $PKG_NAME $FPM_LINUX_OPTIONS \
--depends $SSL_LIB \
--depends zlib1g \
--deb-systemd ./install_mercury/mercury.service \
--deb-no-default-config-files \
--description "$DESCRIPTION" \
--after-remove ./install_mercury/postuninstall_remove \
--deb-after-purge ./install_mercury/postuninstall_purge \
./src/mercury=/usr/local/bin/ mercury.cfg=/etc/mercury/ \
./mercury=/usr/share/bash-completion/completions/ \
./resources/resources.tgz=/usr/local/share/mercury/
elif [ "$BUILDTYPE" == "rpm" ]; then
# note: we could detect libssl version here
fpm -s dir -t rpm -n mercury $FPM_LINUX_OPTIONS \
--depends 'libssl.so.10()(64bit)' \
--depends 'libz.so.1()(64bit)' \
--rpm-dist el7 \
--rpm-attr 775,mercury,mercury:/usr/local/var/mercury \
--description "$DESCRIPTION" \
--after-remove ./install_mercury/postuninstall_rpm \
./install_mercury/mercury.service=/usr/lib/systemd/system/ \
./src/mercury=/usr/local/bin/ mercury.cfg=/etc/mercury/ \
./resources/pyasn.db=/usr/local/share/mercury/ ./resources/fingerprint_db.json.gz=/usr/local/share/mercury/
fi