#!/bin/sh

echo "Started the pre-install script"

#pbx working dir
PBX_APP_DIR=/usr/Applications
PBX_WD=/usr/Applications/snomone

#pbx install dir
PBXINSTALL=/usr/Applications/snomone

echo "Create dir if not present"

# Make sure that we have a data directory for the PBX:
if [ ! -d $PBX_APP_DIR ]; then
   mkdir $PBX_APP_DIR
fi

if [ ! -d $PBX_WD ]; then
    echo $PBXWD "folder does not exists. Creating..." 
    mkdir $PBX_WD
fi

# Make sure that we have a data directory for the PBX:
if [ ! -d $PBXINSTALL ]; then 
    echo $PBXINSTALL "folder does not exists. Creating..."
    mkdir $PBXINSTALL
fi

# Remove all other old executables:
if [ -f pbxctrl.old ]; then
  echo "Removing pbxctrl.old"
  rm -f pbxctrl.old
fi

# unload the snomONE if it is already running
launchctl unload -w /Library/LaunchDaemons/com.vodia.snomone.plist

echo "moving pbxctrl to pbxctrl.old"
mv pbxctrl pbxctrl.old

echo "Completed the pre-install script"

