From 8ee8b216db58a89240a279476070a185be03ff39 Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Fri, 26 Feb 2021 17:56:51 +0100
Subject: [PATCH] A working AppImage distribution

---
 .gitignore   |  1 +
 appimage.sh  | 36 ++++++++++++++++++++++++++++++++++++
 package.json |  9 ++-------
 3 files changed, 39 insertions(+), 7 deletions(-)
 create mode 100755 appimage.sh

diff --git a/.gitignore b/.gitignore
index 382f7c0..dbbe22c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ dist
 
 *.log
 *.tgz
+*.AppImage
diff --git a/appimage.sh b/appimage.sh
new file mode 100755
index 0000000..a29370b
--- /dev/null
+++ b/appimage.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+YARN=${YARN:-yarnpkg}
+
+[ ! -d dist ] && mkdir dist
+
+# DL the appimagetool
+URL_APPIMAGETOOL="https://github.com/probonopd/AppImageKit/releases/download/continuous/appimagetool-`arch`.AppImage"
+APPIMAGETOOL="dist/appimagetool-`arch`.AppImage"
+WGET=`which wget 2>/dev/null`
+[ $? -ne 0 ] && exit 1
+echo "wget: $WGET"
+[ -e "$APPIMAGETOOL" ] || { wget "$URL_APPIMAGETOOL" -O "$APPIMAGETOOL" || exit 1; }
+chmod +x "$APPIMAGETOOL"
+
+# Build initial AppImage
+rm -rf dist/squashfs-root dist/Amadeus dist/[aA]madeus-*.AppImage dist/*.fs
+
+$YARN dist
+
+[ ! -f dist/lektord-`arch`.AppImage ] && { cp "$(which lektord-`arch`.AppImage)" dist/ || exit 1; }
+
+# Extract AppImages
+(cd dist && ./lektord-`arch`.AppImage --appimage-extract && mv squashfs-root lektord.fs)
+(cd dist && ./amadeus-?.?.?.AppImage --appimage-extract && mv squashfs-root amadeus.fs)
+
+cp -rf dist/amadeus.fs/* dist/lektord.fs/
+rm -rf dist/amadeus.fs
+mv dist/lektord.fs dist/Amadeus
+
+# Clean and setup
+(cd dist/Amadeus/usr/ && ln -s bin sbin)
+(cd dist/Amadeus && rm lektor* AppRun.wrapped)
+
+# Package
+$APPIMAGETOOL dist/Amadeus
diff --git a/package.json b/package.json
index 48e99f8..f6bdfef 100644
--- a/package.json
+++ b/package.json
@@ -13,13 +13,8 @@
     "license": "ISC",
     "scripts": {
         "start": "electron .",
-        "pack": "electron-builder",
-
-        "linux-dist": "yarn pack && yarn linux-extract-clean && yarn linux-extract-lektor && yarn linux-extract-amadeus && yarn linux-extract-links",
-        "linux-extract-links": "cd dist/squashfs-root/usr && ln -s bin sbin; cd ../../..",
-        "linux-extract-clean": "cd dist && rm -rf squashfs-root; cd ..",
-        "linux-extract-lektor": "cd dist && ./lektord-`arch`.AppImage --appimage-extract; cd ..",
-        "linux-extract-amadeus": "cd dist && ./amadeus*.AppImage --appimage-extract; cd .."
+        "dist": "electron-builder",
+        "linux-dist": "./appimage.sh"
     },
     "dependencies": {
         "ejs": "^3.1.5",
-- 
GitLab