#!/bin/sh
# Create Project dirs.
# Registered Under General Public License 2.0 and above.
# Written by hip0. 

project_client_dir='/disk2/samba/htdocs/www.24hours-vn.com/clients';
skele_dir='/disk2/project-skele';

banner () {

clear;
printf "\t\t\tCreate New Project.\n";
printf "\t\t\t-------------------\n";

}

read_vars () {

printf "Client Name:";
read client_name;

printf "Project Name:";
read project;
project_name=`echo "$project" | sed -e "s/ /_/g"`;

printf "Add to employee:";
read employee_name;

}


create_project_dir () {

if [[ ! -d $project_client_dir/$client_name ]]; then

mkdir $project_client_dir/$client_name;
#chown -R httpd.httpd $project_client_dir/$client_name;

fi

if [[ -d $project_client_dir/$client_name ]] && \
[[ ! -d $project_client_dir/$client_name/$project_name ]]; then

mkdir $project_client_dir/$client_name/$project_name;
chown -R httpd.httpd $project_client_dir/$client_name/$project_name;

fi

}

copy_skele () {

if [[ -d $skele_dir ]]; then

cp $skele_dir/* $project_client_dir/$client_name/$project_name;
chown -R httpd.httpd $project_client_dir/$client_name;

fi

}

skele_error () {

if [[ ! -d $skele_dir ]]; then
echo "$skele_dir Does not exist. Probably Something terrible have happened.";
fi

}

chk_empl_client_dir_existence () {

if [[ ! -d /samba/$employee_name/clients ]]; then

mkdir /samba/$employee_name/clients;
chown -R httpd.httpd /samba/$employee_name/clients;

fi

}

crt_empl_prj_links () {

if [[ ! -d /samba/$employee_name/clients/$client_name ]]; then

mkdir /samba/$employee_name/clients/$client_name;
chown -R httpd.httpd /samba/$employee_name/clients/$client_name;

fi

if [[ -d /samba/$employee_name/clients ]]; then
cd /samba/$employee_name/clients/$client_name;
ln -sf $project_client_dir/$client_name/$project_name $project_name; 
chown httpd.httpd -R /samba/$employee_name/clients;

fi

}

complete_greetings () {
echo -e "\nAll Done.\n";
echo -e "\nThank you for using this Anti Microsoft Product:-]\n";
}


main () {

banner;
read_vars;
create_project_dir;
copy_skele;
skele_error;
chk_empl_client_dir_existence;
crt_empl_prj_links;
complete_greetings;
}

main;
