#!/bin/bash

#Tworzenie katalogow
echo -e "\033[01;34m Utworzenie folderow w /home/test/ \033[00m"
if [ ! -d /home/test ]; then
	mkdir -p /home/test
fi
cd /home/test
mkdir -p public_html
mkdir -p repos
mkdir -p repository
mkdir -p maildir
mkdir -p files
mkdir -p public_ftp
mkdir -p users
mkdir -p vendor
mkdir -p public_html/apps
mkdir -p public_html/apps/backproc
mkdir -p public_html/apps/backproc/data
mkdir -p public_html/apps/backproc/logs
mkdir -p public_html/apps/backproc/pid
mkdir -p public_html/apps/edokumenty
mkdir -p public_html/apps/edokumenty/scripts
mkdir -p public_html/apps/edokumenty/scripts/FileIndexingTool
mkdir -p public_html/apps/edokumenty/scripts/FileIndexingTool/conf
mkdir -p public_html/apps/edokumenty/var/cache/tmpl
mkdir -p var/log

echo -e "\033[01;34m Nadanie uprawenień do utworzonych folderow \033[00m"
#Uprawnienia do katalogow systemu
chown -R test:test public_html
chown -R test:test vendor

# Jeśli dodatkowo nieprawidłowo ustawione są uprawnienia do plików w repozytorium
chown -R www-data:test files maildir repository repos public_ftp users var
# Grant read/write/execute to owner and group, remove all permissions for others for security
chmod -R u+rwX,g+rwX,o-rwx files maildir repository repos public_ftp users var

# Ustaw uprawnienia dla podkatalogów katalogu backproc
cd /home/test/public_html/apps/backproc
chown -R www-data:test data logs pid
chmod -R u+rwX,g+rwXs,o-rwx data logs pid