From b615e4f848e30114474093e3061b0cf4dfa998e7 Mon Sep 17 00:00:00 2001
From: Benoit Lavenier <benoit.lavenier@e-is.pro>
Date: Thu, 4 Jan 2024 17:56:51 +0100
Subject: [PATCH] enh(build) Fix AppImage build

---
 .gitignore                             |  4 +--
 README.md                              |  2 +-
 arch/linux/appimage.yml                | 31 ++++++++++++++++
 arch/linux/appimage/appimage.yml       | 24 -------------
 arch/linux/bootstrap.sh                |  2 +-
 arch/linux/build-deb.sh                | 14 +++++---
 arch/linux/{appimage => }/pkg2appimage |  0
 arch/windows/build.bat                 | 49 +++++++++++++++++---------
 release.sh                             |  2 +-
 scripts/build.sh                       |  2 +-
 10 files changed, 78 insertions(+), 52 deletions(-)
 create mode 100644 arch/linux/appimage.yml
 delete mode 100644 arch/linux/appimage/appimage.yml
 rename arch/linux/{appimage => }/pkg2appimage (100%)

diff --git a/.gitignore b/.gitignore
index 35a7b46..b7ce8f1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,18 +13,18 @@ arch/linux/.vagrant
 arch/linux/cesium-*
 arch/linux/splash.html
 arch/linux/package.json
+arch/linux/package-lock.json
 arch/linux/yarn.lock
 arch/linux/LICENSE.txt
-arch/linux/ubuntu*
 arch/linux/nw*
 
 arch/windows/.vagrant
 arch/windows/cesium-*
 arch/windows/splash.html
 arch/windows/package.json
+arch/windows/package-lock.json
 arch/windows/yarn.lock
 arch/windows/LICENSE.txt
-arch/windows/LICENSE.txt
 arch/windows/*.box
 arch/windows/*.exe
 arch/windows/.directory
diff --git a/README.md b/README.md
index 8586778..c672da6 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ This script will run Cesium Desktop, taking care of installing Cesium + Nw.js if
 
 The release script use some Vagrant, and a VM running into VirtualBox.
 
-- Install VirtualBox version 6 (not tested under version 7)
+- Install VirtualBox version 7
 - Install the VirtualBox Extension Pack (need by OSx build, for USB support).
 - Install vagrant : `sudo apt install vagrant`
 
diff --git a/arch/linux/appimage.yml b/arch/linux/appimage.yml
new file mode 100644
index 0000000..2ecd995
--- /dev/null
+++ b/arch/linux/appimage.yml
@@ -0,0 +1,31 @@
+app: cesium-desktop
+
+ingredients:
+  script:
+    - CESIUM_ROOT=cesium-desktop.AppDir/opt/cesium
+    - rm -rf $CESIUM_ROOT
+    - mkdir -p $CESIUM_ROOT
+    - TGZ_FILE=$(ls ../cesium-desktop-v*-linux-x64.tar.gz | sort -V | tail -n 1)
+    - tar xzf $TGZ_FILE -C $CESIUM_ROOT
+script:
+  - cat > cesium.desktop <<EOF
+  - [Desktop Entry]
+  - Type=Application
+  - Name=Cesium Äž1
+  - Exec=cesium
+  - StartupNotify=true
+  - Icon=cesium
+  - Categories=Utility;
+  - EOF
+  - ln -s opt/cesium/nw/nw usr/bin/cesium
+  - mkdir -p usr/share/icons/hicolor/256x256/apps
+  - cp opt/cesium/nw/cesium/img/logo_32px.png usr/share/icons/hicolor/32x32/apps/cesium.png
+  - cp opt/cesium/nw/cesium/img/logo_128px.png usr/share/icons/hicolor/128x128/apps/cesium.png
+  - cp opt/cesium/nw/cesium/img/logo_256px.png usr/share/icons/hicolor/256x256/apps/cesium.png
+  - cp opt/cesium/nw/cesium/img/logo_512px.png usr/share/icons/hicolor/512x512/apps/cesium.png
+  - cp usr/share/icons/hicolor/256x256/apps/cesium.png .
+  - chmod +r -R opt/cesium
+  - chmod +x opt/cesium/nw/nw opt/cesium/nw/lib opt/cesium/nw/locales
+  - sed -i 's/Cesium/Cesium Äž1/g' opt/cesium/nw/splash.html
+  - sed -i 's/Cesium/Cesium Äž1/g' opt/cesium/nw/cesium/index.html
+  - sed -i 's/"Cesium"/"Cesium Äž1"/g' opt/cesium/nw/cesium-desktop.js
diff --git a/arch/linux/appimage/appimage.yml b/arch/linux/appimage/appimage.yml
deleted file mode 100644
index 6444252..0000000
--- a/arch/linux/appimage/appimage.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-app: cesium-desktop
-
-ingredients:
-  script:
-    - rm -rf cesium-desktop.AppDir/opt/cesium
-    - mkdir -p cesium-desktop.AppDir/opt/cesium
-    - TGZ_FILE=$(ls ../cesium-desktop-v*-linux-x64.tar.gz | sort -V | tail -n 1)
-    - tar xzf $TGZ_FILE -C cesium-desktop.AppDir/opt/cesium
-script:
-  - cat > cesium.desktop <<EOF
-  - [Desktop Entry]
-  - Type=Application
-  - Name=Cesium Äž1
-  - Exec=cesium
-  - StartupNotify=true
-  - Icon=cesium
-  - Categories=Utility;
-  - EOF
-  - ln -s opt/cesium/nw/nw usr/bin/cesium
-  - mkdir -p usr/share/icons/hicolor/256x256/apps
-  - cp opt/cesium/nw/cesium/img/logo_256px.png usr/share/icons/hicolor/256x256/apps/cesium.png
-  - cp usr/share/icons/hicolor/256x256/apps/cesium.png ./app.png
-  - chmod ugo+r -R opt/cesium
-  - chmod ugo+x -R opt/cesium/nw/nw opt/cesium/nw/lib opt/cesium/nw/locales
diff --git a/arch/linux/bootstrap.sh b/arch/linux/bootstrap.sh
index 3700399..0752ebd 100755
--- a/arch/linux/bootstrap.sh
+++ b/arch/linux/bootstrap.sh
@@ -5,7 +5,7 @@ apt update
 # Deps need for tar.gz and .deb build
 apt install --yes git curl python3-minimal zip fakeroot
 # Deps need for AppImage build
-apt install --yes imagemagick desktop-file-utils binutils
+apt install --yes imagemagick desktop-file-utils binutils fuse3
 
 # User installation
 sudo su vagrant -c "bash /vagrant/user-bootstrap.sh"
diff --git a/arch/linux/build-deb.sh b/arch/linux/build-deb.sh
index 19f639f..0c219f1 100755
--- a/arch/linux/build-deb.sh
+++ b/arch/linux/build-deb.sh
@@ -154,12 +154,16 @@ rm -rf "${RELEASES}/${PROJECT_NAME}-x64" || exit 1
 # Build Desktop version .AppImage
 # -------------------------------------------------
 
-cp -f /vagrant/appimage/* "${RELEASES}/" || exit 1
-cp -f /vagrant/${OUTPUT_BASENAME}.tar.gz "${RELEASES}/" || exit 1
+cp -f /vagrant/appimage.yml "${RELEASES}/" || exit 1
+cp -f /vagrant/pkg2appimage "${RELEASES}/" || exit 1
+ln -s /vagrant/${OUTPUT_BASENAME}.tar.gz "${RELEASES}/${OUTPUT_BASENAME}.tar.gz" || exit 1
 cd "${RELEASES}"
-bash -ex ./pkg2appimage appimage.yml || exit 1
-
-OUTPUT_APPIMAGE=$(ls "./out/*.AppImage" | sort -V | tail -n 1)
+./pkg2appimage appimage.yml || exit 1
+OUTPUT_APPIMAGE=$(ls ./out/*.AppImage | sort -V | tail -n 1)
+if [ ! -f "${OUTPUT_APPIMAGE}" ]; then
+  echo "ERROR: No AppImage file found in directory ${RELEASES}/out - Please check previous error"
+  exit 1
+fi
 mv "${OUTPUT_APPIMAGE}" "/vagrant/${OUTPUT_BASENAME}.AppImage" || exit 1
 
 # -------------------------------------------------
diff --git a/arch/linux/appimage/pkg2appimage b/arch/linux/pkg2appimage
similarity index 100%
rename from arch/linux/appimage/pkg2appimage
rename to arch/linux/pkg2appimage
diff --git a/arch/windows/build.bat b/arch/windows/build.bat
index 7277a08..47f7406 100644
--- a/arch/windows/build.bat
+++ b/arch/windows/build.bat
@@ -1,3 +1,4 @@
+echo off
 
 set NW_VERSION=0.42.2
 set NW_RELEASE=v%NW_VERSION%
@@ -11,17 +12,26 @@ REM NPM
 set PATH="C:\Users\vagrant\AppData\Roaming\npm";%PATH%
 REM InnoSetup
 set PATH="C:\Program Files (x86)\Inno Setup 5";%PATH%
+set SOURCE=C:\vagrant
+if not exist "%SOURCE%" (
+  set SOURCE=\\VBOXSVR\vagrant
+)
+if not exist "%SOURCE%" (
+  echo "vagrant folder not mounted !"
+  pause
+  exit 1
+)
 
 cd C:\Users\vagrant
 REM echo "Deleting old source..."
 del /s /q cesium-v*-web.zip
 rd /s /q cesium
 rd /s /q cesium_release
-echo "Cloning Cesium (from git.duniter.org)..."
 echo "Cloning Cesium (from github.com)..."
 git clone https://github.com/duniter/cesium.git
 if not exist C:\Users\vagrant\cesium (
   echo "ERROR: Cannot clone Cesium source!"
+  pause
   exit 1
 )
 cd cesium
@@ -30,35 +40,39 @@ for /f "delims=" %%a in ('git rev-list --tags --max-count=1') do @set CESIUM_REV
 for /f "delims=" %%a in ('git describe --tags %CESIUM_REV%') do @set CESIUM_TAG=%%a
 set CESIUM=cesium-%CESIUM_TAG%-web
 set CESIUM_ZIP=%CESIUM%.zip
-echo %CESIUM_TAG%
-echo %CESIUM%
-echo %CESIUM_ZIP%
+echo "Version: %CESIUM_TAG%"
+echo "Basename: %CESIUM%"
+echo "Filename: %CESIUM_ZIP%"
 
 cd ..
 
-if not exist C:\vagrant\%NW_GZ% (
+if not exist %SOURCE%\%NW_GZ% (
   echo "Downloading %NW%.zip..."
-  REM powershell -Command "Invoke-WebRequest -Uri https://dl.nwjs.io/v%NW_VERSION%/%NW%.zip -OutFile C:\vagrant\%NW_GZ%"
-  powershell -Command "(New-Object System.Net.WebClient).DownloadFile(\"https://dl.nwjs.io/v%NW_VERSION%/%NW%.zip\", \"C:\vagrant\%NW_GZ%\")"
+  REM powershell -Command "Invoke-WebRequest -Uri https://dl.nwjs.io/v%NW_VERSION%/%NW%.zip -OutFile %SOURCE%\%NW_GZ%"
+  powershell -Command "(New-Object System.Net.WebClient).DownloadFile(\"https://dl.nwjs.io/v%NW_VERSION%/%NW%.zip\", \"%SOURCE%\%NW_GZ%\")"
 )
 
-if not exist C:\vagrant\%CESIUM_ZIP% (
+if not exist %SOURCE%\%CESIUM_ZIP% (
   echo "Downloading %CESIUM_ZIP%..."
-  powershell -Command "(New-Object System.Net.WebClient).DownloadFile(\"https://github.com/duniter/cesium/releases/download/%CESIUM_TAG%/%CESIUM_ZIP%\", \"C:\vagrant\%CESIUM_ZIP%\")"
+  powershell -Command "(New-Object System.Net.WebClient).DownloadFile(\"https://github.com/duniter/cesium/releases/download/%CESIUM_TAG%/%CESIUM_ZIP%\", \"%SOURCE%\%CESIUM_ZIP%\")"
 )
 
-call 7z x C:\vagrant\%NW_GZ%
+call 7z x %SOURCE%\%NW_GZ%
 move %NW% cesium_release
+if not exist cesium_release (
+  echo "ERROR Missing cesium_release folder !"
+  exit 1
+)
 cd cesium_release
 mkdir cesium
 cd cesium
-call 7z x C:\vagrant\%CESIUM_ZIP%
+call 7z x %SOURCE%\%CESIUM_ZIP%
 
 cd ..
-xcopy C:\vagrant\LICENSE.txt .\ /s /e
-xcopy C:\vagrant\package.json .\ /s /e
-xcopy C:\vagrant\cesium-desktop.js .\ /s /e
-xcopy C:\vagrant\splash.html .\ /s /e
+xcopy %SOURCE%\LICENSE.txt .\ /s /e
+xcopy %SOURCE%\package.json .\ /s /e
+xcopy %SOURCE%\cesium-desktop.js .\ /s /e
+xcopy %SOURCE%\splash.html .\ /s /e
 call npm install
 
 cd C:\Users\vagrant\cesium_release\cesium
@@ -70,8 +84,9 @@ rmdir /s /q "maps"
 rmdir /s /q ".git"
 cd ..
 
-iscc C:\vagrant\cesium.iss /DROOT_PATH=%cd%
-move %cd%\Cesium.exe C:\vagrant\cesium-desktop-%CESIUM_TAG%-windows-x64.exe
+iscc %SOURCE%\cesium.iss /DROOT_PATH=%cd%
+move %cd%\Cesium.exe %SOURCE%\cesium-desktop-%CESIUM_TAG%-windows-x64.exe
 echo "Build done: binary available at cesium-desktop-%CESIUM_TAG%-windows-x64.exe"
 
+pause
 exit 0
diff --git a/release.sh b/release.sh
index 3d00c3a..90e6100 100755
--- a/release.sh
+++ b/release.sh
@@ -100,7 +100,7 @@ for ASSET_BASENAME in $EXPECTED_ASSETS; do
   if [[ -z `echo $ASSETS | grep -F "$ASSET_BASENAME"` ]]; then
 
     # Debian
-    if [[ $ASSET_BASENAME == *"linux-x64.deb" ]] || [[ $ASSET_BASENAME == *"linux-x64.tar.gz" ]] || [[ $ASSET_BASENAME == *"linux-x64.AppImage" ]]; then
+    if [[ $ASSET_BASENAME == *"linux-x64."* ]]; then
       if [[ $ARCH == "x86_64" ]]; then
 
         ASSET_PATH="$PWD/arch/linux/$ASSET_BASENAME"
diff --git a/scripts/build.sh b/scripts/build.sh
index 50d3b2f..287a3ff 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -7,7 +7,7 @@ make)
   case "$2" in
   linux)
     cd arch/linux
-    if [[ ! -f "cesium-desktop-v$TAG-linux-x64.deb" ]]; then
+    if [[ ! -f "cesium-desktop-v$TAG-linux-x64.AppImage" ]]; then
       [[ $? -eq 0 ]] && echo ">> Copying Cesium Desktop sources..."
       [[ $? -eq 0 ]] && cp -f ../../src/* ./
       [[ $? -eq 0 ]] && cp -f ../../LICENSE ./LICENSE.txt
-- 
GitLab