forked from VictoriaMetrics/VictoriaMetrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package_deb.sh
executable file
·106 lines (70 loc) · 2.45 KB
/
package_deb.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
#!/bin/bash
ARCH="amd64"
if [[ $# -ge 1 ]]
then
ARCH="$1"
fi
# Map to Debian architecture
if [[ "$ARCH" == "amd64" ]]; then
DEB_ARCH=amd64
EXENAME_SRC="victoria-metrics-linux-amd64-prod"
elif [[ "$ARCH" == "arm64" ]]; then
DEB_ARCH=arm64
EXENAME_SRC="victoria-metrics-linux-arm64-prod"
elif [[ "$ARCH" == "arm" ]]; then
DEB_ARCH=armhf
EXENAME_SRC="victoria-metrics-linux-arm-prod"
else
echo "*** Unknown arch $ARCH"
exit 1
fi
PACKDIR="./package"
TEMPDIR="${PACKDIR}/temp-deb-${DEB_ARCH}"
EXENAME_DST="victoria-metrics-prod"
# Pull in version info
VERSION=`cat ${PACKDIR}/VAR_VERSION | perl -ne 'chomp and print'`
BUILD=`cat ${PACKDIR}/VAR_BUILD | perl -ne 'chomp and print'`
# Create directories
[[ -d "${TEMPDIR}" ]] && rm -rf "${TEMPDIR}"
mkdir -p "${TEMPDIR}" && echo "*** Created : ${TEMPDIR}"
mkdir -p "${TEMPDIR}/usr/bin/"
mkdir -p "${TEMPDIR}/lib/systemd/system/"
echo "*** Version : ${VERSION}-${BUILD}"
echo "*** Arch : ${DEB_ARCH}"
OUT_DEB="victoria-metrics_${VERSION}-${BUILD}_$DEB_ARCH.deb"
echo "*** Out .deb : ${OUT_DEB}"
# Copy the binary
cp "./bin/${EXENAME_SRC}" "${TEMPDIR}/usr/bin/${EXENAME_DST}"
# Copy supporting files
cp "${PACKDIR}/victoria-metrics.service" "${TEMPDIR}/lib/systemd/system/"
# Generate debian-binary
echo "2.0" > "${TEMPDIR}/debian-binary"
# Generate control
echo "Version: $VERSION-$BUILD" > "${TEMPDIR}/control"
echo "Installed-Size:" `du -sb "${TEMPDIR}" | awk '{print int($1/1024)}'` >> "${TEMPDIR}/control"
echo "Architecture: $DEB_ARCH" >> "${TEMPDIR}/control"
cat "${PACKDIR}/deb/control" >> "${TEMPDIR}/control"
# Copy conffile
cp "${PACKDIR}/deb/conffile" "${TEMPDIR}/conffile"
# Copy postinst and postrm
cp "${PACKDIR}/deb/postinst" "${TEMPDIR}/postinst"
cp "${PACKDIR}/deb/prerm" "${TEMPDIR}/prerm"
cp "${PACKDIR}/deb/postrm" "${TEMPDIR}/postrm"
(
# Generate md5 sums
cd "${TEMPDIR}"
find ./usr ./lib -type f | while read i ; do
md5sum "$i" | sed 's/\.\///g' >> md5sums
done
# Archive control
chmod 644 control md5sums
chmod 755 postinst postrm prerm
fakeroot -- tar -c --xz -f ./control.tar.xz ./control ./md5sums ./postinst ./prerm ./postrm
# Archive data
fakeroot -- tar -c --xz -f ./data.tar.xz ./usr ./lib
# Make final archive
fakeroot -- ar -cr "${OUT_DEB}" debian-binary control.tar.xz data.tar.xz
)
ls -lh "${TEMPDIR}/${OUT_DEB}"
cp "${TEMPDIR}/${OUT_DEB}" "${PACKDIR}"
echo "*** Created : ${PACKDIR}/${OUT_DEB}"