#!/bin/bash # file: gsl__tools # Folder: /var/lib/gsl/scripts # By echolib # License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 #======================================================================= # Tool: Source if found #======================================================================= gsl__check_source() { if [[ -f "$1" ]];then source "$1" else echo "! Missing file: $1" return 1 fi } #======================================================================= # Tool: Check needed file #======================================================================= gsl__check_file() { if ! [[ -f "$1" ]];then return fi } #======================================================================= # Check Needed Folders, and create needed files #======================================================================= # Folders gsl__create_ff() { for gsl_folder in "$gsl_dir_db" \ "$gsl_dir_logs" do if ! [[ -d "$gsl_folder" ]];then echo ": Creating $gsl_folder and give permissions to $USER" sudo mkdir -p "$gsl_folder" && \ sudo chown -R $USER:$USER "$gsl_folder" fi done # Files for gsl_file in "$gsl_file_logs" \ "$gsl_file_db_posts" \ "$gsl_file_db_stats" \ "$gsl_file_db_domains" do gsl__check_file "$gsl_file" && touch "$gsl_file" done } #======================================================================= # Check if PWD is configure for DOMAIN #======================================================================= gsl__find_domain() { gsl_nbr_domains=` find . -maxdepth 1 -not -type d -type f \ -iname "gsl.*.*" 2>/dev/null \ | wc -l` (( $gsl_nbr_domains > 1 )) \ && echo "! Too much domains registred here: Set only One per folder" \ && exit $gsl_nbr_domains (( $gsl_nbr_domains == 0 )) \ && echo "! No registred domain here: change or set folder. See help new" \ && exit 1 gsl_find_domain=` find . -maxdepth 1 -not -type d -type f \ -iname "gsl.*.*" 2>/dev/null` gsl_find_domain=` awk -F"." '{print $(NF-1)"."$NF}' \ <<< $gsl_find_domain` gsl_find_domain=${gsl_find_domain,,} gsl__check_domain "$gsl_find_domain" } #======================================================================= # Check and set domain from DB #======================================================================= gsl__check_domain() { gsl_this_conf_domain=`grep "$1" "$gsl_file_db_domains"` ! [[ "$gsl_this_conf_domain" ]] \ && echo "! Domain Not found: $1" \ && exit 1 gsl_dir_domain_tpl="$gsl_this_conf_domain/templates" gsl_dir_domain_files="$gsl_this_conf_domain/files" gsl_dir_domain_images="$gsl_this_conf_domain/images" for gsl_new_dir in `set -o posix ; set \ | grep "gsl_dir_domain" \ | awk -F= '{print $2}'` do if ! [[ -d "$gsl_new_dir" ]];then mkdir -p "$gsl_new_dir" 2>/dev/null && \ gsl__logs_print \ "$gsl_log_i" \ "Folder" \ "Init..." \ "Created" \ "$gsl_new_dir" fi done }