Skip to content

Commit

Permalink
Merge pull request #11 from suvash/use-pkgbuild-for-installation
Browse files Browse the repository at this point in the history
Use pkgbuild + productbuild for creating installer packages
  • Loading branch information
suvash committed Jul 18, 2020
2 parents 72c805d + a3584ac commit d881642
Show file tree
Hide file tree
Showing 23 changed files with 301 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.zip
*.mpkg
build/
76 changes: 76 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.DEFAULT_GOAL=help
SHELL:=/usr/bin/env bash

APP_ORG:=com.thapaliya
APP_ID:=nepali-romanized
APP_PKG:=install

APP_PKG_ID:=$(APP_ORG).$(APP_ID).$(APP_PKG)
$(info -- APP_PKG_ID is set to $(APP_PKG_ID))

# Remember to bump the version in Info.plist as well
APP_VERSION:=4.0
$(info -- APP_VERSION is set to $(APP_VERSION))

BUILD_DIR:=build
BUILD_TIMESTAMP:=$(shell TZ=Asia/Katmandu date)

$(info -- )

.PHONY: help clean buil build-install-package build-productd

help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-10s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)

clean: ## Clean build directory
$(info -- Cleaning build directory)
rm -rf $(BUILD_DIR)

build: clean build-install-package build-product ## Build the final product

build-install-package:
$(info -- Preparing installation package directory)
mkdir -p $(BUILD_DIR)/installpkgroot/Library/Keyboard\ Layouts/
cp -aR lib/$(APP_ID).bundle $(BUILD_DIR)/installpkgroot/Library/Keyboard\ Layouts/
$(info -- Building installation package)
mkdir -p $(BUILD_DIR)/package/
pkgbuild --identifier $(APP_PKG_ID) \
--version $(APP_VERSION) \
--root $(BUILD_DIR)/installpkgroot \
--scripts pkgdeps/scripts \
$(BUILD_DIR)/package/$(APP_PKG_ID).pkg

build-product:
$(info -- Preparing installation product directory)
mkdir -p $(BUILD_DIR)/product/
cp -Rv productdeps $(BUILD_DIR)/_productdeps
sed -i '' -e 's/__APP_VERSION__/$(APP_VERSION)/g' $(BUILD_DIR)/_productdeps/distribution.xml
sed -i '' -e 's/__BUILD_TIMESTAMP__/$(BUILD_TIMESTAMP)/g' $(BUILD_DIR)/_productdeps/distribution.xml
sed -i '' -e 's/__APP_PKG_ID__/$(APP_PKG_ID)/g' $(BUILD_DIR)/_productdeps/distribution.xml
$(info -- Building installation product)
productbuild --distribution $(BUILD_DIR)/_productdeps/distribution.xml \
--resources $(BUILD_DIR)/_productdeps/Resources \
--package-path $(BUILD_DIR)/package \
$(BUILD_DIR)/product/$(APP_ID)-$(APP_VERSION).pkg

icon: ## Build the icns from the input PNG file
$(info -- Building icns file from original png)
mkdir -p /tmp/np-icon-tmpdir.iconset
cp assets/original/ne.png /tmp/np-icon-tmpdir.iconset/icon.png
sips -z 16 16 /tmp/np-icon-tmpdir.iconset/icon.png --out /tmp/np-icon-tmpdir.iconset/icon_16x16.png
sips -z 32 32 /tmp/np-icon-tmpdir.iconset/icon.png --out /tmp/np-icon-tmpdir.iconset/[email protected]
sips -z 32 32 /tmp/np-icon-tmpdir.iconset/icon.png --out /tmp/np-icon-tmpdir.iconset/icon_32x32.png
sips -z 64 64 /tmp/np-icon-tmpdir.iconset/icon.png --out /tmp/np-icon-tmpdir.iconset/[email protected]
sips -z 64 64 /tmp/np-icon-tmpdir.iconset/icon.png --out /tmp/np-icon-tmpdir.iconset/icon_64x64.png
sips -z 128 128 /tmp/np-icon-tmpdir.iconset/icon.png --out /tmp/np-icon-tmpdir.iconset/[email protected]
sips -z 128 128 /tmp/np-icon-tmpdir.iconset/icon.png --out /tmp/np-icon-tmpdir.iconset/icon_128x128.png
sips -z 256 256 /tmp/np-icon-tmpdir.iconset/icon.png --out /tmp/np-icon-tmpdir.iconset/[email protected]
sips -z 256 256 /tmp/np-icon-tmpdir.iconset/icon.png --out /tmp/np-icon-tmpdir.iconset/icon_256x256.png
sips -z 512 512 /tmp/np-icon-tmpdir.iconset/icon.png --out /tmp/np-icon-tmpdir.iconset/[email protected]
sips -z 512 512 /tmp/np-icon-tmpdir.iconset/icon.png --out /tmp/np-icon-tmpdir.iconset/icon_512x512.png
sips -z 1024 1024 /tmp/np-icon-tmpdir.iconset/icon.png --out /tmp/np-icon-tmpdir.iconset/[email protected]
sips -z 1024 1024 /tmp/np-icon-tmpdir.iconset/icon.png --out /tmp/np-icon-tmpdir.iconset/icon_1024x1024.png
rm /tmp/np-icon-tmpdir.iconset/icon.png
iconutil -c icns /tmp/np-icon-tmpdir.iconset
mv /tmp/np-icon-tmpdir.icns assets/ne.icns
rm -rf /tmp/np-icon-tmpdir.iconset
Binary file added assets/ne.icns
Binary file not shown.
Binary file added assets/original/background.psd
Binary file not shown.
Binary file added assets/original/ne.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 85 additions & 0 deletions assets/original/ne.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions lib/nepali-romanized.bundle/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>com.thapaliya.ukelele.keyboardlayout.nepali-romanized</string>
<key>CFBundleName</key>
<string>nepali-romanized</string>
<key>CFBundleVersion</key>
<string>4.0</string>
<key>KLInfo_Nepali (Romanized) - Pro</key>
<dict>
<key>TICapsLockLanguageSwitchCapable</key>
<false/>
<key>TISInputSourceID</key>
<string>com.thapaliya.ukelele.keyboardlayout.nepali-romanized.nepali(romanized)-pro</string>
<key>TISIntendedLanguage</key>
<string>ne</string>
</dict>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE keyboard PUBLIC "" "file://localhost/System/Library/DTDs/KeyboardLayout.dtd">
<?xml version="1.1" encoding="UTF-8"?>
<!DOCTYPE keyboard SYSTEM "file://localhost/System/Library/DTDs/KeyboardLayout.dtd">
<!--Created by Ukelele version 2.2.6 on 2014-01-07 at 19:20 (GMT+1)-->
<!--Last edited by Ukelele version 2.2.7 on 2014-01-23 at 19:34 (GMT+1)-->
<!--Last edited by Jwalanta Shrestha on 2014-08-04-->
<!--Author: Suvash Thapaliya
Based on the Nepali Romanized Keyboard layout by MPP-->
<keyboard group="126" id="-11464" name="Nepali Romanized Pro" maxout="3">
<!--Author: Suvash Thapaliya-->
<!--Based on the Nepali Romanized Keyboard layout by MPP-->
<!--Last edited by Ukelele version 3.4.2.314 on 2020-07-18 at 01:28 (GMT+2)-->
<keyboard group="126" id="-6758" name="Nepali (Romanized) - Pro" maxout="3">
<layouts>
<layout first="0" last="0" modifiers="30" mapSet="a8"/>
<layout first="0" last="0" mapSet="a8" modifiers="30"/>
</layouts>
<modifierMap id="30" defaultIndex="6">
<keyMapSelect mapIndex="0">
Expand Down
Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions lib/nepali-romanized.bundle/Contents/version.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildVersion</key>
<string></string>
<key>ProjectName</key>
<string>nepali-romanized</string>
<key>SourceVersion</key>
<string></string>
</dict>
</plist>
Binary file removed packager/Nepali Romanized Pro.icns
Binary file not shown.

This file was deleted.

1 change: 0 additions & 1 deletion packager/Nepali-Romanized-Pro-Packager.pmdoc/01nepali.xml

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion packager/Nepali-Romanized-Pro-Packager.pmdoc/02nepali.xml

This file was deleted.

1 change: 0 additions & 1 deletion packager/Nepali-Romanized-Pro-Packager.pmdoc/index.xml

This file was deleted.

12 changes: 12 additions & 0 deletions pkgdeps/scripts/postinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

log_post() {
TIMESTAMP=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
echo "[$TIMESTAMP] - $1" >> /tmp/nepali-romanized-postinstall.log
}

log_post "Starting postinstall"

log_post "Finished postinstall"

exit 0
32 changes: 32 additions & 0 deletions pkgdeps/scripts/preinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

log_pre() {
TIMESTAMP=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
echo "[$TIMESTAMP] - $1" >> /tmp/nepali-romanized-preinstall.log
}

log_pre "Starting preinstall"

if [ -f "/Library/Keyboard Layouts/Nepali Romanized Pro.keylayout" ]
then
log_pre "Keyboard layout Nepali Romanized Pro.keylayout is already installed."
log_pre "Purging Nepali Romanized Pro.keylayout"

rm "/Library/Keyboard Layouts/Nepali Romanized Pro.icns" "/Library/Keyboard Layouts/Nepali Romanized Pro.keylayout"
else
log_pre "Nepali Romanized Pro.keylayout has not yet been installed."
fi

if [ -d "/Library/Keyboard Layouts/nepali-romanized.bundle/" ]
then
log_pre "Keyboard layout bundle nepali-romanized.bundle is already installed."
log_pre "Purging nepali-romanized.bundle."

rm -rf "/Library/Keyboard Layouts/nepali-romanized.bundle/"
else
log_pre "nepali-romanized.bundle has not yet been installed."
fi

log_pre "Finished preinstall"

exit 0
Binary file added productdeps/Resources/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions productdeps/distribution.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<installer-script minSpecVersion="1.000000">
<localization>
<strings language="en">
<![CDATA[
"NR_TITLE" = "Nepali Romanized Pro";
"NR_OLD_DETECT" = "An older version detected";
"NR_OLD_DETECT_MSG" = "An older version of the keyboard layout already exists. This installer will purge it and install new bundle.";
"NR_PREV_DETECT" = "Previous installation detected";
"NR_PREV_DETECT_MSG" = "A previous installation of the keyboard layout bundle already exists. This installer will overwrite it.";
]]>
</strings>
</localization>
<allowed-os-versions>
<os-version min="10.10"/>
</allowed-os-versions>
<title>NR_TITLE</title>
<background mime-type="image/png" file="background.png" alignment="bottomleft" scaling="none"/>
<background-darkAqua mime-type="image/png" file="background.png" alignment="bottomleft" scaling="none"/>
<options customize="never" allow-external-scripts="no" rootVolumeOnly="true"/>

<welcome language="en" mime-type="text/html"><![CDATA[<html><body><br />
<p style="margin: 0px; font: 14px 'Helvetica'">This installer will guide you through the process of installing the 'Nepali Romanized Pro' keyboard layout in your operating system.<br /><br />You will need to log out, then log back in to use the layouts.<br /><br />Version : __APP_VERSION__<br />Built on : __BUILD_TIMESTAMP__</p></body></html>]]></welcome>
<conclusion language="en" mime-type="text/html"><![CDATA[<html><body><br />
<p style="margin: 0px; font: 14px 'Helvetica'">'Nepali Romanized Pro' keyboard layout is now installed.<br /><br />Please log out first, then log back in again.<br />Afterwards, visit the Keyboard Layouts panel in your System Preferences to see the newly installed layout.</p></body></html>]]></conclusion>
<installation-check script="pre_install_check();"/>
<script>
<![CDATA[
function pre_install_check() {
if(system.files.fileExistsAtPath('/Library/Keyboard Layouts/Nepali Romanized Pro.keylayout')) {
my.result.title = system.localizedString('NR_OLD_DETECT');
my.result.message = system.localizedString('NR_OLD_DETECT_MSG');
my.result.type = 'Warning';
return false;
}
if(system.files.fileExistsAtPath('/Library/Keyboard Layouts/nepali-romanized.bundle')) {
my.result.title = system.localizedString('NR_PREV_DETECT');
my.result.message = system.localizedString('NR_PREV_DETECT_MSG');
my.result.type = 'Warning';
return false;
}
return true;
}
]]>
</script>

<choices-outline>
<line choice="install"/>
</choices-outline>
<choice id="install" title="Nepali Romanized Pro">
<pkg-ref id="__APP_PKG_ID__"/>
</choice>
<pkg-ref id="__APP_PKG_ID__" auth="Root">__APP_PKG_ID__.pkg</pkg-ref>
<!-- onConclusion="RequireLogout" -->
</installer-script>
4 changes: 0 additions & 4 deletions scripts/preinstall.sh

This file was deleted.

0 comments on commit d881642

Please sign in to comment.