#!/bin/bash

source /usr/local/bin/globalvars


if [ ! -d "${temp_backup_directory}" ]
then
  ${MKDIR} ${temp_backup_directory}
fi
  
${CHOWN} root.tempbackups ${temp_backup_directory}
${CHMOD} 770 ${temp_backup_directory}

if [ -e "${symlink}" ]
then
  ${UNLINK} ${symlink}
fi

${LN} -s ${temp_backup_directory}/ ${symlink}

if [ -d "/mnt/storage1/backups" ]
then
  ${FIND} /mnt/storage1/backups -type d -exec ${CHMOD} 750 {} \;
  ${FIND} /mnt/storage1/backups -type f -exec ${CHMOD} o-rwx {} \;
  ${FIND} /mnt/storage1/backups -type f -exec ${CHMOD} g-w {} \;
  ${CHOWN} -R root.backup /mnt/storage1/backups
fi

if [ -d "/mnt/storage2/backups" ]
then
  ${FIND} /mnt/storage2/backups -type d -exec ${CHMOD} 750 {} \;
  ${FIND} /mnt/storage2/backups -type f -exec ${CHMOD} o-rwx {} \;
  ${FIND} /mnt/storage2/backups -type f -exec ${CHMOD} g-w {} \;
  ${CHOWN} -R root.backup /mnt/storage2/backups
fi

if [ -d "/mnt/storage3/backups" ]
then
  ${FIND} /mnt/storage3/backups -type d -exec ${CHMOD} 750 {} \;
  ${FIND} /mnt/storage3/backups -type f -exec ${CHMOD} o-rwx {} \;
  ${FIND} /mnt/storage3/backups -type f -exec ${CHMOD} g-w {} \;
  ${CHOWN} -R root.backup /mnt/storage3/backups
fi

if [ -d "/mnt/storage4/backups" ]
then
  ${FIND} /mnt/storage4/backups -type d -exec ${CHMOD} 750 {} \;
  ${FIND} /mnt/storage4/backups -type f -exec ${CHMOD} o-rwx {} \;
  ${FIND} /mnt/storage4/backups -type f -exec ${CHMOD} g-w {} \;
  ${CHOWN} -R root.backup /mnt/storage4/backups
fi

