summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 286572a36e4b46f202836dedd4d98c3835decb90 (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
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
# Maintainer: Chris Severance aur.severach aATt spamgourmet dott com

# Todo: service for Pro/5 DataServer

# Basis bug: BLM is hard coded to use /usr/tmp (fixed herein)
# Basis bug: some Basis scripts have cosmetic errors (fixed herein)

# Build instructions:

# This PKGBUILD does not automatically download all files. Basis does not make
# all files available as direct links. It is not necessary to have a license
# to download, install, and run Pro/5. Without a license you get nag screens.

# At the Basis web site click Products, Downloads
# Choose a BASIS product: Pro/5
#   Platform: Linux
#   OS Level: Linux Kernel 2.6.17-1.2142_FC4+ AND glibc v2.3+ [Port 1045]
#   Revision: Latest or any
#   License Type: (*) Update existing software. (No license delivered.)
#     (Licensing will be handled during install. You may need to call Basis.)
#   Enter info... Download Product
#   Repeat for 64 bit: Linux Kernel v2.6+ AND glibc v2.3+ [Port 6045] - 64-bit
# Choose a BASIS product: Pro/5 Data Server
#   Repeat above for 1245 & 6245
# Place the 4 files in with PKGBUILD
# The BLM is downloaded automatically.

# If you already have license files, run "makepkg -oc" and place them
# in the appropriate z folders. This allows them to be built into the package
# for easy installs and upgrades. See below for files and folders.

# License concepts: (for those who aren't familiar with Macrovision FlexLM)

# The only product that requires a license file generated by Basis is the
# Basis License Manager (BLM). Every site must run at least one
# BLM server. A single BLM server on the same machine that runs Pro/5 is
# typical to get started. Developers may have a separate BLM server
# from production BLM servers.

# It is not necessary to have a functioning BLM server to try Pro/5. You can
# test suitability, functionality, run, extract data, and edit programs.
# Once your BLM server is licensed and running you can point your Pro/5
# installs to it and they will become fully functional without nag screens.

# While the BLM license is locked to the BLM server the HostID was generated
# on, BLM license checkout for Pro/5 instances are not machine locked,
# platform or OS specific. You can run Pro/5 on as many different machines
# and OS as you like. You can try other platforms to see if they are better
# suited to your needs. All you need is a BLM server with available licenses
# to point to. This PKGBUILD only handles Arch Linux.

# BLM License file security content may improve over time. Newer revisions
# of Pro/5 may require features not found in old license files or BLM servers.
# Contact Basis for an updated license file or for BLM server changes.
# Older revisions of Pro/5 are expected to run with newer licenses
# and BLM servers.

# Developer only licenses are available at a low yearly price.
# This is highly recommended for active developers.
# * You get get all features enabled. Good for testing to determine
#   whether a better licenses for production would be worthwhile.
# * You don't get kicked when the production BLM servers restart,
#   crash, or run out of licenses.
# * You don't consume one or more full licenses needed for users
#   on production systems.
# * If you develop on production systems you can use an altered
#   Pro/5 SERVER configuration so your runs use licenses from
#   the BLM serving your developers license.

# Install instructions

# TL;DR
# * Purchase license
# * install package
# * run standalone BLM
# * install package again
# * systemctl enable --now basis_lmgrd.service
# * configure Pro/5 installations to use BLM server

# There are two installers. "./install" is found in /usr/local/basis.
# The "BLM installer" is in the build folder. Some functionality is offered
# by both installers but only works properly in one of them.

# 1. Purchase a license from Basis or a reseller. You are sent:
#    A. Order confirmation
#    B. Instructions with Serial and Authorization.
#
# 2. Install the basis-pro5 package.
#
# 3. Run the BLM installer.
#  Original command: sudo java -jar BLM1600_09-29-2016_1212.jar
#  Use the provided helper script
#    sudo /usr/local/basis/blmgr/BLMrun
#
# Internet access will make registration and reregistration easier.
# The BLM installer automatically retrieves the license.
# Stop at step "Configure BLM Startup" which is done by the package

# The first time the license is activated, the activated license for your BLM
# can be returned in as little as two minutes. If the license has already been
# activated and you're changing the BLM server to another system, you may need
# to call Basis to have your activation reset. This may require an active SAM
# plan or a one time fee. A license request without an activation reset will
# get you a license but it's only good for 7 days as a emergency license. Check
# your expiry date and if it's 7 days, plan on some time on the phone to get
# the licensing straightened out before the nag screens come up again.

# Note: Some licenses require periodic reactivation and Internet access to the
# server. See http://documentation.basis.com/BASISHelp/WebHelp/inst/basis_license_types.htm
#
# 4. Install the basis-pro5 package again to replace some patched files
# overwritten by the BLM installer.
#
# 5. On all your Pro/5 installations run /usr/local/basis/install and select
# PRO5, SERVER
# and specify the IP or DNS name of your running BLM server.

_opt_blmgr_user='nobody' # default: root, the license manager should not be run as root
_opt_blmgr_group='nobody'
_opt_pro5_sql='pro5b'    # default: pro5b for non-sql, pro5s for sql
_opt_pro5_exe='bbx4'     # default: pro5, this link will be created in /usr/bin so
                         # Pro/5 is in the path. Select a name that minimizes the number of
                         # scripts you must modify.

# Up to 3 packages can be created
#   i686 for 32 bit systems
#   x86_64 for 64 bit systems
#   any for 64 bit systems running multilib
# They can all be made and ready for compatibility,
# performance, crash testing, or just carrying around for easy installs.

# To build and install package for native bitness:
# makepkg -sCcfi

# To build 32 bit package on 64 bit system
# makepkg -sCcf CARCH=i686

# To build 32 bit multilib package on 64 bit system
# makepkg -sCcf CARCH=any

# Once installed with an activated license you can enable and
# start the BLM service.

#   systemctl enable basis_lmgrd
#   systemctl start basis_lmgrd

# Try out your new Install in command line mode
# cd /usr/local/basis/pro5; unset BBTERM; ./pro5
# Try out your new Install in full screen mode
# cd /usr/local/basis/pro5; export BBTERM=T0; ./pro5

# Got READY> prompt with no nag screens, all good!
# Type BYE or RELEASE to exit

# So far as I know I've solved every one of the annoyances
# with the Basis install.
# If you have license nags check the logs at /var/log/basis/
# Check the status with
#   systemctl status basis_lmgrd.service
#   /usr/local/basis/blmgr/lmutil lmstat -a

# The setup for a fully functioning Basis BBx Progression Pro/5 environment
# is extensive and not covered here.

# There are no man pages.

# Once installed you should add the utility folders ext, graphics, and std
# to your operating config.bbx. Old utilities should be removed if there are
# no modified versions. Many of the supplied utilities won't work unless all
# the utilities are the same version. To keep you from becoming dependant on
# custom changes to these files they are locked on install.
# If you want to customize an included utility, make
# a copy with a new name.

# Uninstall cleanup: rm -rf /var/log/basis /usr/local/basis

set -u
# _basefolder can be /usr/local or /usr/share
# Whatever is chosen must have the same number of characters as /usr/local
# Anything other than those two folders will require amending the install.
# An upgrade after a change here will generate 3 harmless chattr errors on install that are handled.
_basefolder='/usr/local'
_basedir="${_basefolder}/basis"
_servicefile='basis_lmgrd.service'
_logfolder='/var/log/basis'

pkgname='basis-pro5'
pkgver='18.00'; _dsver='18.00'
pkgrel='1'
pkgdesc='BASIS BBx Progression Pro/5 Business BASIC eXtended for BBj'
url='http://www.basis.com/'
license=('custom')
depends=('glibc' 'wget' 'gzip')
#depends+=('java-environment-jdk'{'>=7','<9'}) # The Windows install recommends jdk over jre so we do too. OpenJDK does not work.
optdepends=('ncompress: Original compress for logs instead of gzip')
#backup=("${_basedir##/}/blmgr/Register.properties")
options=('!docs' 'emptydirs' '!strip') # strip is so poorly implemented that it changes the content and date on executables, even when there's nothing to strip! What were they thinking?
install="${pkgname}-install.sh"
#_verwatch=("${url}availability" '<td class="revision".*">\([0-9\.]\+\).*' 'f') # Almost works
#_blmjar='BLM1600_03-11-2016_1203.jar'; _blmjarwebstart=''; _mj='7'
#_blmjar='BLM1600_04-11-2016_1107.jar'; _blmjarwebstart=''; _mj='7'
#_blmjar='BLM1600_09-29-2016_1212.jar'; _blmjarwebstart='BLM1600_08-10-2016_1012.jar'; _mj='7' # BBjWebstartBootstrap.jar is left out of BLM1600_09-29-2016_1212.jar, upgraders from previous versions didn't notice.
_blmjar='BLM1800_03-24-2018_1847.jar'; _blmjarwebstart=''; _mj='8'
depends+=('java-runtime-jre'{">=${_mj}",'<9'})
source=("http://public.basis.com/blm/jar/${_blmjar}")
noextract=("${_blmjar}")
if [ ! -z "${_blmjarwebstart}" ]; then
  source+=("http://public.basis.com/blm/jar/${_blmjarwebstart}")
  noextract+=("${_blmjarwebstart}")
fi
_file='@::file://@' # convince the git submission that these files aren't on the web and don't need to be supplied
# 32-bit Rev 15.00 Linux Kernel 2.6.17-1.2142_FC4+ AND glibc v2.3+
# 10455yyyy.Z          = Pro/5            Port 1045
# 12455yyyy.Z          = Pro/5 DataServer Port 1245
for _src in "10455${pkgver//./}.Z" "12455${_dsver//./}.Z"; do
  source_i686+=("${_file//@/${_src}}")
done

sha256sums=('3e2b1c7b9f2d1407bd8ba4dbc70b7397806fe19393221c30e6a560e150ca4192')
sha256sums_i686=('5096ed35aabb556b097a28d28c5f7925e61defe26f6eefd2b8642c46f11ed56c'
                 '97576e330ef46c47bbdaf6a06108f8d3200f264b1043db43a59b0ac6b151b76f')
sha256sums_x86_64=('5243e3c6c882386a50ca5aeba3f22144964e0d073949235b31c87345d1605508'
                   '62f49d454ea8289e661b37ff538a8762a2f537ee89cc1a583f2d373d7d4e3d0a')

for _src in "60455${pkgver//./}.Z" "62455${_dsver//./}.Z"; do
  source_x86_64+=("${_file//@/${_src}}")
done
# 64-bit Rev 15.00 Linux Kernel v2.6+ and glibc v2.3+
# 60455xxxx.Z          = Pro/5            Port 6045
# 62455yyyy.Z          = Pro/5 DataServer Port 6245
unset _src
unset _file

if [ "${CARCH:-}" != 'any' ]; then
  arch=('i686' 'x86_64')
else
  # This allows us to build an i686, x86_64, and any package all with the same name so pacman thinks it's an upgrade.
  :;source+=("${source_i686[@]}")
  unset source_i686 source_x86_64
  :;sha256sums+=("${sha256sums_i686[@]}")
  unset sha256sums_i686 sha256sums_x86_64
  arch=('any')
  depends+=('lib32-glibc')
fi

# Approximate update frequency, yearly
# 10455 has some old versions attached to it
_vercheck() {
  curl -s -l "${url}availability" | grep -FA1 $'60455\n10455' | sed -e 's:<[^>]\+>::g' | grep '^[0-9]\+\.[0-9]\+$' | tr '.' ':' | LC_ALL=C sort -n | tr ':' '.' # 1>&2
}

# We can't modify .install but we can stop and force the user to fix it.
_install_check() {
  local _ckvar
  local _ckline
  for _ckvar in _opt_blmgr_user _opt_blmgr_group _basedir _basefolder _logfolder _servicefile; do
    _ckline="${_ckvar}='${!_ckvar}'"
    if ! grep -q "^${_ckline}"'$' "${startdir}/${install}"; then
      msg "${install} must be fixed"
      echo "${_ckline}"
      set +u
      false
    fi
  done
}

prepare() {
  set -u
  _install_check

  if [ "${#_basedir}" -ne 16 ] || [ "${#_basefolder}" -ne 10 ]; then
    echo 'Due to replacements within binary files the following strings must be the same length as the sample string'
    echo '_basedir same length as /usr/local/basis'
    echo '_basefolder same length as /usr/local'
    set +u
    false
  fi

  cd "${srcdir}"

  # unpack most of the new BLM, removing files customized by the BLM installer
  # for seamless reinstalls and upgrades.
  rm -rf 'blmgr' 'blmgr.tmp'
  mkdir 'blmgr.tmp'
  mkdir 'blmgr'
  cd 'blmgr.tmp'
  bsdtar -xf "${srcdir}/${_blmjar}"
  if [ ! -s 'BBjWebstartBootstrap.jar' ]; then
    mkdir 'webstart.tmp'
    cd 'webstart.tmp'
    bsdtar -xf "${srcdir}/${_blmjarwebstart}"
    mv 'BBjWebstartBootstrap.jar' ..
    cd ..
    rm -r 'webstart.tmp'
  fi
  rm -r 'com' 'org' 'META-INF' 'blminstall.xml'
  mkdir 'Archtemp'
  cd 'Archtemp'
  bsdtar -xf '../package_blm.jar'
  declare -A _arch=([any]='32' [i686]='32' [x86_64]='64')
  mv 'unix'/* "2145/blm/${_arch[${CARCH}]}"/* "${srcdir}/blmgr"
  mv "${srcdir}/blmgr/bin/basisrunlm" "${srcdir}/blmgr"
  rm "${srcdir}/blmgr/bin/unixautostart"
  # mv "${srcdir}/blmgr/bin/admin" "${srcdir}/blmgr/bin/blmadmin"
  rm "${srcdir}/blmgr/bin/admin" # Java isn't using this version any more
  cd '..'
  rm -r 'Archtemp'
  mkdir 'Archtemp'
  cd 'Archtemp'
  bsdtar -xf '../package_install.jar' 'lib/' 'unix'
  rm 'unix/images'/*.png 'unix/images/BasisB.xpm' 'unix'/*.directory 'unix'/*.menu 'unix/bin/.envsetup'
  local _df
  for _df in 'unix'/*/; do
    local _df2="${_df%/}"
    mv "${_df2}"/* "${srcdir}/blmgr/${_df2##*/}"
    rmdir "${_df2}"
  done
  rmdir 'unix'
  mv * "${srcdir}/blmgr"
  cd ..
  mv 'BBjWebstartBootstrap.jar' "${srcdir}/blmgr/lib"
  cd "${srcdir}/blmgr"
  bsdtar -xf '../blmgr.tmp/package_native_2145.jar'
  rm -r 'META-INF'
  mkdir -p 'cfg' 'log' 'uninstall/com/basis/install/'
  cd "${srcdir}"
  rm -r 'blmgr.tmp'

  cd "${srcdir}"
  # The permissions on these files are horrendous
  local _file
  for _file in $(find . -type 'f'); do
    #echo "${_file}"
    local _pm_executable=0
    local _pm_type="$(file "${_file}")"
    local _pm_isdata="${_pm_type##*:}" # bash
    local _pm_isdata="$(echo ${_pm_isdata})" # Trim spaces

    case "${_pm_isdata}" in
      #'empty')         _pm_executable=0;;
      'ASCII text'*)    _pm_executable=0;;
      'HTML'*)          _pm_executable=0;;
      #*'tar archive'*) _pm_executable=0;;
      *'ELF '*)         _pm_executable=1;;
      #*'compressed data'*) _pm_executable=0;;
      *' batch '*)      _pm_executable=1;;
      *' source, '*)    _pm_executable=0;;
      'BBx '*)          _pm_executable=0;;
      *'POSIX shell script'*) _pm_executable=1;;
      *) echo "${_pm_isdata}: ${_file}";;
    esac

    if [ "${_pm_executable}" -eq 0 ]; then
      chmod 644 "${_file}"
    else
      chmod 755 "${_file}"
    fi
  done
  unset _file
  unset _pm_executable
  unset _pm_type
  unset _pm_isdata
  unset _pm_isdata

  find . -type 'd' -exec chmod 755 '{}' '+'
  chmod 644 'scripts'/* # these are all sourced
  chmod 755 'install' # only root can run install (the installer is fixed with an EUID check later)

  # these will be marked immutable during install to prevent root from modifying
  chmod 444 'pro5'/{ext,std,graphics}/*

  # Fix a few missing utility files with old names for easier upgrades.
  ln -s '_ask.utl' 'pro5/ext/_ask.pub'
  #ln -s '_copy.pub' 'pro5/std/_copy.utl'
  #ln -s '_ddguess.utl' 'pro5/ext/_guess'
  #ln -s '_msg.utl' 'pro5/ext/_msg'
  ln -s '_unerr.utl' 'pro5/ext/_unerr.pub'
  ln -s '_yesno.utl' 'pro5/ext/_yesno.pub'
  #ln -s '_warn.utl' 'pro5/ext/_warn'

  # Branding the EXE eliminates the need for the license path in an ENV variable
  # Branding didn't work in the Basis installer. Only two files contain BLM_LICLOC.
  # Branding causes a linker error if done in package when fakeroot is active.
  local _touches
  for _touches in 'pro5/pro5'{b,s}; do
    pro5/BLMbrand "${_touches}" "${_touches}.tmp" "${_basedir}/pro5"
    touch -r "${_touches}" "${_touches}.tmp"
    mv "${_touches}.tmp" "${_touches}"
  done
  unset _touches

  # Fix the date on every file modified
  local _badfiles
  readarray -t _badfiles <<<"$(grep -larF $'/usr/local/\n/usr/tmp')"
  local _badfile
  for _badfile in "${_badfiles[@]}"; do
    touch -r "${_badfile}" "${_badfile}.Archtmp"
  done

  # Fix a little sbin, within the protection of touch
  sed -e 's:/usr/sbin:/usr/bin:g' -i 'scripts/BasisFuns'

  # We are modifying binary files so replace strings must be exactly the same length.
  sed -e '# fix /usr/local' \
      -e "s:/usr/local/:${_basefolder}/:g" \
      -e '# fix /usr/tmp' \
      -e 's:/usr/tmp:/var/tmp:g' \
    -i "${_badfiles[@]}"

  for _badfile in "${_badfiles[@]}"; do
    touch -r "${_badfile}.Archtmp" "${_badfile}"
    rm "${_badfile}.Archtmp"
  done
  unset _badfiles
  unset _badfile

  set +u
}

package() {
  set -u
  cd "${srcdir}"

  install -d "${pkgdir}${_basedir}"

  local _basis_pkg
  for _basis_pkg in *; do
    if [ ! -h "${_basis_pkg}" ]; then
      mv "${_basis_pkg}" "${pkgdir}${_basedir}/"
    fi
  done
  unset _basis_pkg

  # The source folders are gone so let's move
  cd "${pkgdir}${_basedir}"

  # The BLMGR gets used a lot so it needs to be installed with a helper script
  install -pm644 "${srcdir}/${_blmjar}" -t 'blmgr'
  install -m744 <(cat << EOF
#!/usr/bin/bash

# This executes the BLM and makes the necessary changes to apply any new licenses

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

cd "\$(dirname "\$0")" # guarantee that chown works on the right folder
set -u
shopt -s nullglob
list1=(*.lic*)

# Can't use openjdk even if present. Use the highest version of jdk
pushd '/usr/lib/jvm' > /dev/null
wantjdk=''
wantjdkbin=''
for jdk in java-[78]-j[dr][ke]/; do
  jdk="\${jdk%/}"
  case "\${jdk}" in
  *-jre) jdkbin="\${jdk}/jre/bin/java";;
  *-jdk) jdkbin="\${jdk}/bin/java";;
  esac
  if [ -x "\${jdkbin}" ]; then
    if [ -z "\${wantjdk}" ] || [ "\$(vercmp "\${jdk%-j*}" "\${wantjdk%-j*}")" -gt 0 ]; then
      wantjdkbin="\${jdkbin}"
      wantjdk="\${jdk}"
    fi
  fi
done
popd > /dev/null
unset jdk jdkbin wantjdk

echo "Using java \${wantjdkbin}"
echo
echo 'Exit when you see: Configure BLM Startup'

# findHome only works when basis_lmgrd is already running.
# This makes it work on the first run
cat > 'ps' << EOR
#!/bin/sh
echo '2 1 ./basis_lmgrd -c /usr/local/basis/blmgr'
EOR
chmod 755 'ps'
PATH="${_basedir}/blmgr/:\${PATH}" \
/usr/lib/jvm/\${wantjdkbin} -jar '${_blmjar}' # -p '/usr/local/basis/blmgr/BLM/Install.properties'
rm 'ps'
chown -R '${_opt_blmgr_user}:${_opt_blmgr_group}' *
list2=(*.lic*)
if [ "\${#list1[@]}" -ne "\${#list2[@]}" ] && systemctl -q is-enabled '${_servicefile}'; then
  systemctl restart '${_servicefile}'
  echo 'License manager restarted'
fi
EOF
  ) 'blmgr/BLMrun'
  touch -r "${srcdir}/${_blmjar}" 'blmgr/BLMrun'

  # Provide a minimal configuration
  install -m644 <(cat << EOF
# Automatically added by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR
# https://aur.archlinux.org/

ALIAS T0 /dev/tty xterm
prefix '${_basedir}/pro5/std/' '${_basedir}/pro5/ext/' '${_basedir}/pro5/graphics/'
EOF
) 'pro5/config.bbx'

  # Perform the BLM CREATE step, auto-Install the BasisRunLM
  local _outfile='scripts/BasisLicManager'
  cp -p "${_outfile}" "${_outfile}.Arch"
  sed -e '# disable all the pauses' \
      -e 's/ read / funcread /g' \
      -e '# fix a cosmetic script bug.' \
      -e 's/License Manager not found: ${lmgrdcom}/License Manager not found: \\${lmgrdcom}/g' \
    -i "${_outfile}.Arch"
cat >> "${_outfile}.Arch" << EOF
PrintFile() {
  :
  #echo "Print Stuff"
}
PrintPrompt() {
  :
  #echo "Prompt Stuff"
}
funcread() {
  :
  #echo "Read Stuff"
}
CreateRunLM "${pkgdir}${_basedir}/blmgr"
EOF
  sh -e -u "${_outfile}.Arch" >/dev/null
  rm "${_outfile}.Arch"

  # We had to add ${pkgdir} to get the install to put the file in the right place
  # now we remove the ${pkgdir} slop from the generated file
  sed -e "s:${pkgdir}/:/:g" \
      -e "# The systemd service doesn't work right unless you have hash bang on the front" \
      -e '1i #!/usr/bin/sh' \
      -e '# Place the log where logs belong. A logrotate is included.' \
      -e "s:${_basedir}/blmgr/log:${_logfolder}:g" \
    -i 'blmgr/BasisRunLM'
  touch -r "${srcdir}/${_blmjar}" 'blmgr/BasisRunLM'

  # the log must be world writable so we can run the manager under a non root user's account
  install -dm775 "${pkgdir}${_logfolder}"

  # disable BLM CREATE ADD START STOP. We do all this here in PKGBUILD.
  # CREATE won't work because they can't fix the hash bang problem fixed above.
  _outfile='scripts/BasisLicManager'
  if ! grep -ql 'Arch Linux' "${_outfile}"; then
    touch -r "${_outfile}" "${_outfile}.Arch"
    cat >> "${_outfile}" << EOF

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

# The commands
# BLM CREATE ADD START STOP
# are not compatible with Arch Linux systemd.

# The Arch Linux PKGBUILD performs CREATE automatically.
# The Arch Linux PKGBUILD also creates systemd scripts (ADD) for
# START and STOP.

# The original functionality is disabled and substituted with
# instructionals for Arch Linux.

# These modifications do not bypass any license agreements (AcceptLic).

CreateRunLM ()
{
        echo "This function has already been completed by the Arch Linux installer."
        echo ""
        PrintPrompt ReturnToContinue
        read crlm_answer
}

InstallRunLM ()
{
  CreateRunLM
}

StartBLM ()
{
    echo "To start your license manager use:"
    echo "  systemctl start basis_lmgrd"
    echo ""
    echo "To have your license mananger start at every boot use:"
    echo "  systemctl enable basis_lmgrd"
    echo ""
    echo "To check the status of your license manager"
    echo "  systemctl status basis_lmgrd"
    echo "  less ${_logfolder}/blm.log"
    echo ""
        PrintPrompt ReturnToContinue
        read crlm_answer
}

StopBLM ()
{
    echo "To stop your license manager use:"
    echo "  systemctl stop basis_lmgrd"
    echo ""
    echo "To stop your license mananger from starting at every boot use:"
    echo "  systemctl disable basis_lmgrd"
    echo ""
    echo "To check the status of your license manager"
    echo "  systemctl status basis_lmgrd"
    echo "  less ${_logfolder}/blm.log"
    echo ""
        PrintPrompt ReturnToContinue
        read crlm_answer
}
EOF
    touch -r "${_outfile}.Arch" "${_outfile}"
    rm "${_outfile}.Arch"
  fi

  # systemd support
  install -Dm644 <(cat << EOF
[Unit]
# Automatically generated by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR
# https://aur.archlinux.org/

Description=Basis License Manager for Pro/5 (BLM)
After=network.target

# Changing the user name here may require the following:
# rm -rf /var/tmp/{.flexlm,lockbasis}
# chmod root:group '${_logfolder}'
# chmod -R user:group '${_logfolder}'/*
[Service]
User=${_opt_blmgr_user}
Type=forking
ExecStart=${_basedir}/blmgr/BasisRunLM
ExecStop=${_basedir}/blmgr/lmutil lmdown -vendor basis
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
EOF
) "${pkgdir}/usr/lib/systemd/system/${_servicefile}"

  # Install a profile.d script. Branding makes this env variable unnecessary.
  # This variable requires a reboot or a relogin. Branding works immediately and
  # can't be broken by someone messing with profile scripts.
  if ! :; then
    local _licfile
    for _licfile in 'csh' 'sh'; do
      install -Dm755 <(cat << EOF
# Automatically generated by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR
# https://aur.archlinux.org/

# This file tells Basis Pro/5 where to look for it's license file

LM_LICENSE_FILE="${_basedir}/pro5/BASIS.lic"
export LM_LICENSE_FILE
EOF
) "${pkgdir}/etc/profile.d/basis_lmgr.${_licfile}"
    done
    unset _licfile
  fi

  # Fix script error in 14.0,15.00 that makes the user wonder why the installer doesn't reread the phone
  touch -r 'scripts/BasisReg' 'scripts/BasisReg.Arch'
  sed -e 's:"Delivery"[)]    :"Phone")blr_phone="${blr_propval}" ;;\n"Delivery") :g' -i 'scripts/BasisReg'
  touch -r 'scripts/BasisReg.Arch' 'scripts/BasisReg'
  rm 'scripts/BasisReg.Arch'

  # turns out that submission by OTHER works perfectly so we don't need all these hacks.
  # it's here in case someone wants to see how this can be done. The new BLM doesn't
  # register with install at all and has it's own online submission system.
  if ! :; then
    # Make a workable email system for those who don't have sendmail
    # Enable automatic operation
    sed -e 's: blr_orighostid="\$: $blr_readreturn\nblr_orighostid="\$:g' -i 'scripts/BasisReg'

    sed -e 's: glr_mthd="\$1":\nif [ "$glr_tmpfolder" = "" ]; then\n  glr_tmpfolder=".."\nfi\nglr_mthd="$1":g' \
        -e 's:\.\./\${glr_tmpfile}:${glr_tmpfolder}/${glr_tmpfile}:g' \
      -i 'scripts/BasisFuns'

    sed -e 's: blm|BLM[)]: email|EMAIL) cd "${CurDir}/blmgr";blr_readreturn="return";BasisLicRegister;glr_tmpfolder="/tmp";GenLicRequest EMAIL;echo "";echo "Generated $glr_tmpfolder/$glr_tmpfile";echo "";echo "How to send\:";echo "Compose new message in your email.";echo "Disable HTML or Rich Text--send as text only";echo "Subject\: (blank subject)";echo "Paste $glr_tmpfile into body (not as attachment)";echo "Copy To\: address to your To\: field";echo "Remove To\: address and first blank line from email body";echo "Erase or disable any signatures";echo "Send Email";echo "rm $glr_tmpfolder/$glr_tmpfile" ;;\nblm|BLM):g' -i 'install'

    local _emailfile="${srcdir}/genemail.sh"
    rm -f "${_emailfile}"
    cat > "${_emailfile}" << EOF
#!/bin/sh
# Automatically generated by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR
# https://aur.archlinux.org/
cd "\$(dirname "\$0"\)"
if [ ! -s 'blmgr/Register.properties' ]; then
  echo 'Please run the installer'
  echo 'BLM REG'
  echo 'Select EMAIL as your delivery preference'
else
  ./install email
fi
EOF

    install -Dpm755 "${_emailfile}" "${pkgdir}/${_basedir}"
    rm "${_emailfile}"
  fi

  # Root only for installer. Better than chmod 744.
  sed -e 's:^\(CurDir=\):if [ "${EUID}" -ne 0 ]; then\n  echo "Must be root"\n  exit 1\nfi\n\n \1:g' -i 'install'

  # select executable
  install -d "${pkgdir}/usr/bin"
  ln -s "${_basedir}/pro5/${_opt_pro5_sql}" "${pkgdir}/usr/bin/${_opt_pro5_exe}"

  # create bin links findable by the path
  local _pro5exe
  for _pro5exe in pro5{cpl,plot,lst}; do
    ln -s "${_basedir}/pro5/${_pro5exe}" "${pkgdir}/usr/bin/"
  done
  unset _pro5exe
  # a symlink is better than what the Basis installer does
  ln -s "${_opt_pro5_sql}" "${pkgdir}/${_basedir}/pro5/pro5"

  # Broken BLM writes files to /root
  install -dm750 "${pkgdir}/root"
  install -d "${pkgdir}/${_basedir}/blmgr/BLM"
  touch "${pkgdir}/${_basedir}/blmgr/BLM"/{Install.properties,install.log}
  ln -s "${_basedir}/blmgr" "${pkgdir}/root/BASIS"
  ln -s "${_basedir}/blmgr/BLM" "${pkgdir}/root/BLM"

  set +u
}

set +u