-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathmkdsm_macos.sh
130 lines (114 loc) · 4.11 KB
/
mkdsm_macos.sh
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
#!/bin/bash
#
# Build the DSM on macOS, and create a package file, which
# is wrapped in a disk image, and then compress it. We'll
# put the finished result on the desktop...
#
# Say hi...
echo ""
echo "Build the DSM..."
# Init stuff...
VERSION=`printf "%02d.%02d.%02d.00" "${DSMMAJOR}" "${DSMMINOR}" "${DSMBUILD}"`
SIGNER=`cat signer`
SCRIPTDIR=$( cd $(dirname "${BASH_SOURCE}"); pwd )
BLDDIR="${SCRIPTDIR}/TWAIN_DSM/build/Release"
TMPDIR="/private/tmp/twaindsm"
PKGDIR="${TMPDIR}/pkg"
DSTDIR="${TMPDIR}/dst"
DMGDIR="${TMPDIR}/dmg"
DESKTOPDIR="${HOME}/Desktop"
# Fix the version
/usr/libexec/PlistBuddy -c "Set CFBundleVersion ${DSMMAJOR}.${DSMMINOR}.${DSMBUILD}" "TWAIN_DSM/Info.plist"
/usr/libexec/PlistBuddy -c "Set CFBundleShortVersionString ${DSMMAJOR}.${DSMMINOR}.${DSMBUILD}" "TWAIN_DSM/Info.plist"
# Get the folders ready...
rm -rf "${TMPDIR}" >/dev/null 2>&1
rm "${DESKTOPDIR}/twaindsm-${DSMMAJOR}.${DSMMINOR}.${DSMBUILD}.dmg.gz" >/dev/null 2>&1
mkdir -p "${TMPDIR}"
mkdir -p "${PKGDIR}"
mkdir -p "${DSTDIR}"
mkdir -p "${DMGDIR}"
# Build the project, drop into it to do this...
echo "run xcodebuild..."
pushd "${SCRIPTDIR}/TWAIN_DSM" >/dev/null 2>&1
xcodebuild clean build | egrep '^(/.+:[0-9+:[0-9]+:.(error|warning):|fatal|===)'
popd >/dev/null 2>&1
# Create the package folder, and the rooted path to where
# we'll be installing it on the target machines, and then
# copy our stuff over...
echo "build the package folder..."
mkdir -p "${PKGDIR}/Library/Frameworks"
cp -R "${BLDDIR}/TWAINDSM.framework" "${PKGDIR}/Library/Frameworks"
# Fix the owner, group, and mode...
chown -R root "${PKGDIR}/Library"
chgrp -R wheel "${PKGDIR}/Library"
chmod -R 755 "${PKGDIR}/Library"
# Sign our binary...
echo "sign the binary..."
if [ "${SIGNER}" == "" ]; then
echo "**************************************************"
echo "* signer file not found, nothing will be signed. *"
echo "* If you want to sign the DSM and the installer, *"
echo "* then put the certificate name in a file named *"
echo "* signer. This certificate will have to be in *"
echo "* your keychain. *"
echo "**************************************************"
else
echo "signer: ${SIGNER}"
codesign -f -s "${SIGNER}" "${PKGDIR}/Library/Frameworks/TWAINDSM.Framework/Versions/A/TWAINDSM"
fi
# Build the package
if [ "${SIGNER}" == "" ]; then
pkgbuild\
--identifier com.twain.dsm.pkg\
--version "${VERSION}"\
--root "${PKGDIR}"\
"${DSTDIR}/twaindsm-${DSMMAJOR}.${DSMMINOR}.${DSMBUILD}.pkg"
else
pkgbuild\
--identifier com.twain.dsm.pkg\
--version "${VERSION}"\
--sign "${SIGNER}"\
--root "${PKGDIR}"\
"${DSTDIR}/twaindsm-${DSMMAJOR}.${DSMMINOR}.${DSMBUILD}.pkg"
fi
if [ "$?" != "0" ]; then
echo "pkgbuild failed..."
exit 1
fi
# Fix the owner and the group...
chown -R root "${PKGDIR}"
chgrp -R wheel "${PKGDIR}"
# Create the disk image
echo "creating the disk image..."
pushd "${TMPDIR}" >/dev/null 2>&1
hdiutil create -srcfolder "${DSTDIR}" -fs HFS+ -volname "twaindsm-${DSMMAJOR}.${DSMMINOR}.${DSMBUILD}.pkg" "${DMGDIR}/tmp.dmg" >/dev/null 2>&1
if [ "$?" != "0" ]; then
echo "hdiutil create failed"
exit 1
fi
popd >/dev/null 2>&1
# This makes the disk read only, and moves it to the desktop...
echo "converting the disk image..."
hdiutil convert -format UDRO -o "${DESKTOPDIR}/twaindsm-${DSMMAJOR}.${DSMMINOR}.${DSMBUILD}.dmg" "${DMGDIR}/tmp.dmg" >/dev/null 2>&1
if [ "$?" != "0" ]; then
echo "hdiutil convert failed..."
exit 1
fi
chown root "${DESKTOPDIR}/twaindsm-${DSMMAJOR}.${DSMMINOR}.${DSMBUILD}.dmg"
chgrp wheel "${DESKTOPDIR}/twaindsm-${DSMMAJOR}.${DSMMINOR}.${DSMBUILD}.dmg"
# And this zips the disk image into the final form, which is "twaindsm.dmg.gz":
echo "Zip it up..."
pushd ${DESKTOPDIR} >/dev/null 2>&1
gzip "twaindsm-${DSMMAJOR}.${DSMMINOR}.${DSMBUILD}.dmg"
if [ "$?" != "0" ]; then
echo "gzip failed..."
popd
exit 1
fi
popd >/dev/null 2>&1
# Drop a copy of the DSM into the DMS folder for this version...
echo "Copy to ${DSMDIR}/macosx..."
mkdir -p "${DSMDIR}/macosx" >/dev/null 2>&1
cp "${DESKTOPDIR}/twaindsm-${DSMMAJOR}.${DSMMINOR}.${DSMBUILD}.dmg.gz" "${DSMDIR}/macosx/"
#Cleanup...
rm -rf "${TMPDIR}"