2011-04-20 12:14:44 +00:00
|
|
|
#!/bin/bash
|
2018-04-25 00:50:29 +00:00
|
|
|
# Build the macOS installer for the tokend and command line tools.
|
|
|
|
#
|
|
|
|
# This is only tested and supported on macOS 10.10 or later, using Xcode 6.0.1.
|
|
|
|
# Building should also work on older macOS versions with slight changes; YMMV.
|
2013-02-20 12:08:29 +00:00
|
|
|
|
2018-04-25 00:50:29 +00:00
|
|
|
# You need to install the following packages from homebrew or macports or fink:
|
|
|
|
# autoconf automake libtool pkg-config help2man gengetopt
|
2014-10-26 09:48:57 +00:00
|
|
|
|
2018-04-24 21:05:43 +00:00
|
|
|
export MACOSX_DEPLOYMENT_TARGET="10.10"
|
2017-10-13 11:31:57 +00:00
|
|
|
|
2011-04-20 12:14:44 +00:00
|
|
|
set -ex
|
|
|
|
test -x ./configure || ./bootstrap
|
|
|
|
BUILDPATH=${PWD}
|
2013-03-30 09:13:26 +00:00
|
|
|
|
2014-10-26 09:48:57 +00:00
|
|
|
# Locate the latest OSX SDK
|
2017-02-28 22:30:43 +00:00
|
|
|
SDK_PATH=$(xcrun --sdk macosx --show-sdk-path)
|
2014-10-25 17:07:36 +00:00
|
|
|
|
|
|
|
# Set SDK path
|
2017-11-14 20:56:43 +00:00
|
|
|
export CFLAGS="$CFLAGS -isysroot $SDK_PATH -arch x86_64"
|
2013-03-30 09:13:26 +00:00
|
|
|
|
2020-04-06 13:42:30 +00:00
|
|
|
# xcodebuild doesn't read the environment variables
|
2020-05-27 21:38:49 +00:00
|
|
|
# transform them into parameters
|
|
|
|
P1="${CODE_SIGN_IDENTITY:+CODE_SIGN_IDENTITY=${CODE_SIGN_IDENTITY}}"
|
|
|
|
P2="${OTHER_CODE_SIGN_FLAGS:+OTHER_CODE_SIGN_FLAGS=${OTHER_CODE_SIGN_FLAGS}}"
|
|
|
|
P3="${CODE_SIGN_INJECT_BASE_ENTITLEMENTS:+CODE_SIGN_INJECT_BASE_ENTITLEMENTS=${CODE_SIGN_INJECT_BASE_ENTITLEMENTS}}"
|
|
|
|
P4="${CODE_SIGN_STYLE:+CODE_SIGN_STYLE=${CODE_SIGN_STYLE}}"
|
2020-04-06 13:42:30 +00:00
|
|
|
|
2011-04-20 12:14:44 +00:00
|
|
|
export SED=/usr/bin/sed
|
|
|
|
PREFIX=/Library/OpenSC
|
2016-06-03 23:36:14 +00:00
|
|
|
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig
|
2011-04-20 12:14:44 +00:00
|
|
|
|
2016-05-18 14:10:00 +00:00
|
|
|
if ! pkg-config libcrypto --atleast-version=1.0.1; then
|
|
|
|
# OpenSSL is not installed
|
2016-10-14 12:02:21 +00:00
|
|
|
if ! test -e $BUILDPATH/openssl_bin/$PREFIX/lib/pkgconfig; then
|
2016-05-18 14:10:00 +00:00
|
|
|
# Build OpenSSL manually, because Apple's binaries are deprecated
|
|
|
|
if ! test -e openssl; then
|
2020-02-13 13:12:22 +00:00
|
|
|
git clone --depth=1 https://github.com/openssl/openssl.git -b OpenSSL_1_1_1-stable
|
2016-05-18 14:10:00 +00:00
|
|
|
fi
|
|
|
|
cd openssl
|
2020-06-03 14:49:35 +00:00
|
|
|
KERNEL_BITS=64 ./config no-shared --prefix=$PREFIX
|
2016-10-14 12:12:15 +00:00
|
|
|
make clean
|
2019-01-02 09:39:51 +00:00
|
|
|
make -j 4
|
2020-02-13 13:12:22 +00:00
|
|
|
make DESTDIR=$BUILDPATH/openssl_bin install_sw
|
2016-05-18 14:10:00 +00:00
|
|
|
cd ..
|
|
|
|
fi
|
|
|
|
export OPENSSL_CFLAGS="`env PKG_CONFIG_PATH=$BUILDPATH/openssl_bin/$PREFIX/lib/pkgconfig PKG_CONFIG_SYSROOT_DIR=$BUILDPATH/openssl_bin pkg-config --static --cflags libcrypto`"
|
|
|
|
export OPENSSL_LIBS="` env PKG_CONFIG_PATH=$BUILDPATH/openssl_bin/$PREFIX/lib/pkgconfig PKG_CONFIG_SYSROOT_DIR=$BUILDPATH/openssl_bin pkg-config --static --libs libcrypto`"
|
|
|
|
fi
|
|
|
|
|
2017-03-23 15:45:31 +00:00
|
|
|
if ! test -e $BUILDPATH/openpace_bin/$PREFIX/lib/pkgconfig; then
|
|
|
|
if ! test -e openpace; then
|
2019-04-25 13:25:02 +00:00
|
|
|
git clone --depth=1 https://github.com/frankmorgner/openpace.git -b 1.1.0
|
2017-03-23 15:45:31 +00:00
|
|
|
fi
|
|
|
|
cd openpace
|
|
|
|
autoreconf -vis
|
2020-03-06 13:31:08 +00:00
|
|
|
./configure --disable-shared --prefix=$PREFIX CRYPTO_CFLAGS="$OPENSSL_CFLAGS" CRYPTO_LIBS="$OPENSSL_LIBS" HELP2MAN=/usr/bin/true
|
|
|
|
touch src/cvc-create.1 src/cvc-print.1
|
2017-03-23 15:45:31 +00:00
|
|
|
make DESTDIR=$BUILDPATH/openpace_bin install
|
|
|
|
cd ..
|
|
|
|
fi
|
2019-04-03 12:50:04 +00:00
|
|
|
export OPENPACE_CFLAGS="`env PKG_CONFIG_PATH=$BUILDPATH/openssl_bin/$PREFIX/lib/pkgconfig:$BUILDPATH/openpace_bin/$PREFIX/lib/pkgconfig PKG_CONFIG_SYSROOT_DIR=$BUILDPATH/openpace_bin pkg-config --static --cflags libeac` $OPENSSL_CFLAGS"
|
|
|
|
export OPENPACE_LIBS="` env PKG_CONFIG_PATH=$BUILDPATH/openssl_bin/$PREFIX/lib/pkgconfig:$BUILDPATH/openpace_bin/$PREFIX/lib/pkgconfig PKG_CONFIG_SYSROOT_DIR=$BUILDPATH/openpace_bin pkg-config --static --libs libeac` $OPENSSL_LIBS"
|
2017-03-23 15:45:31 +00:00
|
|
|
|
2016-10-12 12:52:48 +00:00
|
|
|
if ! test -e ${BUILDPATH}/target/$PREFIX/lib/pkgconfig; then
|
|
|
|
./configure --prefix=$PREFIX \
|
|
|
|
--sysconfdir=$PREFIX/etc \
|
2017-03-23 15:45:31 +00:00
|
|
|
--enable-cvcdir=$PREFIX/etc/cvc \
|
|
|
|
--enable-x509dir=$PREFIX/etc/x509 \
|
2018-11-05 10:16:04 +00:00
|
|
|
--enable-openssl-secure-malloc=65536 \
|
2016-10-12 12:52:48 +00:00
|
|
|
--disable-dependency-tracking \
|
|
|
|
--enable-shared \
|
2017-10-30 10:13:57 +00:00
|
|
|
--enable-static \
|
2016-10-12 12:52:48 +00:00
|
|
|
--enable-strict \
|
|
|
|
--disable-assert \
|
|
|
|
--enable-sm # TODO: remove this (must be sensible default in master)
|
2011-04-20 12:14:44 +00:00
|
|
|
|
2016-10-12 12:52:48 +00:00
|
|
|
# always make clean
|
|
|
|
make clean
|
2011-04-20 12:14:44 +00:00
|
|
|
|
2016-10-12 12:52:48 +00:00
|
|
|
# compile
|
2019-01-02 09:39:51 +00:00
|
|
|
make -j 4
|
2011-04-20 12:14:44 +00:00
|
|
|
|
2016-10-12 12:52:48 +00:00
|
|
|
# copy files
|
2017-10-13 11:31:57 +00:00
|
|
|
rm -rf ${BUILDPATH}/target
|
2016-10-12 12:52:48 +00:00
|
|
|
make install DESTDIR=${BUILDPATH}/target
|
2011-04-20 12:14:44 +00:00
|
|
|
|
2016-10-12 12:52:48 +00:00
|
|
|
# remove garbage
|
2017-10-13 11:31:57 +00:00
|
|
|
rm -f ${BUILDPATH}/target/$PREFIX/lib/*.la
|
2017-10-30 10:13:57 +00:00
|
|
|
rm -f ${BUILDPATH}/target/$PREFIX/lib/*.a
|
2011-04-20 12:14:44 +00:00
|
|
|
|
2016-10-12 12:52:48 +00:00
|
|
|
# generate .bundle (required by Adobe Acrobat)
|
2017-10-13 11:31:57 +00:00
|
|
|
./MacOSX/libtool-bundle ${BUILDPATH}/target/$PREFIX/lib/opensc-pkcs11.so ${BUILDPATH}/target/$PREFIX/lib
|
2016-10-12 12:52:48 +00:00
|
|
|
fi
|
2011-04-20 12:14:44 +00:00
|
|
|
|
2019-12-02 07:22:34 +00:00
|
|
|
|
|
|
|
if ! test -e NotificationProxy; then
|
|
|
|
git clone http://github.com/frankmorgner/NotificationProxy.git
|
|
|
|
fi
|
2020-05-27 21:53:11 +00:00
|
|
|
if test -n "${CODE_SIGN_IDENTITY}"; then
|
|
|
|
xcodebuild -target NotificationProxy -configuration Release -project NotificationProxy/NotificationProxy.xcodeproj install DSTROOT=$BUILDPATH/target/Library/OpenSC/ "$P1" "$P2" "$P3" "$P4"
|
|
|
|
else
|
|
|
|
xcodebuild -target NotificationProxy -configuration Release -project NotificationProxy/NotificationProxy.xcodeproj install DSTROOT=$BUILDPATH/target/Library/OpenSC/
|
|
|
|
fi
|
2019-12-02 07:22:34 +00:00
|
|
|
mkdir -p "$BUILDPATH/target/Applications"
|
|
|
|
osacompile -o "$BUILDPATH/target/Applications/OpenSC Notify.app" "MacOSX/OpenSC_Notify.applescript"
|
|
|
|
|
|
|
|
|
2020-01-27 21:42:46 +00:00
|
|
|
# Build OpenSC.tokend when XCode version < 10
|
2020-05-01 10:48:10 +00:00
|
|
|
if (( $(xcodebuild -version | sed -En 's/Xcode[[:space:]]+([0-9]+)(\.[0-9]*)*/\1/p') < 10 )); then
|
2020-01-27 21:42:46 +00:00
|
|
|
# Check out OpenSC.tokend, if not already fetched.
|
|
|
|
if ! test -e OpenSC.tokend; then
|
|
|
|
git clone http://github.com/OpenSC/OpenSC.tokend.git
|
|
|
|
fi
|
2011-04-20 12:14:44 +00:00
|
|
|
|
2020-01-27 21:42:46 +00:00
|
|
|
# Create the symlink to OpenSC sources
|
|
|
|
test -L OpenSC.tokend/build/opensc-src || ln -sf ${BUILDPATH}/src OpenSC.tokend/build/opensc-src
|
2011-04-20 12:14:44 +00:00
|
|
|
|
2019-10-17 21:28:38 +00:00
|
|
|
# Build and copy OpenSC.tokend
|
2020-05-27 21:53:11 +00:00
|
|
|
if test -n "${CODE_SIGN_IDENTITY}"; then
|
|
|
|
xcodebuild -target OpenSC -configuration Deployment -project OpenSC.tokend/Tokend.xcodeproj install DSTROOT=${BUILDPATH}/target_tokend "$P1" $P2 "$P3" "$P4"
|
|
|
|
else
|
|
|
|
xcodebuild -target OpenSC -configuration Deployment -project OpenSC.tokend/Tokend.xcodeproj install DSTROOT=${BUILDPATH}/target_tokend
|
|
|
|
fi
|
2019-10-17 21:28:38 +00:00
|
|
|
else
|
|
|
|
# https://github.com/OpenSC/OpenSC.tokend/issues/33
|
|
|
|
mkdir -p ${BUILDPATH}/target_tokend
|
|
|
|
fi
|
2017-05-24 10:46:42 +00:00
|
|
|
|
2018-04-24 21:05:43 +00:00
|
|
|
#if ! test -e $BUILDPATH/target/Library/Security/tokend/OpenSC.tokend/Contents/Resources/Applications/terminal-notifier.app; then
|
|
|
|
#if ! test -e terminal-notifier-1.7.1.zip; then
|
|
|
|
#curl -L https://github.com/julienXX/terminal-notifier/releases/download/1.7.1/terminal-notifier-1.7.1.zip > terminal-notifier-1.7.1.zip
|
|
|
|
#fi
|
|
|
|
#if ! test -e terminal-notifier-1.7.1; then
|
|
|
|
#unzip terminal-notifier-1.7.1.zip
|
|
|
|
#fi
|
|
|
|
#mkdir -p $BUILDPATH/target/Library/Security/tokend/OpenSC.tokend/Contents/Resources/Applications
|
|
|
|
#cp -r terminal-notifier-1.7.1/terminal-notifier.app $BUILDPATH/target/Library/Security/tokend/OpenSC.tokend/Contents/Resources/Applications
|
|
|
|
#fi
|
2017-05-24 10:46:42 +00:00
|
|
|
|
2017-12-05 07:27:55 +00:00
|
|
|
imagedir=$(mktemp -d)
|
|
|
|
|
2013-12-18 09:48:02 +00:00
|
|
|
# Prepare target root
|
2017-10-13 11:31:57 +00:00
|
|
|
mkdir -p ${BUILDPATH}/target/usr/local/bin
|
|
|
|
cp MacOSX/opensc-uninstall ${BUILDPATH}/target/usr/local/bin
|
2011-04-20 12:14:44 +00:00
|
|
|
|
2019-03-18 22:08:58 +00:00
|
|
|
# Prepare startup root
|
|
|
|
mkdir -p ${BUILDPATH}/target_startup/Library/LaunchAgents
|
|
|
|
cp src/tools/pkcs11-register.plist ${BUILDPATH}/target_startup/Library/LaunchAgents
|
2019-03-22 16:03:26 +00:00
|
|
|
cp src/tools/opensc-notify.plist ${BUILDPATH}/target_startup/Library/LaunchAgents
|
2019-03-18 22:08:58 +00:00
|
|
|
|
2019-10-17 21:28:38 +00:00
|
|
|
# Build OpenSCToken if possible
|
2020-05-27 21:53:11 +00:00
|
|
|
if test -e OpenSCToken -a -n "${CODE_SIGN_IDENTITY}"; then
|
2019-10-17 21:28:38 +00:00
|
|
|
cd OpenSCToken
|
|
|
|
# make sure OpenSCToken builds with the same dependencies as before
|
|
|
|
if ! test -e OpenSC; then
|
2020-04-06 13:42:30 +00:00
|
|
|
git clone --depth=1 file://$PWD/../../OpenSC
|
2019-10-17 21:28:38 +00:00
|
|
|
else
|
|
|
|
cd OpenSC && git pull && cd ..
|
|
|
|
fi
|
2020-04-06 13:42:30 +00:00
|
|
|
mkdir -p build
|
|
|
|
if ! test -e build/openssl; then
|
|
|
|
# build/openssl/lib/libcrypto.a is hardcoded in OpenSCToken
|
|
|
|
ln -sf $BUILDPATH/openssl_bin/$PREFIX build/openssl
|
|
|
|
# in OpenSCToken's variant of OpenSC we still use OpenSSL flags from above
|
2019-10-17 21:28:38 +00:00
|
|
|
fi
|
2020-04-06 13:42:30 +00:00
|
|
|
if ! test -e build/openpace; then
|
|
|
|
# build/openpace/lib/libeac.a is hardcoded in OpenSCToken
|
|
|
|
ln -sf $BUILDPATH/openpace_bin/$PREFIX build/openpace
|
|
|
|
# in OpenSCToken's variant of OpenSC we still use OpenPACE flags from above
|
2019-10-17 21:28:38 +00:00
|
|
|
fi
|
|
|
|
BP=${BUILDPATH}
|
|
|
|
. ./bootstrap
|
|
|
|
BUILDPATH=${BP}
|
2020-05-27 21:53:11 +00:00
|
|
|
xcodebuild -target OpenSCTokenApp -configuration Debug -project OpenSCTokenApp.xcodeproj install DSTROOT=${BUILDPATH}/target_token "$P1" "$P2" "$P3" "$P4"
|
2019-10-17 21:28:38 +00:00
|
|
|
cd ..
|
|
|
|
else
|
|
|
|
# if no OpenSCToken is checked out, then we create a dummy package
|
|
|
|
mkdir -p ${BUILDPATH}/target_token
|
|
|
|
fi
|
|
|
|
|
2013-12-18 09:48:02 +00:00
|
|
|
# Build package
|
2017-10-13 11:31:57 +00:00
|
|
|
pkgbuild --root ${BUILDPATH}/target --scripts MacOSX/scripts --identifier org.opensc-project.mac --version @PACKAGE_VERSION@ --install-location / OpenSC.pkg
|
2019-02-11 10:14:41 +00:00
|
|
|
pkgbuild --root ${BUILDPATH}/target_tokend --identifier org.opensc-project.tokend --version @PACKAGE_VERSION@ --install-location / OpenSC-tokend.pkg
|
2019-10-17 21:28:38 +00:00
|
|
|
pkgbuild --root ${BUILDPATH}/target_token --identifier org.opensc-project.mac.opensctoken --version @PACKAGE_VERSION@ --install-location / OpenSCToken.pkg
|
2019-03-18 22:08:58 +00:00
|
|
|
pkgbuild --root ${BUILDPATH}/target_startup --identifier org.opensc-project.startup --version @PACKAGE_VERSION@ --install-location / OpenSC-startup.pkg
|
2019-10-17 21:28:38 +00:00
|
|
|
|
2013-12-18 09:48:02 +00:00
|
|
|
# Build product
|
2017-12-05 07:27:55 +00:00
|
|
|
productbuild --distribution MacOSX/Distribution.xml --package-path . --resources MacOSX/resources "${imagedir}/OpenSC @PACKAGE_VERSION@.pkg"
|
2011-04-20 12:14:44 +00:00
|
|
|
|
2017-10-13 11:31:57 +00:00
|
|
|
# Build "Uninstaller"
|
2017-12-05 07:27:55 +00:00
|
|
|
osacompile -o "${imagedir}/OpenSC Uninstaller.app" "MacOSX/OpenSC_Uninstaller.applescript"
|
2014-01-04 16:30:09 +00:00
|
|
|
|
2011-04-20 12:14:44 +00:00
|
|
|
# Create .dmg
|
2013-02-20 12:08:29 +00:00
|
|
|
rm -f OpenSC-@PACKAGE_VERSION@.dmg
|
2015-09-03 03:41:20 +00:00
|
|
|
i=0
|
2018-08-24 07:27:13 +00:00
|
|
|
while ! hdiutil create -srcfolder "${imagedir}" -volname "@PACKAGE_NAME@" -fs JHFS+ OpenSC-@PACKAGE_VERSION@.dmg
|
2015-09-03 03:41:20 +00:00
|
|
|
do
|
|
|
|
i=$[$i+1]
|
|
|
|
if [ $i -gt 2 ]
|
|
|
|
then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
2017-12-05 07:27:55 +00:00
|
|
|
rm -rf ${imagedir}
|