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" \
|
2022-02-19 18:17:09 +01:00
|
|
|
"$gsl_file_db_files" \
|
2022-02-14 02:57:58 +01:00
|
|
|
"$gsl_file_db_domains"
|
2022-02-13 17:58:25 +01:00
|
|
|
do
|
2022-02-17 11:03:25 +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-16 14:11:41 +01:00
|
|
|
(( $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
|
2022-02-13 17:58:25 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-02-16 14:11:41 +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
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
2022-02-15 17:56:45 +01:00
|
|
|
# Check and set domain from DB
|
2022-02-13 17:58:25 +01:00
|
|
|
#=======================================================================
|
|
|
|
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-15 17:56:45 +01:00
|
|
|
&& echo "! Domain Not found: $1" \
|
2022-02-16 14:11:41 +01:00
|
|
|
&& exit 1
|
2022-02-15 17:56:45 +01:00
|
|
|
|
|
|
|
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
|
2022-02-13 17:58:25 +01:00
|
|
|
}
|