forked from teonet-co/teonet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_rpm_inc.sh
executable file
·263 lines (234 loc) · 5.02 KB
/
make_rpm_inc.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/bin/sh
#
# File: make_rpm_inc.sh
# Author: Kirill Scherba <kirill@scherba.ru>
#
# Created on Aug 31, 2015, 2:39:11 PM
#
# Include make functions
# PWD=`pwd`
. "$PWD/sh/make_inc.sh"
# Parameters:
# @param $1 Version (required)
# @param $2 Library HI version
# @param $3 Library version
# @param $4 Release (default 1)
# @param $5 Architecture (default x86_64)
# @param $6 RPM subtype (default deb)
# @param $7 Package name (default libteonet)
# @param $8 Package description (default ...)
# Set global variables:
# VER=$1
# LIBRARY_HI_VERSION=$2
# LIBRARY_VERSION=$3
# RELEASE=$4
# ARCH=$5
# INST="yum install -y "
# RPM_SUBTYPE=$6
# RPM_DEV="rpm-build"
# VER=$1-$RELEASE
# PACKET_NAME=$7
# PACKET_DESCRIPTION=$8
check_param()
{
# The first parameter is required
# $1
if [ -z "$1" ]; then
echo The first parameter is required
exit 1
fi
VER=$1
# $2
if [ -z "$2" ]; then
LIBRARY_HI_VERSION=0
else
LIBRARY_HI_VERSION=$2
fi
# $3
if [ -z "$3" ]; then
LIBRARY_VERSION=0
else
LIBRARY_VERSION=$3
fi
# $4
if [ -z "$4" ]; then
RELEASE=1
else
RELEASE=$4
fi
# $5
if [ -z "$5" ]; then
ARCH="x86_64"
else
ARCH=$5
fi
# $6
if [ -z "$6" ]; then
# Default - Ubuntu
RPM_SUBTYPE="deb"
INST="sudo apt-get install -y "
RPM_DEV="rpm"
else
# Default - Ubuntu
RPM_SUBTYPE=$6
INST="sudo apt-get install -y "
RPM_DEV="rpm"
# Rehl
if [ "$RPM_SUBTYPE" = "yum" ]; then
INST="yum install -y "
RPM_DEV="rpm-build"
fi
# Suse
if [ "$RPM_SUBTYPE" = "zyp" ]; then
INST="zypper install -y "
RPM_DEV="rpm-devel"
fi
fi
# $7
if [ -z "$7" ]; then
PACKET_NAME="libteonet"
else
PACKET_NAME=$7
fi
# $8
if [ -z "$8" ]; then
PACKET_SUMMARY="Teonet library version $VER"
else
PACKET_SUMMARY=$8
fi
}
# Update and upgrade build host
# Parameters:
# @param $1 RPM_SUBTYPE="deb"
update_host()
{
#echo $ANSI_BROWN"Update and upgrade build host:"$ANSI_NONE
#echo ""
#if [ RPM_SUBTYPE="deb" ]; then
#sudo apt-get update
#sudo apt-get -y upgrade
#fi
echo ""
}
# Set RPM build environment
# Parameters:
# @param $1 RPMBUILD
set_rpmbuild_env()
{
if [ -d "$1" ]; then
rm -fr $1
fi
mkdir $1 #/{RPMS,SRPMS,BUILD,SOURCES,SPECS,tmp}
mkdir $1/RPMS
mkdir $1/SRPMS
mkdir $1/BUILD
mkdir $1/SOURCES
mkdir $1/SPECS
mkdir $1/tmp
cat <<EOF >~/.rpmmacros
%_topdir %(echo $HOME)/rpmbuild
%_tmppath %{_topdir}/tmp
EOF
}
# Create binary tarball and remove source folder
# Parameters:
# @param $1 tarball name
build_rpm_tarball()
{
echo $ANSI_BROWN"Create binary tarball:"$ANSI_NONE
echo ""
tar -zcvf $1.tar.gz $1/
rm -rf $1/
echo ""
}
# Copy tarball to the sources folder and create spec file
# @param $1 RPMBUILD
# @param $2 Tarball name
# @param $3 PACKET_NAME
# @param $4 VER
# @param $5 RELEASE
# @param $6 PACKET_SUMMARY
# @param $7 FILES
create_rpm_control()
{
echo $ANSI_BROWN"Create spec and copy files to the rpmbuild sources folder:"$ANSI_NONE
echo ""
# Move tarball file to the rpmbuild folder
mv -f $2.tar.gz $1/SOURCES
# Create spec file
cat <<EOF > $1/SPECS/$3.spec
# Don't try fancy stuff like debuginfo, which is useless on binary-only
# packages. Don't strip binary too
# Be sure buildpolicy set to do nothing
%define __spec_install_post %{nil}
%define debug_package %{nil}
%define __os_install_post %{_dbpath}/brp-compress
Summary: $6
Name: $3
Version: $4
Release: $5
License: GPL+
Group: Development/Tools
SOURCE0 : %{name}-%{version}.tar.gz
URL: http://repo.ksproject.org/
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
%description
%{summary}
%prep
%setup -q
%build
# Empty section.
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}
# in builddir
cp -a * %{buildroot}
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root,-)
$7
#%config(noreplace) %{_sysconfdir}/%{name}/%{name}.conf
%changelog
#* Thu Apr 24 2009 Elia Pinto <devzero2000@rpm5.org> 1.0-1
#- First Build
EOF
echo "done"
echo ""
}
# Build the source and the binary RPM
# Parameters:
# @param $1 $INST$RPM_DEV
# @param $2 RPMBUILD
# @param $3 PACKET_NAME
build_rpm()
{
echo $ANSI_BROWN"Build the source and the binary RPM:"$ANSI_NONE
echo ""
echo $1
$1
rpmbuild -ba $2/SPECS/$3.spec
echo ""
}
# Create RPM repository and add packages to this repository
# Parameters:
# @param $1 RPMBUILD
# @param $2 Repository folder with sub-folder
# @param $3 ARCH
# @param $4 INST
create_rpm_repo()
{
echo $ANSI_BROWN"Add REP package to local repository:"$ANSI_NONE
echo ""
if [ ! -d "$2/" ]; then
mkdir $2/
fi
if [ ! -d "$2/$3/" ]; then
mkdir $2/$3/
fi
cp $1/RPMS/$3/* $2/$3/
cp -r $1/SRPMS/ $2/
$4"createrepo"
createrepo $2/$3/
echo ""
}