Project

General

Profile

build-smb.sh

Version pour eolebase - Philippe Caseiro, 11/07/2016 05:12 PM

Download (6.32 KB)

 
1
#!/bin/bash
2

    
3
#
4
# Build Samba
5
#
6

    
7
EOLERELEASE="2.6.1"
8

    
9
BUILDDEPDS="acl attr autoconf bison build-essential \
10
debhelper dnsutils docbook-xml docbook-xsl flex gdb krb5-user \
11
libacl1-dev libaio-dev libattr1-dev libblkid-dev libbsd-dev \
12
libcap-dev libcups2-dev libgnutls-dev libjson-perl \
13
libldap2-dev libncurses5-dev libpam0g-dev libparse-yapp-perl \
14
libpopt-dev libreadline-dev perl perl-modules-5.22 pkg-config \
15
python-all-dev python-dev python-dnspython python-crypto \
16
xsltproc zlib1g-dev libgpgme11-dev python-gpgme python-m2crypto"
17

    
18
SMBDEPENDS="eole-dhcp"
19
SCRIPTDEPENDS="git"
20

    
21
SMBPKG="samba samba-common samba-common-bin libwbclient0 samba-dsbd-modules samba-libs samba-vfs-modules python-samba"
22

    
23
VERSION="4.5.1"
24
SOURCENAME="samba-${VERSION}"
25
SOURCEFILE="${SOURCENAME}.tar.gz"
26
SOURCEURL="https://download.samba.org/pub/samba/stable/${SOURCEFILE}"
27
GITURL="https://dev-eole.ac-dijon.fr/git/eole-ad-dc.git"
28
CHECKSUM="9f77c562e9578ef68ea9b1f80bd2adebd93dc013"
29
WORKDIR="/tmp/samba-build"
30
ARCH=$(uname -i)
31

    
32
#BUILDOPT="${BUILDOPT} --prefix=/usr"
33
#BUILDOPT="${BUILDOPT} --mandir=/usr/share/man"
34
#BUILDOPT="${BUILDOPT} --sysconfdir=/etc"
35
#BUILDOPT="${BUILDOPT} --localstatedir=/var"
36
#BUILDOPT="${BUILDOPT} --with-piddir=/var/run"
37
#BUILDOPT="${BUILDOPT} --disable-rpath"
38
#BUILDOPT="${BUILDOPT} --disable-rpath-install"
39
#BUILDOPT="${BUILDOPT} --with-modulesdir=/usr/lib/${ARCH}-linux-gnu/samba/"
40
#BUILDOPT="${BUILDOPT} --libdir=/usr/lib/${ARCH}-linux-gnu/"
41
#BUILDOPT="${BUILDOPT} --bundled-libraries=NONE,pytevent,iniparser"
42
#BUILDOPT="${BUILDOPT} --builtin-libraries=ctdb,replace,ccan"
43
BUILDOPT="${BUILDOPT} --enable-fhs"
44
BUILDOPT="${BUILDOPT} --with-gpgme"
45

    
46
# Unsupported options
47
#BUILDOPT="${BUILDOPT} --disable-ntdb"
48

    
49
LOGFILE="${WORKDIR}/build-smb-$(date +'%d%m%Y-%H%M%S').log"
50

    
51
function buildDepends()
52
{
53
    run "apt-eole install ${BUILDDEPDS}"
54
    run "apt-eole install ${SMBDEPENDS}"
55
    return ${?}
56
}
57

    
58
function validateSum()
59
{
60
    local cfile=${1}
61
    local vsum=${2}
62
    local sum=$(sha1sum ${cfile} -b | cut -d ' ' -f 1)
63

    
64
    if [[ "${sum}" == "${vsum}" ]]
65
    then
66
        return 0
67
    else
68
        return 27
69
    fi
70
}
71

    
72
function getSources()
73
{
74
    if [[ -f "${WORKDIR}/${SOURCEFILE}" ]]
75
    then
76
        validateSum ${WORKDIR}/${SOURCEFILE} ${CHECKSUM}
77
        return ${?}
78
    else
79
        run "wget --directory-prefix ${WORKDIR} ${SOURCEURL}"
80
        if [[ ${?} -eq 0 ]]
81
        then
82
            validateSum ${WORKDIR}/${SOURCEFILE} ${CHECKSUM}
83
            return ${?}
84
        else
85
            return 1
86
        fi
87
    fi
88
}
89

    
90
function unpackSources()
91
{
92
    [[ ! -d ${WORKDIR}/sources ]] && mkdir -p ${WORKDIR}/sources/
93
	if [[ ! -d ${WORKDIR}/sources/${SOURCENAME} ]]
94
	then
95
		run "tar xzvf ${WORKDIR}/${SOURCEFILE} -C ${WORKDIR}/sources/"
96
		return ${?}
97
	fi
98
}
99

    
100
function removeSamba()
101
{
102
	for pkg in ${SMBPKG}
103
	do
104
		run "dpkg -r --force-all ${pkg}"
105
	done
106
}
107

    
108
function build()
109
{
110
    local cpu=$(nproc)
111
    local opts=""
112

    
113
    [[ ${cpu} -ge 2 ]] && opts="-j ${cpu}"
114

    
115
    cd ${WORKDIR}/sources/${SOURCENAME}
116
    run "./configure ${BUILDOPT}"
117
    run "make ${opts}"
118
	removeSamba
119
    run "make install"
120
}
121

    
122
function run()
123
{
124
    echo "Running : $@" | tee -a ${LOGFILE}
125
    $@ >> ${LOGFILE} 2>&1
126
    return ${?}
127
}
128

    
129
function error()
130
{
131
    echo "[ERROR][${1}"
132
    exit ${2}
133
}
134

    
135
function makeSeth()
136
{
137
    run "apt-eole install git"
138
	run "git clone ${GITURL} ${WORKDIR}/sources/eole-ad-dc"
139
	run "cd ${WORKDIR}/sources/eole-ad-dc"
140
	run "git checkout release/${EOLERELEASE}"
141
	DESTDIR='/'
142
	run "make install"
143
	run "cd ${WORKDIR}"
144
}
145

    
146
function addService()
147
{
148
	INIT="/etc/systemd/system/samba-ad-dc.service"
149
	WINBIND="/etc/systemd/system/winbind.service"
150
	cat <<EOF >${INIT}
151
[Unit]
152
Description=Samba4 AD DC
153
After=network.target remote-fs.target nss-lookup.target
154

    
155
[Service]
156
Type=forking
157
ExecStart=/usr/local/samba/sbin/samba -D -s /etc/samba/smb.conf
158
PIDFile=/usr/local/samba/var/run/samba/samba.pid
159

    
160
[Install]
161
WantedBy=multi-user.target
162
EOF
163

    
164
	run "systemctl daemon-reload"
165
	run "systemctl enable samba-ad-dc"
166
	run "systemctl start samba-ad-dc"
167
}
168

    
169
function fixInit()
170
{
171
	local initdir="/etc/init.d"
172
	local smb="smbd"
173
	local nmb="nmbd"
174
	local ad="samba-ad-dc"
175

    
176
	cat <<__EOF__ >${initdir}/${nmb}
177
#!/bin/sh
178
### BEGIN INIT INFO
179
# Provides:          nmbd
180
# Required-Start:    \$network \$local_fs \$remote_fs
181
# Required-Stop:     \$network \$local_fs \$remote_fs
182
# X-Start-Before:    smbd
183
# Default-Start:     2 3 4 5
184
# Default-Stop:      0 1 6
185
# Short-Description: start Samba NetBIOS nameserver (nmbd)
186
### END INIT INFO
187
exit 0
188
__EOF__
189

    
190
	chmod +x ${initdir}/${nmb}
191

    
192
	cat <<_EOF_ >${initdir}/${smb}
193
#!/bin/sh
194
### BEGIN INIT INFO
195
# Provides:          smbd
196
# Required-Start:    \$network \$local_fs \$remote_fs
197
# Required-Stop:     \$network \$local_fs \$remote_fs
198
# Default-Start:     2 3 4 5
199
# Default-Stop:      0 1 6
200
# Should-Start:      slapd cups
201
# Should-Stop:       slapd cups
202
# Short-Description: start Samba SMB/CIFS daemon (smbd)
203
### END INIT INFO
204
exit 0
205
_EOF_
206

    
207
	chmod +x ${initdir}/${smb}
208

    
209
	cat <<EOF >${initdir}/${ad}
210
#! /bin/sh
211
### BEGIN INIT INFO
212
# Provides:          samba-ad-dc
213
# Required-Start:    $network $local_fs $remote_fs
214
# Required-Stop:     $network $local_fs $remote_fs
215
# Default-Start:     2 3 4 5
216
# Default-Stop:      0 1 6
217
# Short-Description: start Samba daemons for the AD DC
218
### END INIT INFO
219
exit 0
220
EOF
221

    
222
	chmod +x ${initdir}/${ad}
223
}
224

    
225
function fixPath()
226
{
227
	smbsbin="/usr/local/samba/sbin"
228
	smbbin="/usr/local/samba/bin"
229
	smbetc="/usr/local/samba/etc/samba"
230
	for bin in $(ls ${smbsbin}/*)
231
	do
232
		ln -s ${bin} /usr/sbin
233
	done
234

    
235
	for bin in $(ls ${smbbin}/*)
236
	do
237
		ln -s ${bin} /usr/bin
238
	done
239

    
240
	ln -s ${smbetc} /etc
241
}
242

    
243
#
244
# Fixing eole script bug in 2.6.1 release
245
#
246
function fixLibSamba()
247
{
248
	local libfile="/usr/lib/eole/samba4.sh"
249

    
250
	sed -i '177s/"$ADMIN_PASSWORD"/"${ADMIN_PASSWORD}" \\/' ${libfile}
251
	return ${?}
252
}
253

    
254
#
255
# MAIN
256
#
257

    
258
[[ ! -d ${WORKDIR} ]] && mkdir -p ${WORKDIR}
259
cd ${WORKDIR}
260

    
261
# Install build depends
262
buildDepends
263
[[ ${?} -ne 0 ]] && error "Problem during deps installation" 1
264

    
265
# Download sources and validate
266
getSources
267
if [[ ${?} -eq 1 ]]
268
then
269
    error "Problem downloading the file from ${SOURCEURL}" 2
270
elif [[ ${?} -eq 27 ]]
271
then
272
    error "Downloaded file sum is not ${CHECKSUM}" 3
273
else
274
    unpackSources
275
    [[ ${?} -ne 0 ]] && error "Unpacking problem for file ${WORKDIR}/${SOURCEFILE}" 4
276
fi
277

    
278
build
279
[[ ${?} -ne 0  ]] && error "Error during build" 5
280

    
281
makeSeth
282
addService
283
fixInit
284
fixPath
285
fixLibSamba
286
[[ ${?} -ne 0  ]] && error "Error fixing samba4.sh lib" 10