2022-02-13 17:58:25 +01:00
|
|
|
#!/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
|
2022-02-14 02:57:58 +01:00
|
|
|
return
|
2022-02-13 17:58:25 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
|
|
|
# Check Needed Folders, and create needed files
|
|
|
|
#=======================================================================
|
|
|
|
# Folders
|
|
|
|
gsl__create_ff() {
|
|
|
|
for gsl_folder in "$gsl_dir_db" \
|
|
|
|
"$gsl_dir_logs"
|
|
|
|
do
|
2022-02-14 02:57:58 +01:00
|
|
|
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
|
2022-02-13 17:58:25 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
# Files
|
2022-02-14 02:57:58 +01:00
|
|
|
for gsl_file in "$gsl_file_logs" \
|
|
|
|
"$gsl_file_db_posts" \
|
|
|
|
"$gsl_file_db_stats" \
|
|
|
|
"$gsl_file_db_domains"
|
2022-02-13 17:58:25 +01:00
|
|
|
do
|
2022-02-14 02:57:58 +01:00
|
|
|
gsl__check_file "$gsl_file" || \
|
|
|
|
touch "$gsl_file"
|
2022-02-13 17:58:25 +01:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
|
|
|
# Check if PWD is configure for DOMAIN
|
|
|
|
#=======================================================================
|
|
|
|
gsl__find_domain() {
|
|
|
|
gsl_nbr_domains=`
|
2022-02-14 02:57:58 +01:00
|
|
|
find . -maxdepth 1 -not -type d -type f \
|
|
|
|
-iname "gsl.*.*" 2>/dev/null \
|
|
|
|
| wc -l`
|
|
|
|
|
2022-02-13 17:58:25 +01:00
|
|
|
if (( $gsl_nbr_domains > 1 ));then
|
2022-02-14 02:57:58 +01:00
|
|
|
echo "! Too much domains registred here: Set only One per folder"
|
|
|
|
return
|
2022-02-13 17:58:25 +01:00
|
|
|
elif (( $gsl_nbr_domains == 0 ));then
|
2022-02-14 02:57:58 +01:00
|
|
|
echo "! No registred domain here: change or set folder. See help new"
|
|
|
|
return
|
2022-02-13 17:58:25 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
gsl_find_domain=`
|
2022-02-14 02:57:58 +01:00
|
|
|
find . -maxdepth 1 -not -type d -type f \
|
|
|
|
-iname "gsl.*.*" 2>/dev/null`
|
2022-02-13 17:58:25 +01:00
|
|
|
|
|
|
|
if [[ "$gsl_find_domain" ]];then
|
2022-02-14 02:57:58 +01:00
|
|
|
gsl_find_domain=`
|
|
|
|
awk -F"." '{print $(NF-1)"."$NF}' \
|
|
|
|
<<< $gsl_find_domain`
|
|
|
|
|
|
|
|
gsl_find_domain=${gsl_find_domain,,}
|
|
|
|
gsl__check_domain "$gsl_find_domain"
|
2022-02-13 17:58:25 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
|
|
|
# Check and set domain from db
|
|
|
|
#=======================================================================
|
|
|
|
gsl__check_domain() {
|
|
|
|
gsl_this_conf_domain=`grep "$1" "$gsl_file_db_domains"`
|
2022-02-14 02:57:58 +01:00
|
|
|
|
2022-02-13 17:58:25 +01:00
|
|
|
! [[ "$gsl_this_conf_domain" ]] \
|
2022-02-14 02:57:58 +01:00
|
|
|
&& echo "! Domain Not found: $1"
|
2022-02-13 17:58:25 +01:00
|
|
|
}
|