From 83910ddae3a76f3f780326bd99c48782bfcca3ee Mon Sep 17 00:00:00 2001
From: Willi Mutschler <willi@mutschler.eu>
Date: Tue, 26 Sep 2023 12:23:31 +0200
Subject: [PATCH] macOS installer: don't require admin + ability to change
 install path

id="org.dynare.VERSION_NO_SPACE" fixes #1790, i.e old Dynare versions will not get uninstalled.
---
 macOS/build.sh                  | 9 +++++----
 macOS/distribution_template.xml | 7 ++++---
 macOS/welcome_template.html     | 1 +
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/macOS/build.sh b/macOS/build.sh
index 90c960cb6a..bba2664fc0 100755
--- a/macOS/build.sh
+++ b/macOS/build.sh
@@ -130,10 +130,11 @@ cp -p  "$ROOTDIR"/macOS/deps/lib64/x13as/x13as                       "$PKGFILES"
 cd "$ROOTDIR"/macOS/pkg
 
 # Dynare option
-pkgbuild --root "$PKGFILES" --identifier org.dynare --version "$VERSION" --install-location /Applications/Dynare/"$LOCATION" "$NAME".pkg
+pkgbuild --root "$PKGFILES" --identifier org.dynare."$VERSION" --version "$VERSION" --install-location /Applications/Dynare/"$LOCATION" "$NAME".pkg
 
 # Create distribution.xml by replacing variables in distribution_template.xml
 sed -e "s/VERSION_NO_SPACE/$VERSION/g" \
+    -e "s/LOCATION/$LOCATION/g" \
     "$ROOTDIR"/macOS/distribution_template.xml > distribution.xml
 
 # Create welcome.html by replacing variables in welcome_template.html
@@ -147,13 +148,13 @@ sed -e "s/GCC_VERSION/$GCC_VERSION/g" \
     "$ROOTDIR"/macOS/conclusion_template.html > "$ROOTDIR"/macOS/conclusion.html
 
 # Create installer
-productbuild --distribution distribution.xml --resources "$ROOTDIR"/macOS --package-path ./"$NAME".pkg "$NAME"-new.pkg
+productbuild --distribution distribution.xml --resources "$ROOTDIR"/macOS --package-path ./"$NAME".pkg "$NAME"-productbuild.pkg
 
-# cleanup
+# Cleanup
 rm -f ./distribution.xml
 rm -rf "$PKGFILES"
 rm -f "$ROOTDIR"/macOS/welcome.html
 rm -f "$ROOTDIR"/macOS/conclusion.html
 
 # Final pkg
-mv "$NAME"-new.pkg "$NAME".pkg
+mv "$NAME"-productbuild.pkg "$NAME".pkg
diff --git a/macOS/distribution_template.xml b/macOS/distribution_template.xml
index 7c78874435..41e46aaa4e 100644
--- a/macOS/distribution_template.xml
+++ b/macOS/distribution_template.xml
@@ -6,13 +6,14 @@
   <welcome file="welcome.html" mime-type="text/html" />
   <conclusion file="conclusion.html" mime-type="text/html" />
   <license file="gpl-3.0-standalone.html" mime-type="text/html" />
+  <domains enable_anywhere="true" enable_currentUserHome="true"/>
   <pkg-ref id="default" />
   <options customize="allow" require-scripts="false" hostArchitectures="x86_64" />
   <choices-outline>
     <line choice="default" />
   </choices-outline>
-  <choice id="default" title="Dynare" description="Dynare Required Files" start_enabled="false" enabled="false">
-    <pkg-ref id="org.dynare" />
+  <choice id="default" title="Dynare" description="Dynare Required Files" start_enabled="false" enabled="false" customLocation="/Applications/Dynare/dynare-LOCATION">
+    <pkg-ref id="org.dynare.VERSION_NO_SPACE" />
   </choice>  
-  <pkg-ref id="org.dynare" version="VERSION_NO_SPACE">dynare-VERSION_NO_SPACE.pkg</pkg-ref>
+  <pkg-ref id="org.dynare.VERSION_NO_SPACE" version="VERSION_NO_SPACE">dynare-VERSION_NO_SPACE.pkg</pkg-ref>
 </installer-gui-script>
\ No newline at end of file
diff --git a/macOS/welcome_template.html b/macOS/welcome_template.html
index 520fe788ad..113c2fce46 100644
--- a/macOS/welcome_template.html
+++ b/macOS/welcome_template.html
@@ -21,6 +21,7 @@
     </header>
 
     <main>
+      <p>If you need to change the path of the installation, click <strong>Customize</strong> after agreeing to the license and on the folder below <strong>Location</strong>.</p>
       <p>Please read the <strong>Postinstallation Recommendations</strong> at the end of the installation process on how to (optionally) install Xcode Command Line Tools and gcc-GCC_VERSION via Homebrew.</p>
     </main>
   </body>
-- 
GitLab