XIVLauncherWrapper/installer.sh

197 lines
6.1 KiB
Bash
Executable file

#!/bin/bash
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/xivlauncher-wrapper"
CONFIG_FILE="$CONFIG_DIR/config.json"
# Install paths
BIN_DIR="$HOME/.local/bin"
APP_DIR="$HOME/.local/share/applications"
ICON_DIR="$HOME/.local/share/icons/hicolor/512x512/apps"
echo "XIVLauncher Wrapper - Installer"
echo "=========================================="
# ------------------------------------------------------------------
# Helper Functions
# ------------------------------------------------------------------
check_xivlauncher_installed() {
# Check for Flatpak
if command -v flatpak >/dev/null 2>&1; then
if flatpak list --app | grep -q "dev.goats.xivlauncher"; then
echo "Found XIVLauncher (Flatpak)."
return 0
fi
fi
# Check for Native
if command -v xivlauncher >/dev/null 2>&1 || \
command -v xivlauncher-core >/dev/null 2>&1 || \
command -v xivlauncher-rb >/dev/null 2>&1; then
echo "Found XIVLauncher (Native)."
return 0
fi
return 1
}
install_flatpak_version() {
echo "Attempting to install XIVLauncher via Flatpak..."
if ! command -v flatpak >/dev/null 2>&1; then
echo "Error: 'flatpak' command not found. Cannot install Flatpak version."
return 1
fi
# Ensure Flathub repo exists (common issue if not set up)
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
# Install
flatpak install -y flathub dev.goats.xivlauncher
}
install_aur_version() {
local helper="$1"
echo "Attempting to install XIVLauncher via AUR ($helper)..."
# Using xivlauncher-bin for faster installation
$helper -S --noconfirm xivlauncher-bin
}
# ------------------------------------------------------------------
# Main Logic
# ------------------------------------------------------------------
echo "Checking for XIVLauncher installation..."
if ! check_xivlauncher_installed; then
echo "XIVLauncher not found. Attempting auto-installation..."
if [ -f "/etc/os-release" ]; then
. /etc/os-release
fi
INSTALLED=false
OS_ID="${ID:-linux}"
OS_LIKE="${ID_LIKE:-}"
# Logic for SteamOS / Bazzite (Force Flatpak)
# Bazzite often identifies as bazzite or fedora but has image-based constraints.
# Usually recommended to use Flatpaks.
if [[ "$OS_ID" == "steamos" ]] || [[ "$OS_ID" == "bazzite" ]] || [[ "$OS_ID" == "chimeraos" ]]; then
echo "Detected Gaming OS ($OS_ID). Using Flatpak."
install_flatpak_version
if check_xivlauncher_installed; then INSTALLED=true; fi
# Logic for Arch / CachyOS (Try AUR, Fallback to Flatpak)
elif [[ "$OS_ID" == "arch" ]] || [[ "$OS_ID" == "cachyos" ]] || [[ "$OS_LIKE" == *"arch"* ]]; then
echo "Detected Arch-based OS ($OS_ID)."
if command -v yay >/dev/null 2>&1; then
install_aur_version "yay"
INSTALLED=true
elif command -v paru >/dev/null 2>&1; then
install_aur_version "paru"
INSTALLED=true
else
echo "No AUR helper (yay/paru) found. Falling back to Flatpak."
install_flatpak_version
if check_xivlauncher_installed; then INSTALLED=true; fi
fi
# Fallback for others
else
echo "Detected OS: $OS_ID."
if command -v flatpak >/dev/null 2>&1; then
echo "Flatpak found. Defaulting to Flatpak version."
install_flatpak_version
if check_xivlauncher_installed; then INSTALLED=true; fi
else
echo "Flatpak is not installed."
echo "We recommend installing XIVLauncher via Flatpak on this distribution."
echo "Please install Flatpak using your package manager, then run this script again."
fi
fi
# Final Check
if ! check_xivlauncher_installed; then
echo "WARNING: Automated installation failed or XIVLauncher is still not detected."
echo "You will need to install XIVLauncher manually."
read -p "Press Enter to continue with wrapper installation anyway..." _
else
echo "XIVLauncher installed successfully!"
fi
else
echo "XIVLauncher is already present."
fi
echo ""
# Create config directory if it doesn't exist
mkdir -p "$CONFIG_DIR"
SETUP_CONFIG=true
if [ -f "$CONFIG_FILE" ]; then
echo "Configuration file already exists at: $CONFIG_FILE"
read -p "Do you want to overwrite it? (y/N): " OVERWRITE
if [[ ! "$OVERWRITE" =~ ^[Yy]$ ]]; then
echo "Skipping configuration setup."
SETUP_CONFIG=false
fi
fi
if [ "$SETUP_CONFIG" = true ]; then
echo "Creating empty configuration file..."
echo "{}" > "$CONFIG_FILE"
echo "Configuration created at: $CONFIG_FILE"
echo "You will be prompted for your OTP secret when you run the wrapper for the first time."
fi
echo ""
echo "Installing application files..."
# Create directories
mkdir -p "$BIN_DIR"
mkdir -p "$APP_DIR"
mkdir -p "$ICON_DIR"
# Install Wrapper Script
echo "Installing wrapper script to $BIN_DIR/xivlauncher-wrapper..."
cp wrapper.py "$BIN_DIR/xivlauncher-wrapper"
chmod +x "$BIN_DIR/xivlauncher-wrapper"
# Install Icon
echo "Installing icon to $ICON_DIR/xivlauncher-wrapper.png..."
if [ -f "xivlauncher-wrapper.png" ]; then
cp xivlauncher-wrapper.png "$ICON_DIR/xivlauncher-wrapper.png"
else
echo "Warning: xivlauncher-wrapper.png not found in current directory. Icon installation skipped."
fi
# Install Desktop File
echo "Installing desktop file to $APP_DIR/xivlauncher-wrapper.desktop..."
# We generate the desktop file content to ensure paths are correct
cat > "$APP_DIR/xivlauncher-wrapper.desktop" <<EOF
[Desktop Entry]
Name=XIVLauncher Wrapper
Comment=FFXIV Launcher with OTP Injection
Exec=$BIN_DIR/xivlauncher-wrapper
Icon=xivlauncher-wrapper
Terminal=false
Type=Application
Categories=Game;
Keywords=ffxiv;launcher;mmo;
EOF
echo "Updating desktop database..."
if command -v update-desktop-database >/dev/null 2>&1; then
update-desktop-database "$APP_DIR"
else
echo "update-desktop-database not found, skipping."
fi
echo ""
echo "Installation complete!"
echo "You may need to add $BIN_DIR to your PATH if it's not already there."