aboutsummarylogtreecommitdiffstats
path: root/PKGBUILD
blob: d7449a6172e8201747709c2681bfe03956c26de4 (plain)
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
# Maintainer:  Chris Severance aur.severach aATt spamgourmet dott com
# Contributor: David Raymond <raymond at kestrel dot nmt dot edu>
# Contributor: Alex Suykov <axs at ukr dot net>
# Contributor: Frank Thieme <frank at fthieme dot net>

# TODO: Did I miss references or fix too many in man pages.
# (done) TODO: Fix lpc [lpd|lpq|lprm] and other internal usages? These run the CUPS executables.
# TODO: Improve instructions for LPR only support for brand name printers.
# TODO: We shouldn't be the ones to rename the binaries. Upstream should implement EXEEXT.
# TODO: Are there better versions of these old filters?

# Renaming cups binaries has race conditions where binaries are bogus or missing for a short time.

_opt_SSL=0
_opt_SSLVER='' # Compiles with 3.0, don't know if it works
#_opt_SSLVER='-1.0' # no longer needed, patched by Debian
#_opt_SSLVER='-1.1'

_primarylpr=0 # Can be changed between installs
# 0 - cups  binaries with original name lp lpr lpq, alternate names for lprng
# 1 - lprng binaries with original name lp lpr lpq, alternate names for cups
# 2 - lprng binaries, original package, does not coexist with cups
# Final test: install 0 twice, install 1 twice, install cups, install 0 twice

# suffix for conflicting binaries: lpr -> lprng so tab completion will find it
# Can be changed between installs.
if [ "${_primarylpr}" -eq 0 ]; then
  _sfx='ng' # sources contain EXEEXT but I couldn't get it to do anything.
elif [ "${_primarylpr}" -eq 1 ]; then
  _sfx='cups'
else
  _sfx=''
fi

# Need: Web based printcap editor, LPInfo?

# https://github.com/apple/cups/issues/5269

# CUPS plans to drop '-o raw' support. raw 9100 is the *only* useful
# way to print for a large swath of industrial printers, Zebra label
# printers in particular for which the ZPL and EPL print software will never
# be rewritten to output a CUPS compatible format.
# CUPS is needed for a large swath of WinPrinters
# and for automatic printing of PCL, PXL, PostScript and PDF. Neither
# raw nor CUPS is going away so I fixed lprng to coexist with CUPS.

# printcap is also a lot easier to manage than CUPS. Text FTW!

# Gentoo solves this with a use flag that leaves out the lpr binaries from the cups package
# https://packages.gentoo.org/useflags/lprng-compat
# Debian/Ubuntu solves this with the conflicting binaries in a separate cups-bsd package.
# Unfortunately neither of these solutions allows using both cups and lprng command line tools.

# Here we can rename either the cups binaries or the lprng binaries, whichever is easier to fix scripting.

# As of Dec 2018 CUPS raw can be considered as already gone.
# CUPS has two show stopper raw bugs that probably won't be fixed.

# Bug 1:
# https://github.com/apple/cups/issues/4782
# Bug reappeared yet again
#   lp -d lp -o raw file1 file2
# 2 files queued, file1 prints, file2 does not

# Bug 2:
# Some instances of piping stdin '|lp -o raw' or '|lpr -o raw' crash with
#   lp:  Error - unable to queue from stdin - Success.
#   lpr: Error - unable to queue from stdin - Broken pipe.
# lp and lpr are breaking the pipe, not the source. Capturing
# stdin to a file and printing with 'lpr -r -o raw file' works.

# This might be a not yet found bug from glib 2.28 breaking filters.
# https://bugs.archlinux.org/task/60044
# https://github.com/OpenPrinting/cups-filters/issues/58
# https://github.com/apple/cups/issues/5396

# cups-lpr cups-lpd also has some faults

# CUPS printers must be shared to be accessed by the locally running cups-lpr.
# CUPS sharing pollutes the network with unwanted printers.

# -o raw does not work with cups-lpd. It can be tricked into working but
# eventually it will not work.

# https://lists.cups.org/pipermail/cups/2009-August/047481.html Adam Tauno Williams [cups.general] Remote raw printing via cups-lpd s
# https://marc.info/?l=cups&m=125084903028064&w=2
# The solution is to use different switches with systemd or xinetd
# This can be applied to systemd with
#   systemctl edit org.cups.cups-lpd@.service
# [Service]
# ExecStart=
# ExecStart=-/usr/lib/cups/daemon/cups-lpd -o job-sheets=none -o document-format=application/vnd.cups-raw

_spooldir='/var/spool/lpd'
_printcap='/etc/lprng/printcap'
_service='lpd.service'

set -u
pkgname='lprng'
pkgver='3.9.0'
pkgrel='1'
pkgdesc='an enhanced, extended, and portable implementation of the Berkeley LPR lpd print spooler'
if [ ! -z "${_sfx}" ]; then
  pkgname+='-cups'
  pkgdesc+=' that coexists with CUPS'
fi
arch=('i686' 'x86_64' 'armv6h')
#url="http://www.lprng.com"
url='https://lprng.sourceforge.net'
license=('custom:Artistic')
depends=('glibc' 'bash' 'file' 'grep' 'sed')
if [ "${_opt_SSL}" -ne 0 ]; then
  depends+=("openssl${_opt_SSLVER}")
fi
optdepends=(
  'poppler: pdf to ps conversion in filters (gsfilter)' # formerly xpdf
  'ghostscript: convert ps to device language in filters (gsfilter)'
  'enscript: text to ps conversion in filters (gsfilter,psfilter)'
  'foomatic-filters-lprng: foomatic-rip in filters (foofilter)'
  'hplip: drivers for HP printers'
  'ifhp: filters for many printers'
)
if [ ! -z "${_sfx}" ]; then
  provides=("lprng=${pkgver}") # a rather specious claim since we don't provide the binaries with the same name
  conflicts=('lprng')
  optdepends+=(
    'lprng: install this instead for standard BSD binaries lp lpr lpq without cups'
  )
  if [ "${_primarylpr}" -ne 0 ]; then
    depends+=('cups')
  else
    optdepends+=(
      'cups: standard BSD binaries lp lpr lpq'
    )
  fi
else
  conflicts=('cups')
fi
backup=(
  'etc/lprng/lpd/lpd.conf'
  'etc/lprng/lpd/lpd.perms'
  "${_printcap#/}"
)
_mans=(
  'man1/cancel.1'
  'man1/lp.1'
  'man1/lpq.1'
  'man1/lpr.1'
  'man1/lprm.1'
  'man1/lpstat.1'
  'man8/lpc.8'
)
if [ "${_primarylpr}" -eq 1 ]; then
  _bins=("${_mans[@]##*/}")
  _bins=("${_bins[@]%%.*}")
  _binscups=("${_bins[@]/#/usr\/bin/}")
  _binscups=("${_binscups[@]/%/${_sfx}}")
  backup+=("${_binscups[@]}") # minimize race conditions with cups binaries. Race conditions for man pages are of no concern.
  unset _binscups
fi
options=('!strip')
install="${pkgname%%-*}.install"
_srcdir="lprng-${pkgver}"
source=(
  "http://sourceforge.net/projects/lprng/files/lprng/lprng-${pkgver}.tar.gz"
  #'0000-lprng-help-website.patch' # Clean outdated info from help files
  '0001-hardlink-to-symlink-binaries.patch'
  '0002-openssl_1.1.patch' # https://sources.debian.org/data/main/l/lprng/3.8.B-7/debian/patches/openssl_1.1.patch
  '0003-lpc-lpq-lprm-suffix.manual.patch'
  'lpd.service'
  'gsfilter'
  'psfilter'
  'foofilter'
  'printcap_remote'
  'printcap_server'
  'README'
  'lpd.conf'
  'lpd.perms'
)
md5sums=('10f4ec823df0e021404284037138aa8a'
         '08fbfe9aac9aebdd88f71afc557b5e68'
         'c8f1ae4eefe6b82d9097f095ab1557c8'
         '06db650ad6f5704e7a177bae23500977'
         'a59c448b0e37db80422175b7a1a2c304'
         'ce6f32b57a8e650f610523a6afaaf659'
         'd6c523f275bb63f68bf17d5ca02e4814'
         '1fa86ca79140bed23d59a552ac2d39b2'
         '496dfbb160f2a0308b7847541b03c8db'
         '422ad79bda6ae9d2990fdef55240e569'
         '1768d2f81d6d14c22686293ca60528c1'
         '3ef9f91dc0de273da1f5f1b20d49cd17'
         '3f861c75c2d68c0e45b4095ab39ba1c8')
sha256sums=('c92597671f4c7cbe8bb3f38fbc4283354db84c6abff1efb675fa2e120421915d'
            '96828bce13d6548a02e1d9849e713c950312b5c38c2282f2c5cfc5be454c6784'
            '269d2fdd0bbef11aa933cd4d49c06a44ce227badeec2530f199b185c7bd7f4f7'
            'd071adace21df32507d69c908851dc94511f404ecea4095bcdbb7d8504d97241'
            '3b546e8dd8f7ef3a1025d7d59ed8187fa21a9b9cf839a9bbda9821733da046e1'
            'c6a696dea62f7ffdade6a3071d201d076ee81e4aa14283dd4072578665e5eb7a'
            'f1a8a318f210cfc3814d234cb98a3de0c7a161c0e0c5671fe1c266ee03e351ec'
            'ce83b23dd188876b0b66de70f8b13d12036ba2ec1b837212bce6a172308904d4'
            'be383447b74cf9b86666adeaf35f844b394c222abbcda7f5cd7fc64f79373b82'
            'fc94245b58b23c9498a10c64aed20b6120595c6c3e1412bb419126ca78123a94'
            'a4c261f5754b380ff85c454249a152cb67baf9bbf10dc95cd16026f90bacb620'
            'faf52cf982eaa66a475344a5647a80a761d10402ccb9de263c70dc15ccc85c29'
            '47b48ab7fa15ae9226463c98d6c8fce9ee9b602c3a9f96907fcd84e50902b2cc')

prepare() {
  set -u
  cd "${_srcdir}"

  local _f
  for _f in "${source[@]}"; do
    _f="${_f%%::*}"
    _f="${_f##*/}"
    if [[ "${_f}" = *.manual.patch ]]; then
      if [ "${_primarylpr}" -eq 0 ]; then
        set +u; msg2 "Patch ${_f}"; set -u
        patch -Nup1 -i <(sed -E -e "s:@SUFFIX@:${_sfx}:g" "${srcdir}/${_f}")
      fi
    elif [[ "${_f}" = *.patch ]]; then
      set +u; msg2 "Patch ${_f}"; set -u
      patch -Nup1 -i "${srcdir}/${_f}"
    fi
  done
  #cd ..; cp -pr "${_srcdir}" 'a'; ln -s "${_srcdir}" 'b'; cd "${_srcdir}"; false
  #diff -pNaru5 'a' 'b' > '0000-new.patch'

  sed -e 's:/var/spool/LPD:/var/spool/lpd:g' -i 'man/lpd.n'

  # Clean up sbin
  sed -e 's:/usr/local/sbin/:/usr/bin/:g' -i $(grep -lrFe '/usr/local/sbin/' .)
  sed -e 's:/usr/sbin/:/usr/bin/:g' -i $(grep -lrFe '/usr/sbin/' .)
  sed -e '/FILTER_PATH/ s@/usr/sbin:@@g' -i 'src/vars.c'

  # Clean up /usr/local
  sed -e 's:/usr/local/libexec/:/usr/lib/:g' -i $(grep -lrFe '/usr/local/libexec/' .)
  sed -e 's:/usr/local/bin:/usr/bin:g' -i $(grep -lrFe '/usr/local/bin' .)
  sed -e 's:/usr/local/:/usr/:g' -i 'src/pclbanner.in'

  # Fix ifhp path in printcap
  sed -e 's:/usr/libexec/filters/ifhp:/usr/lib/filters/ifhp:g' -i 'conf/printcap'

  # Check filters
  local _f
  for _f in "${srcdir}"/*filter; do
    bash -n "${_f}"
  done
  set +u
}

build() {
  set -u
  cd "${_srcdir}"

  if [ ! -s 'Makefile' ]; then
    local _conf=(
      -q
      --libexecdir='/usr/lib/lprng'
      --localstatedir='/var'
      --mandir='/usr/share/man'
      --sbindir='/usr/bin'
      --sysconfdir="${_printcap%/*}"
      --with-groupid='lp'
      --with-spooldir="${_spooldir}"
      --with-userid='daemon'
      --prefix='/usr'
    )
    local _lf=''
    local _cf=' -Wno-unused-result -s -fcommon'
    if [ "${_opt_SSL}" -ne 0 ]; then
      if [ ! -z "${_opt_SSLVER}" ]; then
        _cf+=" -I/usr/include/openssl${_opt_SSLVER}"
        _lf+=" -L/usr/lib/openssl${_opt_SSLVER}"
      fi
      _conf+=(--enable-ssl)
    else
      _conf+=(--disable-ssl)
    fi
    set -x
    CFLAGS="${CFLAGS}${_cf}" \
    LDFLAGS="${LDFLAGS}${_lf}" \
    ./configure "${_conf[@]}"
    set +x
  fi
  set -x
  make -s
  set +x
  set +u
}

package() {
  set -u
  cd "${_srcdir}"
  make -s -j1 MAKEPACKAGE='YES' DESTDIR="${pkgdir}" install
  install -Dpm0644 'COPYRIGHT' -t "${pkgdir}/usr/share/licenses/${pkgname}/"
  cat >> "${pkgdir}${_printcap}.sample" << EOF
#
# Printer names are case preserving and case insensitive.
# Do not make two printers same letters different case.
# If you do the last one will be used.
#
EOF
  cd "${srcdir}"

  install -d "${pkgdir}${_spooldir}"
  if [ "${_opt_SSL}" -eq 0 ]; then
    rm "${pkgdir}/usr/bin"/*certs "${pkgdir}/usr/share/man/man1"/*certs*
  fi
  install -Dpm0644 'lpd.service' "${pkgdir}/usr/lib/systemd/system/${_service}"
  install -Dpm0755 'foofilter' 'gsfilter' 'psfilter' -t "${pkgdir}/usr/share/doc/${pkgname}/"
  install -Dpm0644 'printcap_remote' 'printcap_server' 'README' -t "${pkgdir}/usr/share/doc/${pkgname}/"
  install -Dpm0644 'lpd.conf' 'lpd.perms' -t "${pkgdir}/etc/lprng/lpd/"
  install -Dpm0644 /dev/null "${pkgdir}${_printcap}"

  # Change spool dir
  if [ "${_spooldir}" != '/var/spool/lpd' ]; then
    sed -e "s:/var/spool/lpd:${_spooldir}:g" \
      -i "${pkgdir}/usr/share/doc/${pkgname}/"{'printcap_remote','printcap_server'} \
         "${pkgdir}/etc/lprng/printcap.sample" \
         "${pkgdir}/etc/lprng/lpd"/*.sample \
         $(grep -lrFe '/var/spool/lpd' "${pkgdir}/usr/share/man")
  fi

  # Make documentation easy to find
  ln -s "/usr/share/doc/${pkgname}" "${pkgdir}/etc/lprng/lpd/doc"

  local _cdir="usr/lib/${pkgname}/cups" # This must be deleted when changing to _primarylpr=0
  local _scriptdir="/usr/share/${pkgname}"
  local _script="${_scriptdir}/${pkgname}.sh"

  # Generate amended install
  bash -n "${startdir}/${install}" || echo "${}"
  true && install="${install}.pkg"
  rm -f "${startdir}/${install}"
  cat - <<<"
# Do not modify this copy

_printcap='${_printcap}'
_service='${_service}'
_postinst='${_script}' # secondary needs this to clean up afer a primary -> secondary switch
_primarylpr='${_primarylpr}' # This is a post-upgrade setting sent to the pre-upgrade script
_cdir='${_cdir}'

" <(sed -E -e 's:^_[a-z]+=:#&:g' "${startdir}/${install%.pkg}") > "${startdir}/${install}"
  bash -n "${startdir}/${install}" || echo "${}"

  # Produce suffix cups or suffix lprng
  if [ ! -z "${_sfx}" ]; then
    if [ "${_primarylpr}" -ne 0 ]; then
      pushd "${pkgdir}/usr/bin"
      local _ldir="usr/lib/${pkgname}/lprng"
      local _cdir="usr/lib/${pkgname}/cups"
      # folders to store conflicting lprng and cups files
      install -d "${pkgdir}/${_ldir}"/{usr/bin,/usr/share/man/{man1,man8}}
      # There's no way to do this without this folder of untracked files.
      install -d "${pkgdir}/${_cdir}"/{usr/bin,/usr/share/man/{man1,man8}}
      local _f
      for _f in "${_bins[@]}"; do
        mv "${_f}" "${pkgdir}/${_ldir}/usr/bin"
        touch "${_f}${_sfx}"
      done
      local _zipmanlpr='.gz' # These need to be the same or cups will show untracked files
      local _zipmancups='.gz'
      cd "${pkgdir}/usr/share/man"
      for _f in "${_mans[@]}"; do
        mv "${_f}" "${pkgdir}/${_ldir}/usr/share/man/${_f}"
        touch "${_f/./${_sfx}.}${_zipmancups}"
      done
      popd > /dev/null

      # Generate install helper script.
      install -Dpm644 <(cat << EOF
#!/bin/sh

# Automatically generated by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR
# https://aur.archlinux.org/

set +e
set -u

_opt_q=''

$(declare -p _bins)
$(declare -p _mans)
_zipmancups='${_zipmancups}'
_zipmanlpr='${_zipmanlpr}'
_sfx='${_sfx}'
_ldir='${_ldir}'
_cdir='${_cdir}'
_primarylpr='${_primarylpr}'

if [ "\${EUID}" -eq 0 ]; then
  #_echo=''
  _tp='/'
  #_true='true '
else
  #_echo=''
  _tp='../../../'
  #_true=''
fi

# -t to generate cups test files, test option only
# -c to install/upgrade cups from pacman hook
# Install method isn't used any more
# -l to post-install lprng
# -p to pre-upgrade lprng
# -u to post-upgrade lprng
# -r to pre-remove lprng

# Generate fake CUPS files in system folders
# This only works in the test folder. It is never called from the .install
_fn_gen_cups() {
  if [ "\${EUID}" -ne 0 ]; then
    local _f _c1 _c1 _c2
    for _f in "\${_bins[@]}"; do
      _c1="\${_tp}usr/bin/\${_f}"
      rm -f "\${_c1}"
      dd if=/dev/urandom of="\${_c1}" bs=512 count=1 2> /dev/null
    done
    for _f in "\${_mans[@]}"; do
      _c1="\${_tp}usr/share/man/\${_f}\${_zipmancups}"
      rm -f "\${_c1}"
      dd if=/dev/urandom of="\${_c1}" bs=512 count=1 2> /dev/null
    done
  fi
}

# Copy cups files from system folders to _cdir with original names
_fn_store_cups() {
  local _f _c1 _c2
  for _f in "\${_bins[@]}"; do
    _c1="\${_tp}usr/bin/\${_f}"
    _c2="\${_tp}\${_cdir}/usr/bin/\${_f}"
    cp -pf "\${_c1}" "\${_c2}"
  done
  for _f in "\${_mans[@]}"; do
    _c1="\${_tp}usr/share/man/\${_f}\${_zipmancups}"
    _c2="\${_tp}${_cdir}/usr/share/man/\${_f}\${_zipmancups}"
    cp -pf "\${_c1}" "\${_c2}"
  done
}

# Copy cups files to system folders with modified names
_fn_cp_cups() {
  local _f _c1 _c2
  for _f in "\${_bins[@]}"; do
    _c1="\${_tp}usr/bin/\${_f}\${_sfx}"
    _c2="\${_tp}\${_cdir}/usr/bin/\${_f}"
    cp -pf --remove-destination "\${_c2}" "\${_c1}"
  done
  for _f in "\${_mans[@]}"; do
    _c1="\${_tp}usr/share/man/\${_f/./\${_sfx}.}\${_zipmancups}"
    _c2="\${_tp}${_cdir}/usr/share/man/\${_f}\${_zipmancups}"
    cp -pf --remove-destination "\${_c2}" "\${_c1}"
  done
}

# Erase modified name cups files in system folders
# This prevents .pacsave files
_fn_rm_cups() {
  local _f _c1 _c2
  for _f in "\${_bins[@]}"; do
    _c1="\${_tp}usr/bin/\${_f}\${_sfx}"
    rm "\${_c1}"
  done
  for _f in "\${_mans[@]}"; do
    _c1="\${_tp}usr/share/man/\${_f/./\${_sfx}.}\${_zipmancups}"
    rm "\${_c1}"
  done
}

# Erase lprng files with original cups names in system folders.
# cp -f isn't erasing our soft links leading to cups lp -> lpr which isn't correct.
# cp --remove-destination fixed this
_fn_rm_lprng_cups() {
  local _f _c1 _c2
  for _f in "\${_bins[@]}"; do
    _c1="\${_tp}usr/bin/\${_f}"
    rm "\${_c1}"
  done
  for _f in "\${_mans[@]}"; do
    _c1="\${_tp}usr/share/man/\${_f}\${_zipmancups}"
    rm "\${_c1}"
  done
}

# Erase original name cups files in _cdir
_fn_rm_cups_store() {
  rm -rf "\${_tp}\${_cdir}/usr"
}

# Copy cups files to system folders with original names
_fn_cp_cups_u() {
  cp -dprf --remove-destination "\${_tp}${_cdir}/." "\${_tp}/"
}

# Copy original name lpr files to system folders
_fn_cp_lpr() {
  cp -dprf --remove-destination "\${_tp}${_ldir}/." "\${_tp}/"
}

while getopts 'qtclp:u:r' opt; do
  case "\${opt}" in
  q) _opt_q='true ';;
  t) _fn_gen_cups;;
  c)
    \${_opt_q} echo 'lprng: update cups'
    _fn_store_cups
    _fn_cp_lpr
    _fn_cp_cups
    ;;
  l)
    \${_opt_q} echo 'lprng: post-install lprng'
    _fn_store_cups
    _fn_cp_lpr
    _fn_cp_cups
    ;;
  p)
    \${_opt_q} echo 'lprng: pre-upgrade lprng'
    #_fn_rm_lprng_cups
    _fn_rm_cups
    _fn_cp_cups_u
    if [ "\${OPTARG}" -eq 0 ] && [ "\${_primarylpr}" -ne 0 ]; then
      \${_opt_q} echo 'lprng: pre-upgrade remove cups store changing from primary to secondary'
      _fn_rm_cups_store
    fi
    ;;
  u)
    \${_opt_q} echo 'lprng: post-upgrade lprng'
    #This is *post* upgrade so we can't use the same method as pre-upgrade unless we pass forward the pre-upgrade _primarylpr
    if [ ! -x "\${_cdir}/usr/bin/lpr" ]; then
      \${_opt_q} echo 'lprng: post-upgrade add cups store changing from secondary to primary'
      _fn_store_cups
    fi
    _fn_cp_lpr
    _fn_cp_cups
    ;;
  r)
    \${_opt_q} echo 'lprng: pre-remove lprng'
    _fn_rm_cups
    _fn_cp_cups_u
    _fn_rm_cups_store
    ;;
  *) echo "Usage: \$0 [-c] [-l]"; exit 1 ;;
  esac
done
EOF
      ) "${pkgdir}${_script}"
      test -s "${pkgdir}${_script}" || echo "${}"
      bash -n "${pkgdir}${_script}" || echo "${}"

      # cups hook
      install -Dm644 <(cat << EOF
# Automatically generated by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR
# https://aur.archlinux.org/
# Replace cups lpr tools with lprng tools
# cups tools are renamed
[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = cups
[Action]
Description = Replace cups binaries with lprng
Depends = coreutils
When = PostTransaction
Exec = /usr/bin/bash "${_script}" -q -c
EOF
      ) "${pkgdir}/usr/share/libalpm/hooks/${pkgname}-rename.hook"
    else
      # lpd doesn't conflict with cups
      #sed -e '/^ExecStart=/ s:lpd'":&${_sfx}:g" -i "${pkgdir}/usr/lib/systemd/system/${_service}"
      # Rename programs and change self references in man pages
      pushd "${pkgdir}/usr/bin" > /dev/null
      local _f _fx
      for _fx in "${_mans[@]}"; do
        _f="${_fx##*/}"
        _f="${_f%%.*}"
        mv "${_f}" "${_f}${_sfx}"
        sed -e "s:\b${_f}\b:&${_sfx}:g" \
            -e "1,2 s:\b${_f^^}\b:&${_sfx}:g" \
          -i "${pkgdir}/usr/share/man/${_fx}"
      done
      # Overwrite hard or symlinks with suffix soft links
      ln -sf "lpr${_sfx}" "lp${_sfx}"
      ln -sf "lprm${_sfx}" "cancel${_sfx}"
      # Rename man pages.
      cd "${pkgdir}/usr/share/man"
      for _f in "${_mans[@]}"; do
        mv "${_f}" "${_f/./${_sfx}.}"
      done
      # Change references in man pages
      sed -e "#s:\blpd\( \?\)(:lpd${_sfx}\1(:g" \
          -e "s:\blpr\( \?\)(:lpr${_sfx}\1(:g" \
          -e "s:\blprm\( \?\)(:lprm${_sfx}\1(:g" \
          -e "s:\blpc\( \?\)(:lpc${_sfx}\1(:g" \
          -e "s:\blp\( \?\)(:lp${_sfx}\1(:g" \
          -e "s:\blpq\( \?\)(:lpq${_sfx}\1(:g" \
        -i */*
      sed -e "s:\blprm\b:&${_sfx}:g" \
          -e "s:\blpr\([ ,]\):lpr${_sfx}\1:g" \
          -e "#s:\blpd\([ ,)]\):lpd${_sfx}\1:g" \
          -e "s:\blpq\b:&${_sfx}:g" \
          -e "s:\blpc\b:&${_sfx}:g" \
        -i 'man5/printcap.5' 'man5/lpd.perms.5' 'man8/lpd.8'
      sed -e "/^\.I/ s:\blprm\b:&${_sfx}:g" \
          -e "/^\.I/ s:\blpr\([ ,]\):lpr${_sfx}\1:g" \
          -e "/^\.I/ s:\blpd\([ ,)]\):lpd${_sfx}\1:g" \
          -e "/^\.I/ s:\blpq\b:&${_sfx}:g" \
          -e "/^\.I/ s:\blpc\b:&${_sfx}:g" \
        -i "man8/lpc${_sfx}.8"
      sed -e "s:\blprm\b:&${_sfx}:g" -i "man1/cancel${_sfx}.1"
      popd > /dev/null
      # Change reference in printcap
      sed -e "s: checkpc\b: sudo&:g" \
          -e "s: lpc\b:&${_sfx}:g" \
        -i "${pkgdir}/etc/lprng/printcap.sample"
    fi
  fi

  # Check for unwanted folders
  ! grep -lrFe '/sbin' "${pkgdir}" || { echo "Line ${LINENO} Forbidden: /sbin"; false; }
  ! grep -lrFe '/usr/local' "${pkgdir}" || { echo "Line ${LINENO} Forbidden: /usr/local"; false; }
  ! grep -lrFe '/libexec/' "${pkgdir}" || { echo "Line ${LINENO} Forbidden: /libexec/"; false; }
  set +u
}
set +u