2020-07-10 14:05:54 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Script to generate mac application bundles for KOReader
|
2020-08-04 22:17:09 +00:00
|
|
|
#
|
|
|
|
# We don't use XCode at all. Just commandline tools.
|
|
|
|
#
|
|
|
|
# menu.xml contains the main menu of a typical OSX program.
|
|
|
|
# each time some user facing string in menu.xml changed we can
|
|
|
|
# generate a new translation template with:
|
|
|
|
#
|
|
|
|
# cp menu.xml menu.xib
|
|
|
|
# ibtool --generate-strings-file mac.strings menu.xib
|
|
|
|
# rm -rf menu.xib
|
|
|
|
#
|
|
|
|
# the generated "mac.strings" is in xliff format (binary, not plain text)
|
|
|
|
# and can be translated using an xliff editor or an online service that support
|
|
|
|
# IOS string format, like weblate.
|
|
|
|
|
2024-05-29 21:33:30 +00:00
|
|
|
set -eo pipefail
|
|
|
|
|
2020-07-17 19:17:15 +00:00
|
|
|
COPYRIGHT="Copyright © $(date +"%Y") KOReader"
|
2020-07-10 14:05:54 +00:00
|
|
|
|
|
|
|
command_exists() {
|
|
|
|
type "$1" >/dev/null 2>/dev/null
|
|
|
|
}
|
|
|
|
|
2024-05-29 21:33:30 +00:00
|
|
|
if ! [ -d "${1}" ]; then
|
2020-07-10 14:05:54 +00:00
|
|
|
echo "${0}: can't find KOReader build, please specify a path"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-05-29 21:33:30 +00:00
|
|
|
VERSION="$(cut -f2 -dv "${1}/koreader/git-rev" | cut -f1,2 -d-)"
|
|
|
|
APP_PATH="${1}/bundle"
|
|
|
|
APP_BUNDLE="${1}/../KOReader"
|
2024-06-02 16:22:46 +00:00
|
|
|
APP_ARCH="$(uname -m)"
|
2024-05-29 21:33:30 +00:00
|
|
|
OSX_MAJOR=$(sw_vers -productVersion | cut -d "." -f1)
|
|
|
|
OSX_MINOR=$(sw_vers -productVersion | cut -d "." -f2)
|
|
|
|
|
2020-07-17 19:17:15 +00:00
|
|
|
# minimum deployment target based on host version
|
|
|
|
if [ -z "${MACOSX_DEPLOYMENT_TARGET}" ]; then
|
|
|
|
if [ "${OSX_MAJOR}" == 11 ]; then
|
|
|
|
MACOSX_DEPLOYMENT_TARGET=10.14
|
|
|
|
elif [ "${OSX_MAJOR}" == 10 ]; then
|
|
|
|
MACOSX_DEPLOYMENT_TARGET="10.$((OSX_MINOR - 2))"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Generate PkgInfo and Info.plist
|
|
|
|
printf "APPL????" >"${APP_PATH}/Contents/PkgInfo"
|
|
|
|
cat <<END >"${APP_PATH}/Contents/Info.plist"
|
2020-07-10 14:05:54 +00:00
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
|
|
<plist version="1.0">
|
|
|
|
<dict>
|
2020-07-17 19:17:15 +00:00
|
|
|
<key>CFBundleDevelopmentRegion</key>
|
|
|
|
<string>English</string>
|
|
|
|
<key>CFBundleName</key>
|
|
|
|
<string>KOReader</string>
|
|
|
|
<key>CFBundleDisplayName</key>
|
2020-07-10 14:05:54 +00:00
|
|
|
<string>KOReader</string>
|
|
|
|
<key>CFBundleExecutable</key>
|
|
|
|
<string>koreader</string>
|
2020-07-17 19:17:15 +00:00
|
|
|
<key>CFBundleIconFile</key>
|
|
|
|
<string>icon.icns</string>
|
2020-07-10 14:05:54 +00:00
|
|
|
<key>CFBundleIdentifier</key>
|
2020-07-17 19:17:15 +00:00
|
|
|
<string>rocks.koreader</string>
|
2020-07-10 14:05:54 +00:00
|
|
|
<key>CFBundleShortVersionString</key>
|
|
|
|
<string>${VERSION}</string>
|
|
|
|
<key>CFBundleInfoDictionaryVersion</key>
|
|
|
|
<string>6.0</string>
|
|
|
|
<key>CFBundlePackageType</key>
|
|
|
|
<string>APPL</string>
|
2020-07-17 19:17:15 +00:00
|
|
|
<key>CFBundleSignature</key>
|
|
|
|
<string>????</string>
|
|
|
|
<key>CFBundleVersion</key>
|
|
|
|
<string>1.0</string>
|
|
|
|
<key>CFBundleDocumentTypes</key>
|
|
|
|
<array>
|
|
|
|
<dict>
|
|
|
|
<key>CFBundleTypeExtensions</key>
|
|
|
|
<array>
|
|
|
|
<string>azw</string>
|
|
|
|
<string>cbz</string>
|
|
|
|
<string>chm</string>
|
|
|
|
<string>djv</string>
|
|
|
|
<string>djvu</string>
|
|
|
|
<string>doc</string>
|
|
|
|
<string>docx</string>
|
|
|
|
<string>epub</string>
|
|
|
|
<string>fb2</string>
|
|
|
|
<string>htm</string>
|
|
|
|
<string>html</string>
|
|
|
|
<string>md</string>
|
|
|
|
<string>mobi</string>
|
|
|
|
<string>pdb</string>
|
|
|
|
<string>pdf</string>
|
|
|
|
<string>prc</string>
|
|
|
|
<string>rtf</string>
|
|
|
|
<string>txt</string>
|
|
|
|
<string>xhtml</string>
|
|
|
|
<string>xps</string>
|
|
|
|
</array>
|
|
|
|
<key>CFBundleTypeIconFile</key>
|
|
|
|
<string>icon</string>
|
|
|
|
<key>CFBundleTypeName</key>
|
|
|
|
<string>docs</string>
|
|
|
|
<key>CFBundleTypeRole</key>
|
|
|
|
<string>Viewer</string>
|
|
|
|
</dict>
|
|
|
|
</array>
|
|
|
|
<key>NSHumanReadableCopyright</key>
|
|
|
|
<string>${COPYRIGHT}</string>
|
|
|
|
<key>NSHighResolutionCapable</key>
|
|
|
|
<true/>
|
|
|
|
<key>NSPrincipalClass</key>
|
|
|
|
<string>NSApplication</string>
|
2020-08-04 22:17:09 +00:00
|
|
|
<key>NSMainNibFile</key>
|
|
|
|
<string>MainMenu</string>
|
2020-07-17 19:17:15 +00:00
|
|
|
<key>LSMultipleInstancesProhibited</key>
|
|
|
|
<true/>
|
|
|
|
<key>LSMinimumSystemVersion</key>
|
|
|
|
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
2020-08-04 22:17:09 +00:00
|
|
|
<key>SDL_FILESYSTEM_BASE_DIR_TYPE</key>
|
|
|
|
<string>bundle</string>
|
2020-07-10 14:05:54 +00:00
|
|
|
</dict>
|
|
|
|
</plist>
|
2020-07-17 19:17:15 +00:00
|
|
|
END
|
2020-07-10 14:05:54 +00:00
|
|
|
|
2024-05-29 21:33:30 +00:00
|
|
|
pushd "${APP_PATH}/Contents/koreader"
|
2020-07-10 14:05:54 +00:00
|
|
|
|
2024-05-29 21:33:30 +00:00
|
|
|
# Prepare bundle for distribution.
|
2024-06-02 16:22:46 +00:00
|
|
|
lipo /usr/bin/tar -extract_family "${APP_ARCH}" -output tar
|
2020-08-04 22:17:09 +00:00
|
|
|
mv COPYING README.md ../Resources/
|
|
|
|
mv koreader ../MacOS/koreader
|
2020-07-17 19:17:15 +00:00
|
|
|
rm -rf cache clipboard history ota \
|
|
|
|
l10n/.git l10n/.tx l10n/templates l10n/LICENSE l10n/Makefile l10n/README.md \
|
|
|
|
plugins/SSH.koplugin plugins/hello.koplugin plugins/timesync.koplugin \
|
|
|
|
plugins/autofrontlight.koplugin resources/fonts resources/icons/src \
|
2020-12-19 12:43:28 +00:00
|
|
|
rocks/bin rocks/lib/luarocks screenshots spec tools
|
2020-08-04 22:17:09 +00:00
|
|
|
|
2024-05-29 21:33:30 +00:00
|
|
|
# Adjust reader.lua a bit.
|
2020-08-04 22:17:09 +00:00
|
|
|
sed '1d' reader.lua >tempfile
|
|
|
|
sed -i.backup 's/.\/reader.lua/koreader/' tempfile
|
|
|
|
mv tempfile reader.lua
|
|
|
|
rm -f tempfile*
|
|
|
|
chmod -x reader.lua
|
2024-05-29 21:33:30 +00:00
|
|
|
popd
|
2020-07-10 14:05:54 +00:00
|
|
|
|
2024-05-29 21:33:30 +00:00
|
|
|
# Bundle translations, if any.
|
2020-08-04 22:17:09 +00:00
|
|
|
for path in l10n/*; do
|
|
|
|
lang=$(echo "${path}" | sed s'/l10n\///')
|
|
|
|
if [ "${lang}" != "templates" ]; then
|
|
|
|
translation_file="l10n/${lang}/mac.strings"
|
|
|
|
if [ -f "${translation_file}" ]; then
|
|
|
|
mkdir -p "${APP_PATH}/Contents/Resources/${lang}.lproj"
|
|
|
|
cp -pv "${translation_file}" "${APP_PATH}/Contents/Resources/${lang}.lproj/MainMenu.strings"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-07-10 14:05:54 +00:00
|
|
|
mv "${APP_PATH}" "${APP_BUNDLE}.app"
|
2024-06-02 16:22:47 +00:00
|
|
|
codesign --force --deep -s - "${APP_BUNDLE}.app"
|
2020-08-04 22:17:09 +00:00
|
|
|
|
2024-05-29 21:33:30 +00:00
|
|
|
# Package as 7z reduces size from 80MB to 30MB.
|
2020-12-11 14:16:29 +00:00
|
|
|
if command_exists "7z"; then
|
2024-06-02 16:22:46 +00:00
|
|
|
7z a -l -m0=lzma2 -mx=9 "${APP_BUNDLE}-${APP_ARCH}-${VERSION}.7z" "${APP_BUNDLE}.app"
|
2020-12-11 14:16:29 +00:00
|
|
|
rm -rfv "${APP_BUNDLE}.app"
|
2020-07-10 14:05:54 +00:00
|
|
|
fi
|