LuckyWorld/scripts/install_luckyworld.sh

118 lines
3.8 KiB
Bash

#!/bin/bash
# LuckyWorld macOS Installation Script
# This script installs the LuckyWorld app and removes macOS Gatekeeper quarantine flags
# Terminal colors
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# App paths
APP_NAME="LuckyWorld.app"
APP_SOURCE="$(cd "$(dirname "$0")" && pwd)/$APP_NAME"
APP_DEST="/Applications/$APP_NAME"
# Checking script permissions
if [[ $EUID -ne 0 ]]; then
echo -e "${YELLOW}This script requires administrator permissions to run.${NC}"
echo -e "${BLUE}Requesting administrator access...${NC}"
# Get the script path and re-run with sudo
SCRIPT_PATH=$(readlink -f "$0")
exec sudo "$SCRIPT_PATH"
exit 0
fi
# Header
echo -e "${BLUE}============================================${NC}"
echo -e "${GREEN}LuckyWorld macOS Installation Tool${NC}"
echo -e "${BLUE}============================================${NC}"
echo ""
# Check if source app exists
if [ ! -d "$APP_SOURCE" ]; then
# Check if source app exists in the same directory as the script
APP_SOURCE="$(cd "$(dirname "$0")" && pwd)/../$APP_NAME"
if [ ! -d "$APP_SOURCE" ]; then
echo -e "${RED}ERROR: Could not find $APP_NAME${NC}"
echo -e "${YELLOW}Please make sure the application is located in the same directory as this script.${NC}"
exit 1
fi
fi
echo -e "${BLUE}Source application: ${NC}${YELLOW}$APP_SOURCE${NC}"
echo -e "${BLUE}Destination: ${NC}${YELLOW}$APP_DEST${NC}"
echo ""
# Check if application already exists and is running
if [ -d "$APP_DEST" ]; then
echo -e "${YELLOW}Application $APP_NAME already exists in Applications folder.${NC}"
# Check if app is running
if pgrep -x "LuckyWorld" > /dev/null; then
echo -e "${RED}LuckyWorld is currently running. Please close the application before continuing.${NC}"
read -p "Press Enter after closing the application to continue..."
# Check again
if pgrep -x "LuckyWorld" > /dev/null; then
echo -e "${RED}LuckyWorld is still running. Installation aborted.${NC}"
exit 1
fi
fi
echo -e "${BLUE}Removing existing version...${NC}"
rm -rf "$APP_DEST"
if [ $? -ne 0 ]; then
echo -e "${RED}ERROR: Could not remove existing application. Possible permission issue.${NC}"
exit 1
fi
echo -e "${GREEN}Existing application removed successfully.${NC}"
fi
# Install the application
echo -e "${BLUE}Installing $APP_NAME to Applications folder...${NC}"
cp -R "$APP_SOURCE" /Applications/
if [ $? -ne 0 ]; then
echo -e "${RED}ERROR: Installation failed. Could not copy the application to /Applications.${NC}"
exit 1
fi
# Clear macOS Gatekeeper quarantine flag
echo -e "${BLUE}Removing Gatekeeper quarantine flag...${NC}"
xattr -rd com.apple.quarantine "$APP_DEST"
if [ $? -ne 0 ]; then
echo -e "${YELLOW}WARNING: Could not remove Gatekeeper quarantine flag.${NC}"
echo -e "${YELLOW}You may need to manually allow the application in System Preferences > Security & Privacy.${NC}"
else
echo -e "${GREEN}Gatekeeper restrictions removed successfully.${NC}"
fi
# Set proper permissions
echo -e "${BLUE}Setting permissions...${NC}"
chmod -R 755 "$APP_DEST"
# Successful installation message
echo -e "${GREEN}✅ LuckyWorld has been successfully installed!${NC}"
echo -e "${BLUE}============================================${NC}"
echo -e "${YELLOW}To start the application, open /Applications/$APP_NAME${NC}"
echo -e "${BLUE}============================================${NC}"
# Ask if user wants to launch the app
echo ""
read -p "Would you like to launch LuckyWorld now? (y/n): " LAUNCH_APP
if [[ "$LAUNCH_APP" =~ ^[Yy]$ ]]; then
echo -e "${BLUE}Launching LuckyWorld...${NC}"
open "$APP_DEST"
echo -e "${GREEN}Done!${NC}"
fi
exit 0