#!/bin/bash

##
# This file is part of the MailWizz EMA application.
# It is a helper script to chmod to 0777 all the needed directories upon install
# 
# @package MailWizz EMA
# @author MailWizz Development Team <support@mailwizz.com> 
# @link https://www.mailwizz.com/
# @copyright MailWizz EMA (https://www.mailwizz.com)
# @license https://www.mailwizz.com/license/
# @since 1.3.4.8
# 
##

# full path to the document root
DOCUMENT_ROOT="$( cd "$( dirname "$0" )" && cd ../../../../ && pwd )"

# the directories we need to change permissions
PATHS[0]="$DOCUMENT_ROOT/apps/common/config"
PATHS[1]="$DOCUMENT_ROOT/apps/common/runtime"
PATHS[2]="$DOCUMENT_ROOT/backend/assets/cache"
PATHS[3]="$DOCUMENT_ROOT/customer/assets/cache"
PATHS[4]="$DOCUMENT_ROOT/frontend/assets/cache"
PATHS[5]="$DOCUMENT_ROOT/frontend/assets/files"
PATHS[6]="$DOCUMENT_ROOT/frontend/assets/gallery"
PATHS[7]="$DOCUMENT_ROOT/apps/extensions"

printf "%s\n" "Setting proper permissions for directories..."

for i in "${PATHS[@]}"
do
    printf "%s" "chmod -R 0777 $i -> "
    chmod -R 0777 "$i"
    printf "%s\n" "done."
done

printf "%s\n" "DONE!"
