#!/bin/sh
# Makes BeRoTracker.app able to stand on its own, so that it can be dragged anywhere.
#
# Out of the archive the bundle has no palettes and no equalizer presets of its own: they lie in this
# folder, beside it, and all three builds - Linux, Windows and macOS - read the one set. That is why
# the bundle must not be dragged away as it comes; away from this folder it would find neither.
#
# This puts a set of both inside the bundle. Nothing is taken away from this folder, so the builds
# for the other two systems go on working exactly as before.
#
# Afterwards: drag BeRoTracker.app wherever you want it. While it still stands in this folder it goes on
# reading the ones out here, so nothing changes until it is moved.
set -eu

here="$(cd "$(dirname "$0")" && pwd)"
app="$here/BeRoTracker.app"
inside="$app/Contents/MacOS"

[ -d "$app" ] || {
  echo "$(basename "$0"): BeRoTracker.app is not beside this script." >&2
  echo "Run it from the folder both were unpacked into." >&2
  exit 1
}

copied=0
for what in palettes EQPresets; do
  if [ -d "$here/$what" ]; then
    rm -rf "$inside/$what"
    cp -R "$here/$what" "$inside/$what"
    echo "  $what -> BeRoTracker.app/Contents/MacOS/$what"
    copied=1
  else
    echo "  $what is not here, skipped" >&2
  fi
done

[ "$copied" -eq 1 ] || {
  echo "$(basename "$0"): nothing to put in, the folders are missing." >&2
  exit 1
}

echo ""
echo "BeRoTracker.app can now stand on its own. Drag it wherever you want it, /Applications included."
echo ""
echo "It writes nothing into itself: the settings, the cache of the directory and any palette you"
echo "save go to ~/Library/Application Support/BeRoTracker."
