#!/bin/bash # Engine selection echo "Please select the engine you want to use:" echo "1. Godot" echo "2. Unity" read -p "Enter your choice (1 or 2): " engine_choice case $engine_choice in 1) ENGINE="Godot" LAUNCHER_SUFFIX="" ;; 2) ENGINE="Unity" LAUNCHER_SUFFIX="-Unity" ;; *) echo "Invalid choice. Exiting." exit 1 ;; esac # Define the directories APPSTORE_DIR="/Users/$USER/appstore" STORAGE_DIR="$APPSTORE_DIR/AppStorage" CONFIG_FILE="$STORAGE_DIR/config.json" LAUNCHER_UPDATE_CONFIG_FILE="$STORAGE_DIR/launcher_update_config.json" # Check if appstore directory exists if [ ! -d "$APPSTORE_DIR" ]; then echo "Directory $APPSTORE_DIR does not exist." exit 1 fi # Check if config files exist if [ ! -f "$CONFIG_FILE" ]; then echo "Config file $CONFIG_FILE does not exist." exit 1 fi if [ ! -f "$LAUNCHER_UPDATE_CONFIG_FILE" ]; then echo "Launcher update config file $LAUNCHER_UPDATE_CONFIG_FILE does not exist." exit 1 fi # Confirmation prompt echo "You have selected: $ENGINE" echo "This will:" echo "- Delete oa-app.app from QA, UAT, and PROD directories" echo "- Update config to use $ENGINE engine" echo "- Download the latest launcher for $ENGINE engine" echo "- Install the launcher in /Applications" echo "- Launch the launcher" read -p "Are you sure you want to proceed? (y/N): " confirm if [[ ! $confirm =~ ^[Yy]$ ]]; then echo "Operation cancelled." exit 0 fi # Delete oa-app.app directories echo "Deleting oa-app.app directories..." rm -rf "$APPSTORE_DIR/QA/oa-app.app" rm -rf "$APPSTORE_DIR/UAT/oa-app.app" rm -rf "$APPSTORE_DIR/PROD/oa-app.app" # Update config.json echo "Updating config.json for $ENGINE engine..." # Create temporary files for jq operations TEMP_CONFIG=$(mktemp) TEMP_LAUNCHER_CONFIG=$(mktemp) # Update release_url and launcher_release_url if [ "$ENGINE" = "Godot" ]; then jq --arg engine "$ENGINE" ' .release_url = "https://git.offtop.club/api/v1/repos/Apps/\($engine)-{env}/releases" | .launcher_release_url = "https://git.offtop.club/api/v1/repos/Apps/Launcher-{env}/releases/latest" ' "$CONFIG_FILE" > "$TEMP_CONFIG" else jq --arg engine "$ENGINE" ' .release_url = "https://git.offtop.club/api/v1/repos/Apps/\($engine)-{env}/releases" | .launcher_release_url = "https://git.offtop.club/api/v1/repos/Apps/Launcher-Unity-{env}/releases/latest" ' "$CONFIG_FILE" > "$TEMP_CONFIG" fi # Replace original config file mv "$TEMP_CONFIG" "$CONFIG_FILE" # Update launcher_update_config.json echo "Updating launcher_update_config.json for $ENGINE engine..." if [ "$ENGINE" = "Godot" ]; then jq ' .launcher_release_url = "https://git.offtop.club/api/v1/repos/Apps/Launcher-{env}/releases/latest" ' "$LAUNCHER_UPDATE_CONFIG_FILE" > "$TEMP_LAUNCHER_CONFIG" else jq ' .launcher_release_url = "https://git.offtop.club/api/v1/repos/Apps/Launcher-Unity-{env}/releases/latest" ' "$LAUNCHER_UPDATE_CONFIG_FILE" > "$TEMP_LAUNCHER_CONFIG" fi # Replace original launcher update config file mv "$TEMP_LAUNCHER_CONFIG" "$LAUNCHER_UPDATE_CONFIG_FILE" echo "Configuration updated successfully for $ENGINE engine." # Auto download of the launcher per engine echo "Downloading latest launcher for $ENGINE engine..." # Get environment from config.json ENVIRONMENT=$(jq -r '.environment' "$CONFIG_FILE") echo "Using environment: $ENVIRONMENT" # Determine download URL based on engine and environment if [ "$ENGINE" = "Godot" ]; then DOWNLOAD_URL="https://git.offtop.club/api/v1/repos/Apps/Launcher-$ENVIRONMENT/releases/latest" else DOWNLOAD_URL="https://git.offtop.club/api/v1/repos/Apps/Launcher-Unity-$ENVIRONMENT/releases/latest" fi # Create temporary directory for download TEMP_DIR=$(mktemp -d) DMG_PATH="$TEMP_DIR/oa-launcher.dmg" # Get the download URL for the DMG file and version info echo "Fetching release information..." RELEASE_INFO=$(curl -s "$DOWNLOAD_URL") ASSET_URL=$(echo "$RELEASE_INFO" | jq -r '.assets[] | select(.name == "oa-launcher.dmg") | .browser_download_url') LAUNCHER_VERSION=$(echo "$RELEASE_INFO" | jq -r '.tag_name') if [ "$ASSET_URL" = "null" ] || [ -z "$ASSET_URL" ]; then echo "Error: Could not find oa-launcher.dmg in the latest release." rm -rf "$TEMP_DIR" exit 1 fi if [ "$LAUNCHER_VERSION" = "null" ] || [ -z "$LAUNCHER_VERSION" ]; then echo "Warning: Could not extract version from release info." LAUNCHER_VERSION="unknown" fi echo "Found launcher version: $LAUNCHER_VERSION" # Download the DMG file echo "Downloading launcher from: $ASSET_URL" curl -L -o "$DMG_PATH" "$ASSET_URL" if [ ! -f "$DMG_PATH" ]; then echo "Error: Failed to download the launcher." rm -rf "$TEMP_DIR" exit 1 fi # Mount the DMG echo "Mounting DMG..." MOUNT_OUTPUT=$(hdiutil attach "$DMG_PATH" -nobrowse) echo "Raw mount output:" echo "$MOUNT_OUTPUT" # Extract mount point more reliably MOUNT_POINT=$(echo "$MOUNT_OUTPUT" | grep -E '^/dev/' | awk '{for(i=3;i<=NF;i++) printf "%s%s", $i, (i==NF?"\n":" ")}' | tr -d '\n') if [ -z "$MOUNT_POINT" ]; then echo "Error: Failed to extract mount point from hdiutil output." echo "Mount output: $MOUNT_OUTPUT" rm -rf "$TEMP_DIR" exit 1 fi echo "DMG mounted at: '$MOUNT_POINT'" # List contents to debug echo "Contents of mounted DMG:" ls -la "$MOUNT_POINT/" # Remove existing application if it exists if [ -d "/Applications/OA-Launcher.app" ]; then echo "Removing existing OA-Launcher.app..." rm -rf "/Applications/OA-Launcher.app" fi # Copy the app to Applications echo "Installing OA-Launcher.app to /Applications..." if [ -d "$MOUNT_POINT/OA-Launcher.app" ]; then cp -R "$MOUNT_POINT/OA-Launcher.app" "/Applications/" else echo "Error: OA-Launcher.app not found in mounted DMG at $MOUNT_POINT" echo "Available files:" ls -la "$MOUNT_POINT/" hdiutil detach "$MOUNT_POINT" -quiet rm -rf "$TEMP_DIR" exit 1 fi # Unmount the DMG hdiutil detach "$MOUNT_POINT" -quiet # Clean up temporary files rm -rf "$TEMP_DIR" # Remove quarantine attribute echo "Removing quarantine attribute..." xattr -d com.apple.quarantine "/Applications/OA-Launcher.app" 2>/dev/null || true # Update launcher version in both config files if [ "$LAUNCHER_VERSION" != "unknown" ]; then echo "Updating launcher version to $LAUNCHER_VERSION in config files..." # Update config.json TEMP_CONFIG_VERSION=$(mktemp) jq --arg version "$LAUNCHER_VERSION" '.launcher_version = $version' "$CONFIG_FILE" > "$TEMP_CONFIG_VERSION" mv "$TEMP_CONFIG_VERSION" "$CONFIG_FILE" # Update launcher_update_config.json TEMP_LAUNCHER_CONFIG_VERSION=$(mktemp) jq --arg version "$LAUNCHER_VERSION" '.launcher_version = $version' "$LAUNCHER_UPDATE_CONFIG_FILE" > "$TEMP_LAUNCHER_CONFIG_VERSION" mv "$TEMP_LAUNCHER_CONFIG_VERSION" "$LAUNCHER_UPDATE_CONFIG_FILE" echo "Launcher version updated to $LAUNCHER_VERSION in both config files." else echo "Skipping version update due to unknown version." fi # Automatically launch the launcher echo "Launching OA-Launcher..." open "/Applications/OA-Launcher.app" echo "Setup completed successfully! OA-Launcher $LAUNCHER_VERSION has been installed and launched."