File: postinstall

package info (click to toggle)
opensc 0.26.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,420 kB
  • sloc: ansic: 178,823; xml: 6,327; sh: 2,115; makefile: 1,023; cpp: 304; lex: 92
file content (63 lines) | stat: -rwxr-xr-x 1,933 bytes parent folder | download | duplicates (4)
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
#!/bin/bash

# copy libs to /usr/local/lib
cp /Library/OpenSC/lib/opensc-pkcs11.so \
  /Library/OpenSC/lib/onepin-opensc-pkcs11.so \
  /usr/local/lib/

# install opensc.conf if it hasn't been locally modified
# shellcheck disable=SC2043
for f in /Library/OpenSC/etc/opensc.conf; do
  if [ -e "${f}.md5" ]; then
    read -r cs_fromfile _ < "${f}.md5"
    cs_calculated="$(md5 -q "${f}")"
    if [ "$cs_fromfile" != "$cs_calculated" ]; then
      echo "config ${f} was locally modified since last install, skipping" 2>&1
      continue
    fi
  fi
  cp "${f}.orig" "$f"
  md5 -r "$f"  >"${f}.md5"
done

# symlink other files to /usr/local
for f in \
  /Library/OpenSC/bin/* \
  /Library/OpenSC/etc/bash_completion.d/* \
  /Library/OpenSC/share/doc/*
do
  [ -e "$f" ] || continue # keep this or set "shopt -s nullglob"
  a=/Library/OpenSC
  b=/usr/local
  l="${f/$a/$b}" # parameter expansion, returns $f where $a is replaced by $b
  mkdir -p "$(dirname "$l")"
  ln -sf "$f" "$l"
done

# correct past issue where a literal shell glob character was symlinked
# e.g. /usr/local/share/man/man1/* -> /Library/OpenSC/share/man/man1/*
# maybe remove this step post 2022?
for f in \
  '/usr/local/share/man/man1/*' \
  '/usr/local/share/man/man5/*'
do
  [ -L "$f" ] || continue # skip unless $f is a symlink
  t="$(readlink "$f")"
  [ -e "$t" ] && continue # skip if the symlink target actually exists
  a=/usr/local
  b=/Library/OpenSC
  [ "$t" = "${f/$a/$b}" ] || continue # skip unless the target is in the corresponding /Library/OpenSC subdirectory
  # we can now assume that we originally made $f and can safely remove it
  unlink "$f"
done

# register the launch agents
for f in \
  /Library/LaunchAgents/org.opensc-project.mac.pkcs11-register.plist \
  /Library/LaunchAgents/org.opensc-project.mac.opensc-notify.plist
do
  [ -e "$f" ] || continue
  /bin/launchctl asuser "$(id -u "$USER")" /bin/launchctl load "$f" || true
done

exit 0