2010-08-25 08:44:32 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-08-14 12:10:43 +00:00
|
|
|
# copy libs to /usr/local/lib
|
|
|
|
cp /Library/OpenSC/lib/opensc-pkcs11.so \
|
|
|
|
/Library/OpenSC/lib/onepin-opensc-pkcs11.so \
|
|
|
|
/usr/local/lib/
|
2019-03-22 16:03:26 +00:00
|
|
|
|
2020-08-14 12:10:43 +00:00
|
|
|
# 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?
|
2019-04-25 12:48:42 +00:00
|
|
|
for f in \
|
2020-08-14 12:10:43 +00:00
|
|
|
'/usr/local/share/man/man1/*' \
|
|
|
|
'/usr/local/share/man/man5/*'
|
2010-08-25 08:44:32 +00:00
|
|
|
do
|
2020-08-14 12:10:43 +00:00
|
|
|
[ -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"
|
2010-08-25 08:44:32 +00:00
|
|
|
done
|
2019-03-22 16:03:26 +00:00
|
|
|
|
2020-08-14 12:10:43 +00:00
|
|
|
# register the launch agents
|
2019-04-25 12:48:42 +00:00
|
|
|
for f in \
|
2020-11-04 16:38:30 +00:00
|
|
|
/Library/LaunchAgents/org.opensc-project.mac.pkcs11-register.plist \
|
|
|
|
/Library/LaunchAgents/org.opensc-project.mac.opensc-notify.plist
|
2019-03-22 16:03:26 +00:00
|
|
|
do
|
2020-08-14 12:10:43 +00:00
|
|
|
[ -e "$f" ] || continue
|
|
|
|
/bin/launchctl asuser "$(id -u "$USER")" /bin/launchctl load "$f" || true
|
2019-03-22 16:03:26 +00:00
|
|
|
done
|
|
|
|
|
2010-08-25 08:44:32 +00:00
|
|
|
exit 0
|