gsl-statique-litterateur/var/lib/gsl/scripts/gsl__tools

94 lines
2.5 KiB
Bash

#!/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`
if (( $gsl_nbr_domains > 1 ));then
echo "! Too much domains registred here: Set only One per folder"
return
elif (( $gsl_nbr_domains == 0 ));then
echo "! No registred domain here: change or set folder. See help new"
return
fi
gsl_find_domain=`
find . -maxdepth 1 -not -type d -type f \
-iname "gsl.*.*" 2>/dev/null`
if [[ "$gsl_find_domain" ]];then
gsl_find_domain=`
awk -F"." '{print $(NF-1)"."$NF}' \
<<< $gsl_find_domain`
gsl_find_domain=${gsl_find_domain,,}
gsl__check_domain "$gsl_find_domain"
fi
}
#=======================================================================
# 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"
}