#!/bin/sh
#********************************************************************#
#  Easy Bootstrap Installer - Part 2                                 #
#  Description: automatic bootstrap installer for synology nas       #
#  Author:      QTip from the german Synology support forum          #
#  Copyright:   2015-2016 by QTip                                    #
#  License:     GNU GPLv3 (see LICENSE)                              #
#  ----------------------------------------------------------------  #
#  Version:     0.7 - 19/12/2015                                     #
#  for more information check the changelog                          #
#********************************************************************#

[ -f /tmp/${SYNOPKG_PKGNAME}.upgrade ] && exit 0

if [ "${OUTPUTERROR}" == "true" ] ; then
     exit 1
fi

if [ -f `/usr/bin/dirname $0`/lang/${SYNOPKG_DSM_LANGUAGE} ] ; then
     . `/usr/bin/dirname $0`/lang/${SYNOPKG_DSM_LANGUAGE}
else
     . `/usr/bin/dirname $0`/lang/enu
fi
. `/usr/bin/dirname $0`/lsof_lite

PKG_VOL_TMP=/volume1/@tmp
if [ "${select_integratevbox}" == "true" ] ; then
     VBOXOPEN=$(lsof_lite "/opt/VirtualBox /volume?/@*ware/VirtualBox /volumeUSB?/usbshare*/@*ware/VirtualBox")
     if [ -n "${VBOXOPEN}" ] ; then
          echo "${PKG_OPENFILES_ERROR4} <b>/opt/VirtualBox</b> ${PKG_ERROR_PART4}<br>${PKG_OPENFILES_ERROR2}<br>&nbsp;&nbsp;${VBOXOPEN}" > ${SYNOPKG_TEMP_LOGFILE}
          exit 1
     else
          /bin/mkdir -p ${PKG_VOL_TMP}/ebi
          /bin/mv /opt/VirtualBox ${PKG_VOL_TMP}/ebi
     fi
fi
if [ "${select_integrate_bssource}" == "true" ] ; then
     /bin/mkdir -p ${PKG_VOL_TMP}/ebi
     /bin/cp -r /opt/* ${PKG_VOL_TMP}/ebi
#     /bin/rm -rf /opt
elif [ "${select_integrate_bssource}" == "false" ] ; then
     TIMESTAMP="`/bin/date "+%s"`"
     /bin/mv -f /opt /opt_${TIMESTAMP}
fi
if [ -n "${select_remove_bssource}" ] ; then
     if [ -x `/usr/bin/dirname $0`/remove_bootstrap ] ; then
          `/usr/bin/dirname $0`/remove_bootstrap
     else
          if [ -d ${PKG_VOL_TMP}/ebi/VirtualBox ] ; then
               [ -e /opt ] || /bin/mkdir -p /opt
               /bin/mv ${PKG_VOL_TMP}/ebi/* /opt
          fi
          exit 1
     fi
fi
