forked from nbrownus/kafka-deb-packaging
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild_kafka.sh
executable file
·166 lines (140 loc) · 4.2 KB
/
build_kafka.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
#!/bin/bash
set -e
set -u
PKG_NAME="kafka"
VERSION="0.8.1"
DESCRIPTION="Apache Kafka is a distributed publish-subscribe messaging system."
URL="https://kafka.apache.org/"
ARCH="all"
SECTION="misc"
LICENSE="Apache Software License 2.0"
SRC_PACKAGE="kafka-${VERSION}-src.tgz"
DOWNLOAD_URL="https://dist.apache.org/repos/dist/release/kafka/${VERSION}/${SRC_PACKAGE}"
ORIG_DIR="$(pwd)"
BUILD_VERSION=
SCALA_VERSION="2.8.0"
usage() {
echo "Usage: $0 -b \"<build version>\" -h"
echo " -h Prints this message"
echo " -b Build version string, ex: ubuntu1"
}
while getopts ":b:h" NAME; do
case "$NAME" in
b)
BUILD_VERSION=${OPTARG}
;;
h)
usage
exit 0
;;
*)
echo "Unkown option: $OPTARG"
echo ""
usage
exit 1
;;
esac
done
if [ "x$BUILD_VERSION" = "x" ]; then
echo "No build version was supplied"
echo ""
usage
exit 1
fi
#_ MAIN _#
function cleanup() {
rm -rf "${PKG_NAME}*.deb"
}
function bootstrap() {
if [[ ! -f "$SRC_PACKAGE" ]]; then
wget "$DOWNLOAD_URL"
fi
mkdir -p tmp && pushd tmp
rm -rf kafka
mkdir -p kafka
cd kafka
mkdir -p build/opt/kafka # for package
mkdir -p build/opt/kafka/libs build/opt/kafka/bin build/opt/kafka/config
mkdir -p build/var/lib/kafka # for kafka messages storage
mkdir -p build/etc/default
#mkdir -p build/etc/init # for upstart conf on ubuntu
mkdir -p build/etc/init.d # for init script on debian
mkdir -p build/var/log/kafka # for log files
# used a link to /opt/kafka/config instead of mkdir -p build/etc/kafka
# used /var/run/ to store kafka.pid
}
# gets sources, builds project, forms the ../build, leaves to initial folder after
function build_from_sources() {
tar zxf "${ORIG_DIR}/${SRC_PACKAGE}"
pushd "kafka-${VERSION}-src"
./gradlew -PscalaVersion=${SCALA_VERSION} clean
./gradlew -PscalaVersion=${SCALA_VERSION} jar
# KAFKA_HEAP_OPTS is reset to default.
# The patch should fix the ./logs creation though.
# TODO: fix and apply patch
# patch -p0 < "${ORIG_DIR}/kafka-bin.patch"
## populate the /opt/kafka folder structure
# libs
cp -rp core/build/libs/* ../build/opt/kafka/libs
cp -rp core/build/dependant-libs-${SCALA_VERSION}/* ../build/opt/kafka/libs
# config
cp -rp config ../build/opt/kafka/
mv ../build/opt/kafka/config/log4j.properties ../build/opt/kafka/config/log4j.properties.orig
cp ${ORIG_DIR}/log4j.properties ../build/opt/kafka/config
# bin (we don't need windows binaries)
cp bin/*.sh ../build/opt/kafka/bin
# LICENSE and NOTICE
mv LICENSE ../build/opt/kafka/
mv NOTICE ../build/opt/kafka
popd
}
function build_from_binary(){
BINARY_PACKAGE=kafka_2.9.2-0.8.1
wget https://dist.apache.org/repos/dist/release/kafka/0.8.1/${BINARY_PACKAGE}.tgz
tar -xzf ${BINARY_PACKAGE}.tgz
mv ${BINARY_PACKAGE}/* build/opt/kafka
# we don't need windows binaries in deb package
# symbolic link to configs is created in postinst script
}
function apply_configs(){
cp "${ORIG_DIR}/etc/default/kafka" "build/etc/default/kafka"
# Service
cp "${ORIG_DIR}/etc/init.d/kafka" "build/etc/init.d/kafka"
# TODO: Ubuntu option?
#cp "${ORIG_DIR}/kafka-broker.upstart.conf" "build/etc/init/kafka-broker.conf"
cp ${ORIG_DIR}/log4j.properties build/opt/kafka/config/
# symlink from /etc/kafka -> /opt/kafka/config is made in postinst
}
function mkdeb() {
cd build
fpm -t deb \
-n "$PKG_NAME" \
-v "${VERSION}-${BUILD_VERSION}" \
--description "$DESCRIPTION" \
--url="$URL" \
-a "$ARCH" \
--category "$SECTION" \
--vendor "" \
--license "$LICENSE" \
--before-install ${ORIG_DIR}/kafka.preinst \
--after-install ${ORIG_DIR}/kafka.postinst \
--after-remove ${ORIG_DIR}/kafka.postrm \
-m "${USER}" \
--config-files /etc/default/kafka \
--config-files /etc/init.d/kafka \
--prefix=/ \
-d "openjdk-7-jre" \
-s dir \
-- .
mv kafka*.deb ${ORIG_DIR}
popd
}
function main() {
cleanup
bootstrap
build_from_sources
#build_from_binary
apply_configs
mkdeb
}
main