#!/usr/bin/env bash # Illuscape installer # Usage: ./install.sh [--preset=cc|cs6] [--yes] set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PRESET="" AUTO_YES=0 # ── Parse args ────────────────────────────────────────────────────────────── for arg in "$@"; do case "$arg" in --preset=cc|--preset=cs6) PRESET="${arg#--preset=}" ;; --yes|-y) AUTO_YES=1 ;; --help|-h) echo "Usage: ./install.sh [--preset=cc|cs6] [--yes]" echo " --preset=cc Illustrator CC shortcuts (default)" echo " --preset=cs6 Illustrator CS6 shortcuts" echo " --yes Skip confirmation prompts" exit 0 ;; *) echo "Unknown argument: $arg"; exit 1 ;; esac done # ── Check dependencies ─────────────────────────────────────────────────────── check_deps() { if ! command -v inkscape &>/dev/null; then echo "✗ Inkscape is not installed. Install Inkscape first, then run Illuscape." exit 1 fi local version version=$(inkscape --version 2>/dev/null | grep -oP '\d+\.\d+' | head -1) local major minor IFS='.' read -r major minor <<< "$version" # Skip version check if regex couldn't match (non-standard version string) if [[ -n "$major" ]] && { (( major < 1 )) || (( major == 1 && minor < 2 )); }; then echo "⚠ Inkscape $version detected. Illuscape targets Inkscape 1.2+." echo " Some settings may not apply correctly. Continue anyway? [y/N]" [[ $AUTO_YES == 1 ]] || { read -r ans; [[ "$ans" =~ ^[Yy]$ ]] || exit 0; } fi if ! command -v python3 &>/dev/null; then echo "✗ python3 is required. Install it and try again." exit 1 fi } # ── Detect platform ────────────────────────────────────────────────────────── detect_config() { source "$SCRIPT_DIR/scripts/detect_platform.sh" echo "→ Inkscape config: $INKSCAPE_CONFIG ($INKSCAPE_INSTALL_METHOD)" } # ── Backup ─────────────────────────────────────────────────────────────────── backup_config() { local backup_dir="${INKSCAPE_CONFIG}.bak-illuscape-$(date +%Y%m%d-%H%M%S)" # If any illuscape backup already exists, skip (idempotent) if ls "${INKSCAPE_CONFIG}".bak-illuscape-* &>/dev/null; then echo "→ Backup already exists — skipping (idempotent)" return 0 fi if [[ -d "$INKSCAPE_CONFIG" ]]; then cp -r "$INKSCAPE_CONFIG" "$backup_dir" echo "→ Backed up to: $backup_dir" else echo "→ No existing config to back up (fresh install)" fi } # ── Prompt for preset ──────────────────────────────────────────────────────── choose_preset() { [[ -n "$PRESET" ]] && return 0 echo "" echo "Which Illustrator era are you coming from?" echo " [1] CC — current Creative Cloud (default)" echo " [2] CS6 — last perpetual license" printf "Choice [1]: " if [[ $AUTO_YES == 1 ]]; then echo "1 (auto)" PRESET="cc" return 0 fi read -r choice case "${choice:-1}" in 2) PRESET="cs6" ;; *) PRESET="cc" ;; esac echo "→ Using preset: $PRESET" } # ── Merge preferences ──────────────────────────────────────────────────────── merge_prefs() { local prefs_file="$INKSCAPE_CONFIG/preferences.xml" python3 "$SCRIPT_DIR/scripts/merge_prefs.py" \ --prefs "$prefs_file" \ --patch "$SCRIPT_DIR/config/preferences-patch.xml" \ --preset "$PRESET" } # ── Copy config files ──────────────────────────────────────────────────────── copy_files() { mkdir -p \ "$INKSCAPE_CONFIG/keys" \ "$INKSCAPE_CONFIG/palettes" \ "$INKSCAPE_CONFIG/templates" \ "$INKSCAPE_CONFIG/symbols" \ "$INKSCAPE_CONFIG/splashscreens" cp "$SCRIPT_DIR/config/keys/illustrator-${PRESET}.xml" \ "$INKSCAPE_CONFIG/keys/" cp "$SCRIPT_DIR/config/palettes/"*.gpl "$INKSCAPE_CONFIG/palettes/" cp "$SCRIPT_DIR/config/templates/"*.svg "$INKSCAPE_CONFIG/templates/" cp "$SCRIPT_DIR/config/symbols/"*.svg "$INKSCAPE_CONFIG/symbols/" echo "→ Config files copied" } # ── Install desktop launcher + icons (Linux native only) ───────────────────── install_desktop() { [[ "$INKSCAPE_INSTALL_METHOD" != "native" ]] && return 0 local app_dir="$HOME/.local/share/applications" local icon_src="$SCRIPT_DIR/assets/illuscape.svg" local splash_src="$SCRIPT_DIR/assets/splash.svg" local icon_sizes=(16 32 48 64 128 256 512) mkdir -p "$app_dir" cp "$SCRIPT_DIR/assets/org.inkscape.Inkscape.desktop" "$app_dir/" # Rasterize icon at each size (prefer rsvg-convert, fall back to Inkscape) for size in "${icon_sizes[@]}"; do local icon_dir="$HOME/.local/share/icons/hicolor/${size}x${size}/apps" mkdir -p "$icon_dir" if command -v rsvg-convert &>/dev/null; then rsvg-convert -w "$size" -h "$size" "$icon_src" \ -o "$icon_dir/illuscape.png" 2>/dev/null && continue fi if command -v inkscape &>/dev/null; then # Inkscape 1.x uses --export-filename + --export-type (--export-png removed in 1.0) inkscape --export-filename="$icon_dir/illuscape.png" \ --export-type=png \ --export-width="$size" --export-height="$size" \ "$icon_src" 2>/dev/null && continue fi echo "⚠ Could not rasterize icon at ${size}px (install rsvg-convert for icons)" done # Splash screen (600x400) if command -v rsvg-convert &>/dev/null; then rsvg-convert -w 600 -h 400 "$splash_src" \ -o "$INKSCAPE_CONFIG/splashscreens/illuscape-splash.png" 2>/dev/null || true fi update-desktop-database "$app_dir" 2>/dev/null || true echo "→ Desktop launcher installed" } # ── Main ────────────────────────────────────────────────────────────────────── main() { echo "╔══════════════════════════════╗" echo "║ Illuscape Installer ║" echo "╚══════════════════════════════╝" echo "" check_deps detect_config backup_config choose_preset merge_prefs copy_files install_desktop echo "" echo "✓ Illuscape installed (preset: $PRESET)" echo "" echo " Open Inkscape to start using your Illustrator-style workspace." echo " To uninstall: ./uninstall.sh" echo "" } main