-
Notifications
You must be signed in to change notification settings - Fork 47
/
create_packages
executable file
·149 lines (120 loc) · 3.84 KB
/
create_packages
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
#!/bin/bash
######################################################################
VERSION="$(git describe --abbrev=0 --tags)"
if [ -z "$VERSION" ];then
echo "ERROR: unable to find a tag"
exit 100
fi
######################################################################
### HELPERS
prepare(){
PY="$1"
echo "***************************************************************************************************************************************"
echo "PREPARE"
set -e
set -x
umask 0002
mkdir -p -m 755 ${TMPDIR}/usr/bin/
cp -av ${SDIR}/tools/zabbix_* ${TMPDIR}/usr/bin/
chmod 755 ${TMPDIR}/usr/bin/*
if [ "$PY" = "2" ];then
sed -i '~s,#!/usr/bin/env python3,#!/usr/bin/env python,' ${TMPDIR}/usr/bin/*
fi
mkdir -p -m 755 ${TMPDIR}/usr/share/zabbix-agent-extensions/include.d/
cp -av ${SDIR}/agent-config/zabbix_* ${TMPDIR}/usr/share/zabbix-agent-extensions/include.d/
sed -i "~s,VERSION TO BE REPLACED,${VERSION}," ${TMPDIR}/usr/share/zabbix-agent-extensions/include.d/zabbix_agent_extensions.conf
chmod 644 ${TMPDIR}/usr/share/zabbix-agent-extensions/include.d/*
mkdir -p -m 755 ${TMPDIR}/usr/share/zabbix/
cp -av ${SDIR}/check_payloads/* ${TMPDIR}/usr/share/zabbix/
chmod 644 ${TMPDIR}/usr/share/zabbix/*
mkdir -p -m 755 ${TMPDIR}/usr/share/man/man8/
gzip ${SDIR}/man/httpjson-queryagent.8 -c > ${TMPDIR}/usr/share/man/man8/httpjson-queryagent.8.gz
chmod 644 ${TMPDIR}/usr/share/man/man8/*
mkdir -p -m 755 ${TMPDIR}/etc/sudoers.d
cp ${SDIR}/sudoers ${TMPDIR}/etc/sudoers.d/zabbix
chmod 0440 ${TMPDIR}/etc/sudoers.d/*
mkdir -p -m 755 ${TMPDIR}/etc/pam.d
cp ${SDIR}/pam-config ${TMPDIR}/etc/pam.d/zabbix-agent-extensions
chmod 0440 ${TMPDIR}/etc/pam.d/*
mkdir -p -m 755 ${TMPDIR}/var/cache/zabbix
set +x
set +e
}
create_package(){
TYPE="$1"
PY="$2"
if [ "$PY" = "3" ];then
SUFFIX=""
else
SUFFIX="-python2"
fi
echo "***************************************************************************************************************************************"
echo "PACKAGE TYPE: $TYPE"
echo
set -x
fpm -s dir -t $TYPE \
-n "zabbix-agent-extensions$SUFFIX" \
--license GPLv2 \
--verbose \
-a all \
--deb-no-default-config-files \
--deb-group root \
--rpm-group root \
--deb-user root \
--rpm-user root \
--deb-user root \
-m "Marc Schoechlin <[email protected]>" \
--url "https://github.com/scoopex/zabbix-agent-extensions" \
--after-install ${SDIR}/postinstall \
-v $VERSION -C $TMPDIR
set +x
if [ "$TYPE" = "deb" ];then
dpkg -c zabbix-agent-extensions${SUFFIX}_${VERSION}_all.deb
RET="$?"
elif [ "$TYPE" = "rpm" ];then
rpm -qlp zabbix-agent-extensions${SUFFIX}-${VERSION}-1.noarch.rpm
RET="$?"
fi
if [ "$RET" != "0" ];then
echo "ERROR: error on creation of $TYPE package"
exit 1
fi
}
create_docu(){
cd $SDIR/../zabbix_templates/3.2-outdated
./create_template_documentation
cd $SDIR/../zabbix_templates/3.4-outdated
./create_template_documentation
cd $SDIR/../zabbix_templates/4.4-outdated
./create_template_documentation
}
######################################################################
### MAIN
if [ -z "$1" ];then
echo "$0 <version>"
fi
SDIR="$(dirname $(readlink -f $0))/extension-files"
for P in $HOME/.gem/ruby/*/bin/fpm;do
P="$(dirname $P)"
export PATH="$P:$PATH"
done
if ( ! (type -a fpm >/dev/null 2>&1 ) );then
echo "Unable to find 'fpm'"
exit 100
fi
echo "CREATING VERSION: $VERSION"
rm -rf zabbix-agent-extensions_*.deb zabbix-agent-extensions*.rpm
TMPDIR="$(mktemp -d)"
trap "rm -rf $TMPDIR" EXIT TERM INT
prepare 3
create_package deb 3
create_package rpm 3
rm -rf $TMPDIR
trap "" EXIT TERM INT
TMPDIR="$(mktemp -d)"
trap "rm -rf $TMPDIR" EXIT TERM INT
prepare 2
create_package deb 2
create_package rpm 2
create_docu
exit 0