This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
/
cups.SlackBuild
executable file
·487 lines (421 loc) · 14.5 KB
/
cups.SlackBuild
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
#!/bin/sh
#-- cups for Slackware --
# Build script by Phantom X <megaphantomx at bol.com.br>
# Suggested usage: $ cups.SlackBuild 2>&1 | tee build.log
#--
# Copyright 2008-2014 Phantom X, Goiania, Brazil.
# Copyright 2008, 2009, 2010 Patrick J. Volkerding, Sebeka, Minnesota, USA
# Copyright 2006 Martijn Dekker, Groningen, Netherlands.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# http://www.cups.org/
PACKAGER_ID=${PACKAGER_ID:-$USER}
PACKAGER=${PACKAGER:-$USER@$HOSTNAME}
# Set YES for native build with gcc >= 4.2
SB_NATIVE=${SB_NATIVE:-NO}
# Set to YES to replicate slackbuild and patches
SB_REP=${SB_REP:-YES}
CWD=$(pwd)
TMP=${TMP:-/tmp}
if [ ! -d ${TMP} ]; then
mkdir -p ${TMP}
fi
NAME=cups
PKG=${PKG:-${TMP}/package-${NAME}}
VERSION=${VERSION:-2.0.0}
if [ "${SB_NATIVE}" = "YES" ] ;then
ARCH=${ARCH:-$(uname -m)}
else
ARCH=${ARCH:-x86_64}
fi
if [ "${ARCH}" = "x86_64" ] ;then
SLKTARGET=${SLKTARGET:-x86_64}
else
SLKTARGET=${SLKTARGET:-i486}
fi
SLKDTARGET=${SLKDTARGET:-slackware}
BUILD=${BUILD:-1}
NJOBS=${NJOBS:-$(( $(getconf _NPROCESSORS_ONLN) + 1 ))}
DOCDIR=${PKG}/usr/doc/${NAME}-${VERSION}
SBDIR=${PKG}/usr/src/slackbuilds/${NAME}
PKGDEST=${PKGDEST:-${CWD}}
PKGFORMAT=${PKGFORMAT:-txz}
PKGNAME=${NAME}-$(echo ${VERSION} | tr - . )-${ARCH}-${BUILD}${PACKAGER_ID}
# Set to YES to enable dnssd support (with avahi)
SB_DNSSD=${SB_DNSSD:-YES}
# Set to YES to enable krb gssapi support
SB_KRB5=${SB_KRB5:-NO}
# Set to YES to enable pam support
SB_PAM=${SB_PAM:-YES}
# Set to YES to enable systemd socket and journal support
SB_SYSTEMD=${SB_SYSTEMD:-YES}
DATE=$(LC_ALL=C date +%d-%b-%Y)
grep --quiet '^lp:' /etc/group && SB_HGROUP=1
SRCDIR=${NAME}-${VERSION}
SRCARCHIVE=${SRCDIR}-source.tar.bz2
DL_PROG=${DL_PROG:-wget}
DL_TO=${DL_TO:-5}
DL_OPTS=${DL_OPTS:-"--timeout=${DL_TO}"}
DL_URL="http://www.cups.org/software/${VERSION}/${SRCARCHIVE}"
# if source is not present, download in source rootdir if possible
test -r ${CWD}/${SRCARCHIVE} || ${DL_PROG} ${DL_OPTS} ${DL_URL} || exit 1
if [ "${SB_NATIVE}" = "YES" ] ;then
SLKCFLAGS="-O2 -march=native -mtune=native -pipe"
[ "${SB_ECFLAGS}" ] && SLKCFLAGS="${SLKCFLAGS} ${SB_ECFLAGS}"
else
case "${ARCH}" in
i[3-6]86) SLKCFLAGS="-O2 -march=${ARCH} -mtune=i686"
;;
x86_64) SLKCFLAGS="-O2 -fPIC"
;;
s390|*) SLKCFLAGS="-O2"
;;
esac
fi
if [ "${ARCH}" = "x86_64" ] ;then
LIBDIRSUFFIX="64"
SLKCFLAGS="${SLKCFLAGS} -fPIC"
else
LIBDIRSUFFIX=""
fi
if [ -d ${PKG} ]; then
# Clean up a previous build
rm -rf ${PKG}
fi
mkdir -p ${PKG}
cd ${TMP}
rm -rf ${SRCDIR}
tar -xvf ${CWD}/${SRCARCHIVE} || exit 1
cd ${SRCDIR} || exit 1
chmod -R u+w,go+r-w,a-s .
if [ -r ${CWD}/apply-patches.sh ]; then
. ${CWD}/apply-patches.sh
fi
# We want to use the PDF workflow in principle with one exception when the input
# is PostScript and the printer is a native PostScript printer.
# To avoid the PS -> PDF -> PS conversion (costs 66),
# set the cost factor of pstops to 65.
# This forth-and-back conversion sometimes produces PostScript files which are
# too big for the printer's memory resulting in not getting printed.
sed -i -r -e '/\spstops$/ { s/66/65/ }' conf/mime.convs.in
sed -i -e '1iMaxLogSize 0' conf/cupsd.conf.in
# Log to the system journal by default (bug #1078781).
sed -i -e 's,^ErrorLog .*$,ErrorLog journal,' conf/cups-files.conf.in
# Let's look at the compilation command lines.
sed -i -e "s,^.SILENT:,," Makedefs.in
# No overlinking!
sed -i -e '/EXTLINKCUPS/s| $LIBS||g' cups-config.in || exit 1
if [ "${SB_SYSTEMD}" = "YES" ] ;then
sed -i \
-e 's|libsystemd-daemon|libsystemd|g' \
-e 's|libsystemd-journal|libsystemd|g' \
config-scripts/cups-startup.m4 || exit 1
fi
# Rebuild configure script for --enable-avahi.
aclocal -I config-scripts
autoconf -I config-scripts || exit 1
unset SB_DNSSDOPTS SB_KRB5OPTS SB_PAMOPTS
[ "${SB_DNSSD}" = "YES" ] && SB_DNSSDOPTS='--enable-dnssd'
[ "${SB_KRB5}" = "YES" ] || SB_KRB5OPTS='--disable-gssapi'
[ "${SB_PAM}" = "YES" ] || SB_PAMOPTS='--disable-pam'
CC="gcc" \
CXX="g++" \
CFLAGS="${SLKCFLAGS} -fstack-protector-all -DLDAP_DEPRECATED=1" \
CXXFLAGS="${SLKCFLAGS}" \
./configure \
--prefix=/usr \
--libdir=/usr/lib${LIBDIRSUFFIX} \
--sysconfdir=/etc \
--localstatedir=/var \
--infodir=/usr/info \
--mandir=/usr/man \
--enable-debug \
--enable-relro \
--enable-ssl \
--enable-openssl=yes \
--enable-gnutls=no \
--enable-cdsassl=no \
--enable-webif \
${SB_KRB5OPTS} \
--docdir=/usr/doc \
--without-php \
${SB_PAMOPTS} ${SB_DNSSDOPTS} \
--with-cupsd-file-perm=0755 \
--with-log-file-perm=0600 \
--build=${SLKTARGET}-${SLKDTARGET}-linux || exit 1
make -j${NJOBS} || make || exit 1
mkdir -p ${PKG}/etc/cups
mkdir -p ${PKG}/var/spool
make install BUILDROOT=${PKG} || exit 1
find ${PKG} | xargs file | grep -e "executable" -e "shared object" | grep ELF \
| cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
rm -rf ${PKG}/usr/man/cat? ${PKG}/usr/man/*/cat?
# these are shipped with cups-filters
rm -rf ${PKG}/usr/share/cups/banners
rm -f ${PKG}/usr/share/cups/data/testprint
mkdir -p ${PKG}/usr/share/ppd
find ${PKG}/usr/share/cups/model -name "*.ppd" |xargs gzip -n9f
# I've added so many things like /etc/init.d/ to Slackware that CUPS
# is now installing init scripts to the Red Hat locations. We'll move
# them to the usual locations:
mkdir -p ${PKG}/etc/rc.d
# Handle this as a config file, and non-executable in a default install:
mv ${PKG}/etc/init.d/cups ${PKG}/etc/rc.d/rc.cups.new
chmod 644 ${PKG}/etc/rc.d/rc.cups.new
# Clear out the additions:
rm -rf ${PKG}/etc/init.d ${PKG}/etc/rc{0,2,3,5}.d
mkdir -p ${PKG}/lib/systemd/system
install -pm0644 ${CWD}/systemd/*.{service,socket} ${PKG}/lib/systemd/system/ || exit 1
for i in path service socket ;do
mv ${PKG}/lib/systemd/system/org.cups.cupsd.${i} ${PKG}/lib/systemd/system/cups.${i} || exit 1
done
# install /usr/lib/tmpfiles.d/cups.conf (bug #656566)
mkdir -p ${PKG}/usr/lib/tmpfiles.d
cat > ${PKG}/usr/lib/tmpfiles.d/cups.conf <<EOF
d /run/cups 0755 root lp -
d /run/cups/certs 0511 lp sys -
d /var/spool/cups/tmp - - - 30d
EOF
# /usr/lib/tmpfiles.d/cups-lp.conf (bug #812641)
cat > ${PKG}/usr/lib/tmpfiles.d/cups-lp.conf <<EOF
# This file is part of cups.
#
# Legacy parallel port character device nodes, to trigger the
# auto-loading of the kernel module on access.
#
# See tmpfiles.d(5) for details
c /dev/lp0 0660 root lp - 6:0
c /dev/lp1 0660 root lp - 6:1
c /dev/lp2 0660 root lp - 6:2
c /dev/lp3 0660 root lp - 6:3
EOF
# I'm not sure if overwriting this blindly could have ill effects,
# but it never hurts to play it safe. According to the dbus-daemon
# manpage, only files ending in .conf will be used, so there won't
# be any unintended doubling up.
mv ${PKG}/etc/dbus-1/system.d/cups.conf \
${PKG}/etc/dbus-1/system.d/cups.conf.new || exit 1
# For full CUPS SMB support, you'll need to install the cups-samba
# package from the source in this directory. There's no easy way
# to add that to a package build, and the requests aren't pouring in,
# so you'll have to install it yourself. It's easy to do.
# However, this will get you the most useful SMB support for free.
# Thanks to Boris Kurktchiev for the tip. :-)
( cd ${PKG}/usr/lib${LIBDIRSUFFIX}/cups/backend
if [ ! -e smb ]; then
ln -sf /usr/bin/smbspool smb
fi
ln -s http https
)
# Apply no-clobber fix to conffiles:
( cd ${PKG}/etc/cups
for file in * ; do
if [ -f ${file} ]; then
mv ${file} ${file}.new
fi
done
)
# Use symlinks to certain binaries so that CUPS and LPRng can coexist:
SUFFIX=cups
for file in \
usr/bin/cancel \
usr/bin/lp \
usr/bin/lpq \
usr/bin/lpr \
usr/bin/lprm \
usr/bin/lpstat \
usr/sbin/lpc ; do
( cd ${PKG}
mv ${file} ${file}-${SUFFIX}
( cd $(dirname ${file}) ; ln -sf $(basename ${file})-${SUFFIX} $(basename ${file}) )
)
done
mkdir -p ${PKG}/etc/cron.daily
cat > ${PKG}/etc/cron.daily/${NAME} <<'EOF'
#!/bin/sh
[ -x /usr/sbin/tmpwatch ] || exit 0
for d in /var/spool/cups/tmp
do
if [ -d "$d" ]; then
/usr/sbin/tmpwatch -f 720 "$d"
fi
done
exit 0
EOF
chmod 0755 ${PKG}/etc/cron.daily/${NAME} || exit 1
mkdir -p ${PKG}/etc/logrotate.d
cat > ${PKG}/etc/logrotate.d/${NAME}.new <<'EOF'
/var/log/cups/*_log {
missingok
notifempty
sharedscripts
}
EOF
if [ "${SB_PAM}" = "YES" ] ;then
mv ${PKG}/etc/pam.d/cups ${PKG}/etc/pam.d/cups.new || exit 1
fi
# Add a documentation directory:
mkdir -p ${DOCDIR}
if [ -d ${PKG}/usr/share/doc ] ;then
mv ${PKG}/usr/share/doc/*/* ${DOCDIR}/
rm -rf ${PKG}/usr/share/doc
rmdir ${PKG}/usr/share
fi
cp -a \
AUTHORS COPYING ChangeLog LICENSE README NEWS THANKS TODO ${CWD}/ChangeLog.SB \
${DOCDIR}/
ln -sf cups-${VERSION} ${PKG}/usr/doc/${NAME}
find ${DOCDIR}/ -name "*.pdf" -exec rm -f {} \;
find ${DOCDIR}/ -type d -print0 | xargs -0 chmod 0755
find ${DOCDIR}/ -type f -print0 | xargs -0 chmod 0644
# Compress and link manpages, if any:
if [ -d ${PKG}/usr/share/man ]; then
mv ${PKG}/usr/share/man ${PKG}/usr/man
rmdir ${PKG}/usr/share
fi
find ${PKG}/usr/man -type d -name "cat*" | xargs rm -rf
if [ -d ${PKG}/usr/man ]; then
( cd ${PKG}/usr/man
for manpagedir in $(find . -type d -name "man*") ; do
( cd ${manpagedir}
for eachpage in $( find . -type l -maxdepth 1) ; do
ln -s $( readlink ${eachpage} ).gz ${eachpage}.gz
rm -f ${eachpage}
done
gzip -9 *.?
# Prevent errors
rm -f *.gz.gz
)
done
)
fi
# Now fix the associated man pages:
mv ${PKG}/usr/man/man1/cancel.1.gz ${PKG}/usr/man/man1/cancel-${SUFFIX}.1.gz
mv ${PKG}/usr/man/man1/lp.1.gz ${PKG}/usr/man/man1/lp-${SUFFIX}.1.gz
mv ${PKG}/usr/man/man1/lpq.1.gz ${PKG}/usr/man/man1/lpq-${SUFFIX}.1.gz
mv ${PKG}/usr/man/man1/lpr.1.gz ${PKG}/usr/man/man1/lpr-${SUFFIX}.1.gz
mv ${PKG}/usr/man/man1/lprm.1.gz ${PKG}/usr/man/man1/lprm-${SUFFIX}.1.gz
mv ${PKG}/usr/man/man1/lpstat.1.gz ${PKG}/usr/man/man1/lpstat-${SUFFIX}.1.gz
mv ${PKG}/usr/man/man8/lpc.8.gz ${PKG}/usr/man/man8/lpc-${SUFFIX}.8.gz
( cd ${PKG}/usr/man/man1
ln -sf cancel-${SUFFIX}.1.gz cancel.1.gz
ln -sf lp-${SUFFIX}.1.gz lp.1.gz
ln -sf lpq-${SUFFIX}.1.gz lpq.1.gz
ln -sf lpr-${SUFFIX}.1.gz lpr.1.gz
ln -sf lprm-${SUFFIX}.1.gz lprm.1.gz
ln -sf lpstat-${SUFFIX}.1.gz lpstat.1.gz
)
( cd ${PKG}/usr/man/man8
ln -sf lpc-${SUFFIX}.8.gz lpc.8.gz
)
mkdir -p ${PKG}/install
cat ${CWD}/slack-desc > ${PKG}/install/slack-desc
cat ${CWD}/slack-required > ${PKG}/install/slack-required
cat > ${PKG}/install/doinst.sh <<EOF
# Figure out our root directory
ROOTDIR=\$(pwd)
unset CHROOT
if test "\${ROOTDIR}" != "/"; then
CHROOT="chroot \${ROOTDIR} "
ROOTDIR="\${ROOTDIR}/"
fi
config() {
NEW="\$1"
OLD="\$(dirname \$NEW)/\$(basename \$NEW .new)"
# If there's no config file by that name, mv it over:
if [ ! -r \$OLD ]; then
mv \$NEW \$OLD
elif [ "\$(cat \$OLD | md5sum)" = "\$(cat \$NEW | md5sum)" ]; then
# toss the redundant copy
rm \$NEW
fi
# Otherwise, we leave the .new copy for the admin to consider...
}
# Keep same perms on rc.${NAME}.new:
if [ -r etc/rc.d/rc.${NAME} -a -r etc/rc.d/rc.${NAME}.new ]; then
chmod --reference=etc/rc.d/rc.${NAME} etc/rc.d/rc.${NAME}.new
fi
## List of conf files to check. The conf files in your package should end in .new
EOF
( cd ${PKG}
find etc/ -name *.new -exec echo config {} ';' | sort >> ${PKG}/install/doinst.sh
echo >> ${PKG}/install/doinst.sh
)
cat >> ${PKG}/install/doinst.sh <<'EOF'
# Fix permissions
${CHROOT} /bin/chown root.lp /var/spool/cups
${CHROOT} /bin/chown root.lp /var/spool/cups/tmp
${CHROOT} /bin/chown root.lp /var/cache/cups
${CHROOT} /bin/chown root.lp /var/cache/cups/rss
${CHROOT} /bin/chown root.lp /etc/cups
${CHROOT} /bin/chown root.lp /etc/cups/ppd
${CHROOT} /bin/chown root.lp /etc/cups/cupsd.conf.default*
${CHROOT} /bin/chown root.lp /etc/cups/ssl
${CHROOT} /bin/chown root.lp /etc/cups/snmp.conf*
${CHROOT} /bin/chown root.lp /etc/cups/interfaces
${CHROOT} /bin/chown root.lp /etc/cups/cupsd.conf*
if [ -x bin/systemctl ] ; then
${CHROOT} /bin/systemctl --system daemon-reload >/dev/null 2>&1
fi
EOF
sed -i "s|_PACKAGER|${PACKAGER}|g; s|_BUILD_DATE|${DATE}|g" \
${PKG}/install/slack-desc
if [ "${SB_REP}" = "YES" ] ;then
# Replicate slackbuild and patches
mkdir -p ${SBDIR}/{patches,systemd}
install -m0644 ${CWD}/slack-desc ${CWD}/slack-required ${CWD}/ChangeLog.SB \
${CWD}/apply-patches.sh ${SBDIR}/
install -m0755 ${CWD}/${NAME}.SlackBuild \
${SBDIR}/${NAME}.SlackBuild
install -m0644 ${CWD}/patches/*.* \
${SBDIR}/patches/
install -m0644 ${CWD}/systemd/*.* \
${SBDIR}/systemd/
rmdir ${SBDIR}/patches
fi
# Build package:
set +o xtrace # no longer print commands upon execution
set -e
ROOTCOMMANDS="set -o errexit -o xtrace ; cd ${PKG} ;
/bin/chown --recursive root:root . ;
[ \"${SB_HGROUP}\" = 1 ] && /bin/chown root.lp ./var/spool/cups{,/tmp} ./var/cache/cups{,/rss} ;
[ \"${SB_HGROUP}\" = 1 ] && /bin/chown root.lp ./etc/cups{,/ppd,/ssl,/interfaces} ./etc/cups/{cupsd,snmp}.conf* ; "
ROOTCOMMANDS="${ROOTCOMMANDS}
/sbin/makepkg --prepend --linkadd y --chown n ${PKGDEST}/${PKGNAME}.${PKGFORMAT} "
if test ${UID} = 0; then
eval ${ROOTCOMMANDS}
set +o xtrace
elif test "$(type -t fakeroot)" = 'file'; then
echo -e "\e[1mEntering fakeroot environment.\e[0m"
echo ${ROOTCOMMANDS} | fakeroot
else
echo -e "\e[1mPlease enter your root password.\e[0m (Consider installing fakeroot.)"
/bin/su -c "${ROOTCOMMANDS}"
fi
# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
echo "Cleaning..."
if [ -d ${TMP}/${SRCDIR} ]; then
rm -rf ${TMP}/${SRCDIR} && echo "${TMP}/${SRCDIR} cleanup completed"
fi
if [ -d ${PKG} ]; then
rm -rf ${PKG} && echo "${PKG} cleanup completed"
fi
rmdir ${TMP} && echo "${TMP} cleanup completed"
fi
exit 0