#!/bin/bash -p

# (Note the -p argument above. This is required, as bash otherwise will
# ignore that it is run with root as effective UID.)

if [ -z "$1" ]; then
  # This is the text shown when the installer is launched, before the
  # EULA is shown.
  echo "This will install Addictive Drums 1.5.1"
  echo "Make sure you have Mac OS X 10.4 or later!"
  echo
  echo "Disk space requirements: Demo version about 200 MB, full version about 1.5 GB, update from AD 1.1 about 50 MB."

  
  exit
fi

# Include common installer functions and environment.
source xln_installer.sh.inc

echo "Copying Resource and Data files. This may take a few minutes..."
sleep 2
copyfiles Addictive\ Drums\ Installer\ Data/Root "/Library/Application Support/Addictive Drums"


echo "Copying Garageband Instruments." 
sleep 2
copyfiles Addictive\ Drums\ Installer\ Data/MacGBI "/Library/Application Support/GarageBand/Instrument Library/Track Settings/Software/Drum Kits"


echo "Copying User files. (Existing User files will be left intact)"
sleep 2
go pushd ../../..
#go mkdir -p "${HOME}/Library/Application Support/Addictive Drums/
go rsync -rptgo --ignore-existing Addictive\ Drums\ Installer\ Data/User/* "${HOME}/Library/Application Support/Addictive Drums"
go popd
#rsync-flaggor: r underkat, p permiss, t tidstämplar, g grupp, o owner


echo "Copying plugin files (VST, AU, RTAS)."
sleep 2
# must be set as executables?
copyfiles Addictive\ Drums\ Installer\ Data/MacPlugins/Addictive\ Drums.vst "/Library/Audio/Plug-Ins/VST/Addictive Drums.vst"
copyfiles Addictive\ Drums\ Installer\ Data/MacPlugins/Addictive\ Drums.vst "/Library/Audio/Plug-Ins/Components/Addictive Drums.component"
copyfiles Addictive\ Drums\ Installer\ Data/MacPlugins/Addictive\ Drums.dpm "/Library/Application Support/Digidesign/Plug-Ins/Addictive Drums.dpm" 


# set permissions for application and user folders
go chmod -R ug=rwX,o=rX \
  "/Library/Application Support/Addictive Drums" \
  "${HOME}/Library/Application Support/Addictive Drums"

# set owner for application folder
go chown -R root:admin "/Library/Application Support/Addictive Drums"
# set owner for user folder
go chown -R `id -urn`:`id -grn`   "${HOME}/Library/Application Support/Addictive Drums"

#remove old log file from vise installer (caused problems with adpak installers when going from 1.0 to 1.5)
go rm -f "/Library/Application Support/Addictive Drums/Installer Log File"

echo "Addictive Drums was successfully installed!"
