From 16dd01bf754ddc66cce8f57a5dc24d9aefeb187d Mon Sep 17 00:00:00 2001
From: Dmitry Puzyrkov <dmitry.puzyrkov@demlabs.net>
Date: Wed, 26 Apr 2023 08:29:31 +0000
Subject: [PATCH] [+] osx packaging files added.

---
 .gitlab-ci.yml                            |  7 +++-
 os/macos/PKGINSTALL/CellframeNode.plist   | 18 +++++++++
 os/macos/PKGINSTALL/PackageInfo           | 22 ++++++++++
 os/macos/PKGINSTALL/postinstall           | 49 +++++++++++++++++++++++
 os/macos/PKGINSTALL/preinstall            |  8 ++++
 os/macos/com.demlabs.cellframe-node.plist | 14 +++++++
 prod_build                                |  2 +-
 scripts.darwin/create_configs.sh          |  3 +-
 scripts/create_configs_from_tpl.sh        |  4 ++
 version.mk                                |  2 +-
 10 files changed, 125 insertions(+), 4 deletions(-)
 create mode 100644 os/macos/PKGINSTALL/CellframeNode.plist
 create mode 100644 os/macos/PKGINSTALL/PackageInfo
 create mode 100755 os/macos/PKGINSTALL/postinstall
 create mode 100755 os/macos/PKGINSTALL/preinstall
 create mode 100755 os/macos/com.demlabs.cellframe-node.plist

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 4aaef4d67..c09c90321 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -38,6 +38,10 @@ macos-amd64:
     before_script: /opt/buildtools/prepare_environment.sh amd64-osx
     script:
       - ./prod_build/build.sh --target osx release
+      - ./prod_build/pack.sh --target osx release --sign /opt/buildtools/sign/macos/demlabs.sh
+    artifacts:
+      paths:
+        - build_*/*.pkg
 
 linux-amd64-debian-buster-dbg:
     extends: .build
@@ -89,11 +93,12 @@ deploy:
     - linux-armhf-debian-bullseye 
     - linux-arm64-debian-bullseye 
     - linux-amd64-debian-buster-rwd
+    - macos-amd64
    
   script: 
     - anybadge -l "node version" -v "$(source version.mk; echo "$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH")" -f node-version-badge.svg -c blue
     - /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ ./node-version-badge.svg || true
     - /opt/buildtools/deploy_files.sh pub_cellframe linux/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*.deb 
-    
+    - /opt/buildtools/deploy_files.sh pub_cellframe macos/cellframe-node/$CI_COMMIT_REF_NAME/ build_*/*.pkg 
 
 
diff --git a/os/macos/PKGINSTALL/CellframeNode.plist b/os/macos/PKGINSTALL/CellframeNode.plist
new file mode 100644
index 000000000..a7fe48140
--- /dev/null
+++ b/os/macos/PKGINSTALL/CellframeNode.plist
@@ -0,0 +1,18 @@
+<?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">
+<array>
+	<dict>
+		<key>BundleHasStrictIdentifier</key>
+		<true/>
+		<key>BundleIsRelocatable</key>
+		<false/>
+		<key>BundleIsVersionChecked</key>
+		<true/>
+		<key>BundleOverwriteAction</key>
+		<string>upgrade</string>
+		<key>RootRelativeBundlePath</key>
+		<string>CellframeNode.app</string>
+	</dict>
+</array>
+</plist>
diff --git a/os/macos/PKGINSTALL/PackageInfo b/os/macos/PKGINSTALL/PackageInfo
new file mode 100644
index 000000000..c1b21e65f
--- /dev/null
+++ b/os/macos/PKGINSTALL/PackageInfo
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<pkg-info overwrite-permissions="true" relocatable="false" identifier="com.demlabs.CellframeNode" postinstall-action="none" version="0" format-version="2" generator-version="InstallCmds-763 (20G80)" install-location="/Applications/" auth="root">
+    <payload numberOfFiles="" installKBytes=""/>
+    <domains enable_localSystem="false" enable_anywhere="true" enable_currentUserHome="true"/>
+    <bundle id="com.demlabs.CellframeNode" path="./CellframeNode.app"/>
+    <bundle-version>
+        <bundle id="com.demlabs.CellframeNode"/>
+    </bundle-version>
+    <upgrade-bundle>
+        <bundle id="com.demlabs.CellframeNode"/>
+    </upgrade-bundle>
+    <update-bundle/>
+    <atomic-update-bundle/>
+    <strict-identifier>
+        <bundle id="com.demlabs.CellframeNode"/>
+    </strict-identifier>
+    <relocate/>
+    <scripts>
+        <preinstall file="./preinstall"/>
+        <postinstall file="./postinstall"/>
+    </scripts>
+</pkg-info>
diff --git a/os/macos/PKGINSTALL/postinstall b/os/macos/PKGINSTALL/postinstall
new file mode 100755
index 000000000..0b70d3e46
--- /dev/null
+++ b/os/macos/PKGINSTALL/postinstall
@@ -0,0 +1,49 @@
+#!/bin/bash
+
+APP_NAME=CellframeNode
+DAP_PREFIX=/Users/$USER/Applications/Cellframe.app/Contents/Resources
+NODE=com.demlabs.cellframe-node
+
+set -x
+sudo xattr -rd com.apple.quarantine /Applications/"$APP_NAME".app
+sudo killall -HUP mDNSResponder
+
+EXEC_PREFIX=/Applications/$APP_NAME.app/Contents/Resources
+
+mkdir -p $DAP_PREFIX
+sudo mv -f /Applications/$APP_NAME.app/Contents/Resources/etc $DAP_PREFIX
+sudo mv -f /Applications/$APP_NAME.app/Contents/Resources/share $DAP_PREFIX
+
+wd=$(pwd)
+cd $EXEC_PREFIX/../MacOS
+
+for filename in $(ls . | grep -v '.'); do
+    if [ -L $filename ] && [ ! -e $filename ]; then
+        strip -u -r $filename
+    fi
+done
+
+sudo chmod +x $EXEC_PREFIX/create_configs.sh
+sudo chmod +x $EXEC_PREFIX/create_configs_from_tpl.sh
+
+$EXEC_PREFIX/create_configs.sh /Applications/${APP_NAME}.app/
+
+mkdir -p /Users/$USER/Library/LaunchAgents
+
+launchctl stop $NODE
+sudo -u $USER launchctl unload -w /Users/$USER/Library/LaunchAgents/$NODE.plist
+sudo chown $USER /Applications/"$APP_NAME".app/Contents/Resources/$NODE.plist
+sudo chmod 644 /Applications/"$APP_NAME".app/Contents/Resources/$NODE.plist
+
+sudo ln -sf /Applications/"$APP_NAME".app/Contents/Resources/$NODE.plist /Users/$USER/Library/LaunchAgents/$NODE.plist
+sudo -u $USER launchctl load -w /Users/$USER/Library/LaunchAgents/$NODE.plist
+
+rm -r /Users/$USER/Applications/"$APP_NAME".app/Contents/Resources/var/lib/global_db/gdb-cdb/
+
+sudo -u $USER launchctl start $NODE
+
+sudo rm $EXEC_PREFIX/*.sh
+
+echo "node agent: $(launchctl list | grep cell)" > /tmp/cellframe-dashboard_install_logs.txt
+
+cd $wd
\ No newline at end of file
diff --git a/os/macos/PKGINSTALL/preinstall b/os/macos/PKGINSTALL/preinstall
new file mode 100755
index 000000000..adbfef0c9
--- /dev/null
+++ b/os/macos/PKGINSTALL/preinstall
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+#NODE=com.demlabs.cellframe-node
+#launchctl stop $NODE
+
+#RET=0
+
+#[ -e /Library/LaunchDaemons/com.demlabs.cellframe-node.plist ] && launchctl unload -w /Users/$USER/Library/LaunchAgents/com.demlabs.cellframe-node.plist
diff --git a/os/macos/com.demlabs.cellframe-node.plist b/os/macos/com.demlabs.cellframe-node.plist
new file mode 100755
index 000000000..4ed5a77b1
--- /dev/null
+++ b/os/macos/com.demlabs.cellframe-node.plist
@@ -0,0 +1,14 @@
+<?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>Label</key>
+	<string>com.demlabs.cellframe-node</string>
+	<key>Program</key>
+	<string>/Applications/CellframeNode.app/Contents/MacOS/cellframe-node</string>
+	<key>RunAtLoad</key>
+	<true/>
+	<key>KeepAlive</key>
+	<true/>
+</dict>
+</plist>
diff --git a/prod_build b/prod_build
index c27f5075f..b399fc74c 160000
--- a/prod_build
+++ b/prod_build
@@ -1 +1 @@
-Subproject commit c27f5075f58e991958ab09195bf5f285a586a1ad
+Subproject commit b399fc74c0700620bad1bb438d8e393c6fff3c33
diff --git a/scripts.darwin/create_configs.sh b/scripts.darwin/create_configs.sh
index 1527658bb..185debc8a 100755
--- a/scripts.darwin/create_configs.sh
+++ b/scripts.darwin/create_configs.sh
@@ -14,7 +14,8 @@ export DAP_AUTO_ONLINE=true
 export DAP_SERVER_ENABLED=false
 export DAP_SERVER_ADDRESS=0.0.0.0
 export DAP_SERVER_PORT=8089
-
+export NOTIFY_SRV_ADDR=127.0.0.1
+export NOTIFY_SRV_PORT=8080
 
 # Raiden testnet
 export DAP_RAIDEN_ENABLED=true
diff --git a/scripts/create_configs_from_tpl.sh b/scripts/create_configs_from_tpl.sh
index 0de71742d..66e637b45 100755
--- a/scripts/create_configs_from_tpl.sh
+++ b/scripts/create_configs_from_tpl.sh
@@ -20,6 +20,8 @@ fi
 [ "$DAP_SERVER_ENABLED" ] || DAP_SERVER_ENABLED="false"
 [ "$DAP_SERVER_PORT" ] || DAP_SERVER_PORT="8079"
 [ "$DAP_SERVER_ADDR" ] || DAP_SERVER_ADDR="0.0.0.0"
+[ "$NOTIFY_SRV_ADDR" ] || NOTIFY_SRV_ADDR="127.0.0.1"
+[ "$NOTIFY_SRV_PORT" ] || NOTIFY_SRV_PORT="8080"
 
 DAP_CFG_TPL="$DAP_PREFIX/share/configs/$DAP_APP_NAME.cfg.tpl"
 
@@ -42,6 +44,8 @@ sed -i .old "s/{AUTO_ONLINE}/$DAP_AUTO_ONLINE/g" $DAP_CFG  || true
 sed -i .old "s/{SERVER_ENABLED}/$DAP_SERVER_ENABLED/g" $DAP_CFG  || true
 sed -i .old "s/{SERVER_PORT}/$DAP_SERVER_PORT/g" $DAP_CFG  || true
 sed -i .old "s/{SERVER_ADDR}/$DAP_SERVER_ADDR/g" $DAP_CFG  || true
+sed -i .old "s/{NOTIFY_SRV_ADDR}/$NOTIFY_SRV_ADDR/g" $DAP_CFG  || true
+sed -i .old "s/{NOTIFY_SRV_PORT}/$NOTIFY_SRV_PORT/g" $DAP_CFG  || true
 sed -i .old "s/{PREFIX}/$DAP_PREFIX_TPL/g" $DAP_CFG  || true
 rm $DAP_CFG.old
 
diff --git a/version.mk b/version.mk
index 198677fa7..0e3715a6d 100644
--- a/version.mk
+++ b/version.mk
@@ -1,3 +1,3 @@
 VERSION_MAJOR=5
 VERSION_MINOR=2
-VERSION_PATCH=100
+VERSION_PATCH=101
-- 
GitLab