-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathbuild.sh
executable file
·104 lines (80 loc) · 2.39 KB
/
build.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
#!/bin/bash
#
#
# simple build script for dhcpy6d
#
#
OS=unknown
function get_os() {
if [ -f /etc/debian_version ]; then
OS=debian
elif [ -f /etc/redhat-release ]; then
yum install -y sudo which
OS=redhat
fi
}
function create_manpages() {
if ! which rst2man; then
if [ "$OS" == "debian" ]; then
sudo apt -y install python3-docutils
fi
if [ "$OS" == "redhat" ]; then
sudo yum -y install python3-docutils
fi
fi
echo "Creating manpages from RST files"
rst2man doc/dhcpy6d.rst man/man8/dhcpy6d.8
rst2man doc/dhcpy6d.conf.rst man/man5/dhcpy6d.conf.5
rst2man doc/dhcpy6d-clients.conf.rst man/man5/dhcpy6d-clients.conf.5
}
# find out where script runs at
get_os
if [ "$1" = "man" ]
then
echo "Re-generating man pages"
create_manpages
elif [ "$OS" == "debian" ]; then
echo "Building .deb package"
create_manpages
# install missing packages
if ! which debuild; then
sudo apt -y install build-essential devscripts dh-python dh-systemd python3-setuptools
fi
if [ ! -d /usr/share/doc/python3-all ]; then
sudo apt -y install python3-all
fi
debuild --no-tgz-check -- clean
debuild --no-tgz-check -- binary-indep
elif [ "$OS" == "redhat" ]; then
echo "Building .rpm package"
create_manpages
# install missing packages
if ! which rpmbuild; then
sudo yum -y install python3-devel python3-setuptools rpm-build
fi
TOPDIR=$HOME/dhcpy6d.$$
SPEC=redhat/dhcpy6d.spec
# create source folder for rpmbuild
mkdir -p $TOPDIR/SOURCES
# init needed in TOPDIR/SOURCES
cp -pf lib/systemd/system/dhcpy6d.service $TOPDIR/SOURCES/dhcpy6d
# use setup.py sdist build output to get package name
FILE=$(python3 setup.py sdist --dist-dir $TOPDIR/SOURCES | grep "creating dhcpy6d-" | head -n1 | cut -d" " -f2)
echo Source file: $FILE.tar.gz
# version
VERSION=$(echo $FILE | cut -d"-" -f 2)
# replace version in the spec file
sed -i "s|Version:.*|Version: $VERSION|" $SPEC
# workaround for less changes, but achieve build with new GitHub source
# TDDO: clean up that build process
cp ${TOPDIR}/SOURCES/${FILE}.tar.gz ${TOPDIR}/SOURCES/v${VERSION}.tar.gz
# finally build binary rpm
rpmbuild -bb --define "_topdir $TOPDIR" $SPEC
echo $TOPDIR
# get rpm file
cp -f $(find $TOPDIR/RPMS -name "$FILE-?.*noarch.rpm") .
# clean
#rm -rf $TOPDIR
else
echo "Package creation is only supported on Debian and RedHat derivatives."
fi