From 13036cb2d428ea23f5ae9e1b479f12c23a9a65a8 Mon Sep 17 00:00:00 2001 From: Amr AlSamahy Date: Mon, 16 Sep 2024 06:07:11 +0300 Subject: [PATCH 1/2] feat: script to create appbundles on macOS instead of running from terminal. Signed-off-by: Amr AlSamahy --- build_all.sh | 17 ++++--- create_macos_appbundles.sh | 95 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 7 deletions(-) create mode 100755 create_macos_appbundles.sh diff --git a/build_all.sh b/build_all.sh index 3ffa8e2..499a4da 100755 --- a/build_all.sh +++ b/build_all.sh @@ -1,24 +1,27 @@ #!/bin/bash -[[ "$OSTYPE" == "darwin"* ]] && export C_INCLUDE_PATH=/usr/local/opt/libusb/include -if [ "$EUID" -ne 0 ] +if [[ "$EUID" -ne 0 ]] && [[ "$OSTYPE" != "darwin"* ]] then echo "Please run as root! (sudo ./build_all.sh)" exit fi +[[ "$OSTYPE" == "darwin"* ]] && export C_INCLUDE_PATH=/usr/local/opt/libusb/include +( cd IMSProg_programmer rm -rf build/ mkdir build/ cmake -S . -B build/ -cmake --build build/ --parallel +cmake --build build/ --parallel cmake --install build/ rm -rf build/ -cd .. #IMSProg +) +( cd IMSProg_editor rm -rf build/ mkdir build/ cmake -S . -B build/ -cmake --build build/ --parallel +cmake --build build/ --parallel cmake --install build/ rm -rf build/ -# Reloading the USB rules -[[ "$OSTYPE" != "darwin"* ]] && udevadm control --reload-rules +) +# Reloading the USB rules or creating the app bundles for macOS +[[ "$OSTYPE" != "darwin"* ]] && udevadm control --reload-rules || ./create_macos_appbundles.sh diff --git a/create_macos_appbundles.sh b/create_macos_appbundles.sh new file mode 100755 index 0000000..b970f88 --- /dev/null +++ b/create_macos_appbundles.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env bash + +CONTENTSDIR1='IMSProg.app/Contents' +CONTENTSDIR2='IMSProg Editor.app/Contents' +CONTENTSDIR3='IMSProg Database Update.app/Contents' + +create_directories() { + local CONTENTSDIR=$1 + mkdir -p "$CONTENTSDIR/MacOS" + mkdir -p "$CONTENTSDIR/Resources" +} + +generate_iconset() { + local INPUT_IMG=$1 + local OUTPUT_ICONS=$2 + + mkdir icon.iconset + sips -z 16 16 -s format png "$INPUT_IMG" --out icon.iconset/icon_16x16.png + sips -z 32 32 -s format png "$INPUT_IMG" --out icon.iconset/icon_16x16@2x.png + sips -z 32 32 -s format png "$INPUT_IMG" --out icon.iconset/icon_32x32.png + sips -z 64 64 -s format png "$INPUT_IMG" --out icon.iconset/icon_32x32@2x.png + sips -z 128 128 -s format png "$INPUT_IMG" --out icon.iconset/icon_128x128.png + sips -z 256 256 -s format png "$INPUT_IMG" --out icon.iconset/icon_128x128@2x.png + sips -z 256 256 -s format png "$INPUT_IMG" --out icon.iconset/icon_256x256.png + sips -z 512 512 -s format png "$INPUT_IMG" --out icon.iconset/icon_256x256@2x.png + + iconutil -c icns icon.iconset -o "$OUTPUT_ICONS" + rm -rf icon.iconset +} + +# Update Info.plist +update_plist() { + local CONTENTSDIR=$1 + local ICON_NAME=$2 + local EXECUTABLE_NAME=$3 + + /usr/libexec/PlistBuddy -c 'Add :CFBundleDevelopmentRegion string English' "$CONTENTSDIR/Info.plist" 1>/dev/null + /usr/libexec/PlistBuddy -c "Add :CFBundleIconFile string $ICON_NAME" "$CONTENTSDIR/Info.plist" + /usr/libexec/PlistBuddy -c 'Add :CFBundleInfoDictionaryVersion string 6.0' "$CONTENTSDIR/Info.plist" + /usr/libexec/PlistBuddy -c 'Add :CFBundlePackageType string APPL' "$CONTENTSDIR/Info.plist" + /usr/libexec/PlistBuddy -c 'Add :CFBundleShortVersionString string 0.2' "$CONTENTSDIR/Info.plist" + /usr/libexec/PlistBuddy -c 'Add :CFBundleVersion string 0.2-10' "$CONTENTSDIR/Info.plist" + /usr/libexec/PlistBuddy -c 'Add :NSPrincipalClass string NSApplication' "$CONTENTSDIR/Info.plist" + /usr/libexec/PlistBuddy -c "Add :CFBundleExecutable string $EXECUTABLE_NAME" "$CONTENTSDIR/Info.plist" + /usr/libexec/PlistBuddy -c 'Add :LSUIElement bool true' "$CONTENTSDIR/Info.plist" +} + +# Create app launch script +create_launch_script() { + local CONTENTSDIR=$1 + local EXECUTABLE_NAME=$2 + local COMMAND=$3 + + cat << ENDOFSCRIPT > "$CONTENTSDIR/MacOS/$EXECUTABLE_NAME" +#!/usr/bin/env bash + +bash -c "$COMMAND > /dev/null 2>&1 &" +ENDOFSCRIPT + + chmod u+x "$CONTENTSDIR/MacOS/$EXECUTABLE_NAME" +} + +move_app() { + local APP_NAME=$1 + mv "$APP_NAME" /Applications/"$APP_NAME" +} + +create_imsprog_app() { + create_directories "$CONTENTSDIR1" + generate_iconset "img/logo_IMSProg.svg" "$CONTENTSDIR1/Resources/IMSProg.icns" + update_plist "$CONTENTSDIR1" "IMSProg.icns" "IMSProg" + create_launch_script "$CONTENTSDIR1" "IMSProg" "/usr/local/bin/IMSProg" + move_app "IMSProg.app" +} + +create_imsprog_editor_app() { + create_directories "$CONTENTSDIR2" + generate_iconset "IMSProg_editor/img/chipEdit64.png" "$CONTENTSDIR2/Resources/IMSProg_editor.icns" + update_plist "$CONTENTSDIR2" "IMSProg_editor.icns" "IMSProg_Editor" + create_launch_script "$CONTENTSDIR2" "IMSProg_Editor" "/usr/local/bin/IMSProg_editor" + move_app "IMSProg Editor.app" +} + +create_imsprog_database_update_app() { + create_directories "$CONTENTSDIR3" + generate_iconset "IMSProg_programmer/img/IMSProg_database_update.png" "$CONTENTSDIR3/Resources/IMSProg_database_update.icns" + update_plist "$CONTENTSDIR3" "IMSProg_database_update.icns" "IMSProg_database_update" + create_launch_script "$CONTENTSDIR3" "IMSProg_database_update" "/usr/local/bin/IMSProg_database_update" + move_app "IMSProg Database Update.app" +} + +# Run the functions to create the apps +create_imsprog_app > /dev/null +create_imsprog_editor_app > /dev/null +create_imsprog_database_update_app > /dev/null From eb56206c00a02bfcb5770539f5ce55675ac06960 Mon Sep 17 00:00:00 2001 From: Amr AlSamahy Date: Mon, 16 Sep 2024 14:11:24 +0300 Subject: [PATCH 2/2] fix: calling IMSProg_editor from inside IMSProg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit exported PATH to include the editor’s location since the spawned shell doesn’t load “~/.zshrc” Signed-off-by: Amr AlSamahy --- create_macos_appbundles.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/create_macos_appbundles.sh b/create_macos_appbundles.sh index b970f88..88942e9 100755 --- a/create_macos_appbundles.sh +++ b/create_macos_appbundles.sh @@ -54,6 +54,7 @@ create_launch_script() { cat << ENDOFSCRIPT > "$CONTENTSDIR/MacOS/$EXECUTABLE_NAME" #!/usr/bin/env bash +export PATH=$PATH:/usr/local/bin/IMSProg_editor bash -c "$COMMAND > /dev/null 2>&1 &" ENDOFSCRIPT