#!/bin/bash

# Postavljanje promenljivih za boje
BR='\033[1;91m' # Bold Red
BG='\033[1;92m' # Bold Green
BGW='\033[1;97m' # Bold White
NC='\033[0m' # No Color

# Laravel website folder rights and permissions
echo -e "\n${BR}Laravel website folder rights and permissions${NC} \n"
sudo chown -R fitness:fitness /home/fitness/public_html/laravel-website
sleep 0.2

echo -e "\n${BG}Changing group and ownership of the files to fitness${NC} \n"
sleep 0.2

# Postavljanje dozvola za Laravel storage i bootstrap foldere
cd /home/fitness/public_html/laravel-website
sudo chgrp -R fitness bootstrap/ storage/ storage/logs/
sleep 0.2
sudo chmod -R g+w bootstrap/ storage/ storage/logs/
echo -e "\n${BG}Storage, Bootstrap and Logs folder and permissions set to fitness${NC} \n"
sleep 0.2
sudo find bootstrap/ storage/ storage/logs/ -type d -exec chmod g+s {} +

# Postavljanje dozvola za logove u sistemskim folderima

# CWP webservers logs
echo -e "\n${BG}Setting permissions for all CWP webservers log files${NC} \n"
sudo chown -R fitness:fitness /var/log/cwp/
sudo chmod -R g+w /var/log/cwp/

# CWPSRV logs
echo -e "\n${BG}Setting permissions for all CWPSRV log files${NC} \n"
sudo chown -R fitness:fitness /usr/local/cwpsrv/logs/
sudo chmod -R g+w /usr/local/cwpsrv/logs/

# Apache domlogs
echo -e "\n${BG}Setting permissions for all Apache domlogs files${NC} \n"
sudo chown -R fitness:fitness /usr/local/apache/domlogs/
sudo chmod -R g+w /usr/local/apache/domlogs/

# Nginx logs
echo -e "\n${BG}Setting permissions for all Nginx log files${NC} \n"
sudo chown -R fitness:fitness /var/log/nginx/
sudo chmod -R g+w /var/log/nginx/

# Završna poruka
echo -e "\n${BGW}System log files permissions set to fitness${NC} \n"
sleep 0.2

# Postavljanje dozvola za Laravel logove
sudo chown -R fitness:fitness /home/fitness/public_html/laravel-website/storage/logs
sudo chmod -R 775 /home/fitness/public_html/laravel-website/storage/logs
sleep 0.2
