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

240 lines
6.2 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# file: gsl__db_manager
# Folder: /var/lib/gsl/scripts
2022-06-14 18:51:19 +02:00
# By echolib (XMPP: im@echolib.re)
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
2022-02-27 19:16:16 +01:00
2022-03-01 18:39:46 +01:00
#======================================================================
2022-06-14 18:51:19 +02:00
# Get arguments from COMMAND (db)
# $1 File
2022-03-01 18:39:46 +01:00
#======================================================================
2022-06-14 18:51:19 +02:00
db__OPTIONS() {
author__check || exit 0 # Check if authors registresd
2022-03-06 01:47:58 +01:00
2022-06-14 18:51:19 +02:00
! [[ "$1" ]] \
&& gsl__invalid_option "$1" "[File]"
2022-02-27 19:16:16 +01:00
2022-06-14 18:51:19 +02:00
if__file "$1" post
[[ -f "$gsl_dir_db_domain/$gsl_this_post.db" ]] \
&& cat "$gsl_dir_db_domain/$gsl_this_post.db" \
|| echo "! No DB yet for $gsl_this_post. Check it first."
exit
2022-02-19 18:17:09 +01:00
}
2022-03-01 18:39:46 +01:00
2022-06-14 18:51:19 +02:00
2022-03-01 18:39:46 +01:00
#======================================================================
2022-06-14 18:51:19 +02:00
# Get Post Hash & Status From Database
2022-03-01 18:39:46 +01:00
#======================================================================
2022-06-14 18:51:19 +02:00
DB__datas() {
if ! [[ -f "$gsl_file_db_post" ]];then
gsl__logs_print -w -D -f \
"Article not yet checked" \
"$gsl_file_db_post"
article_is_new=true
2022-03-06 01:47:58 +01:00
2022-06-14 18:51:19 +02:00
else
# Check corrupted file
Hash_DB=`cksum "$gsl_file_db_post" | awk '{print $1}'`
if ! [[ -f $gsl_file_db_post_hash.$Hash_DB ]];then
db_corrupt=true
[[ `grep "article_Status_www=" "$gsl_file_db_post"` \
|| `grep "article_Status_wip=" "$gsl_file_db_post"` ]] \
|| return
fi
source "$gsl_file_db_post"
fi
}
2022-06-14 18:51:19 +02:00
#======================================================================
# Compare post Hash from Database
#======================================================================
DB__compare_hash() {
case "$1" in
check)
gsl_do_check=true
[[ $article_is_new ]] && return
[[ $db_corrupt ]] && gsl_force_check=true
if [[ $article_Errors == "no" ]];then
if (( $article_Hash == $article_Status_chk ));then
if ! [[ $gsl_force_check ]];then
gsl__logs_print -w -g -C \
"Already done ; Use -F to force" \
"$PWD/$gsl_post"
unset gsl_do_check
fi
else
gsl__logs_print -w -g \
"Compare" \
"Old Hash: $article_Status_chk" \
"${PWD}/$gsl_post"
fi
fi
;;
make|www)
[[ $db_corrupt ]] \
&& gsl__logs_print -e -D -f \
"Corrupted ; Check again first" \
"$gsl_file_db_post" \
&& return
[[ $article_is_new ]] && return
2022-06-23 12:24:01 +02:00
if (( $article_Hash != $article_Status_chk ));then
gsl__logs_print -e -A -inv \
"Article not checked yet" \
"$PWD/$gsl_post"
return
elif [[ $article_Errors == "yes" ]];then
gsl__logs_print -e -A -inv \
"Found errors ; Cannot continue" \
"$PWD/$gsl_post"
return
fi
2022-06-14 18:51:19 +02:00
gsl_do_make=true
;;
esac
}
2022-06-14 18:51:19 +02:00
#======================================================================
# Logger
#======================================================================
DB__create_log() {
gsl__logs_print -i -D -c \
"$article_Type ; Hash: $article_Hash" \
"$gsl_file_db_post"
}
2022-06-14 18:51:19 +02:00
2022-03-01 18:39:46 +01:00
#======================================================================
2022-06-14 18:51:19 +02:00
# Set Post Statuses (chk, wip, www) in Database according to proceess
2022-03-01 18:39:46 +01:00
#======================================================================
2022-06-14 18:51:19 +02:00
DB__set_status() {
2022-03-27 18:46:48 +02:00
case "$1" in
2022-03-05 18:06:48 +01:00
chk)
2022-06-14 18:51:19 +02:00
article_Status_chk="article_Status_chk=$article_Hash"
! [[ $article_Status_wip ]] \
&& article_Status_wip="article_Status_wip=0" \
|| article_Status_wip="article_Status_wip=$article_Status_wip"
! [[ $article_Status_www ]] \
&& article_Status_www="article_Status_www=0" \
|| article_Status_www="article_Status_www=$article_Status_www"
DB__create_datas
DB__create_sum
2022-03-01 18:39:46 +01:00
;;
2022-06-14 18:51:19 +02:00
2022-03-05 18:06:48 +01:00
wip)
2022-06-14 18:51:19 +02:00
sed -i "s/article_Status_wip=.*/article_Status_wip=$article_Hash/" \
"$gsl_file_db_post"
DB__create_sum
2022-03-27 18:46:48 +02:00
;;
2022-06-14 18:51:19 +02:00
wip-del)
sed -i "s/article_Status_wip=.*/article_Status_wip=0/" \
"$gsl_file_db_post"
DB__create_sum
;;
2022-03-27 18:46:48 +02:00
www)
2022-06-14 18:51:19 +02:00
sed -i "s/article_Status_www=.*/article_Status_www=$article_Hash/" \
"$gsl_file_db_post"
DB__create_sum
;;
www-del)
sed -i "s/article_Status_www=.*/article_Status_www=0/" \
"$gsl_file_db_post"
DB__create_sum
2022-03-05 18:06:48 +01:00
;;
2022-03-01 18:39:46 +01:00
esac
}
2022-02-17 17:21:35 +01:00
2022-06-14 18:51:19 +02:00
2022-03-01 18:39:46 +01:00
#======================================================================
2022-06-14 18:51:19 +02:00
# Create DB File for this article
2022-03-01 18:39:46 +01:00
#======================================================================
2022-06-14 18:51:19 +02:00
DB__create_datas() {
! [[ -d "$gsl_dir_db_domain" ]] \
&& mkdir -p "$gsl_dir_db_domain"
2022-03-02 17:25:23 +01:00
2022-06-14 18:51:19 +02:00
[[ -f "$gsl_file_db_post" ]] \
&& rm -f "$gsl_file_db_post"
rm -f "$gsl_file_db_post_hash."*
2022-03-01 18:39:46 +01:00
touch "$gsl_file_db_post"
2022-02-27 19:16:16 +01:00
2022-03-01 18:39:46 +01:00
# Main Print
2022-06-14 18:51:19 +02:00
cat << EODB > "$gsl_file_db_post"
# File
article_domain="$domain_name"
article_URI="${PWD}/$gsl_post"
$article_Status_chk
$article_Status_wip
$article_Status_www
article_epoch=$date_epoch
# Article
article_Errors="$article_Errors"
article_Type=$gsl_post_type
article_CSS="$gsl_post_css"
article_Date="$gsl_post_date"
article_Title="$gsl_post_title"
article_Info="$gsl_post_info"
article_Slug="$gsl_post_slug"
article_Author="$gsl_post_author"
article_Tags="$gsl_post_tags"
# Import
$(cat "$gsl_tmp_db")
# Stats
stat_Titles=$gsl_stat_titles
stat_Tags=$gsl_stat_tags
stat_Words=$gsl_stat_words
stat_Paragraphs=$gsl_stat_p
stat_Links=$gsl_stat_links
stat_Links_Online=$gsl_stat_links_online
stat_ABBRS=$gsl_stat_abbrs
stat_Strongs=$gsl_stat_strongs
stat_Bolds=$gsl_stat_bolds
stat_Emphasis=$gsl_stat_italics
stat_Strikes=$gsl_stat_strikes
2022-06-28 22:56:48 +02:00
stat_Dels=$gsl_stat_dels
2022-06-14 18:51:19 +02:00
stat_Icodes=$gsl_stat_icodes
stat_Lists=$gsl_stat_lists
stat_Lists_Items=$gsl_list_items
stat_Quotes=$gsl_stat_bq
stat_Images=$gsl_stat_images
stat_max_Images=$gsl_total_images
stat_Flinks=$gsl_stat_flinks
stat_Fcodes=$gsl_stat_fcodes
stat_max_Fcodes=$gsl_total_fcodes
stat_Fbruts=$gsl_stat_fbruts
stat_max_Fbruts=$gsl_total_fbruts
EODB
}
#======================================================================
# Create DB File.HASH for this article (avoid corruption)
#======================================================================
DB__create_sum() {
if [[ -f "$gsl_file_db_post" ]];then
Hash_DB=`cksum "$gsl_file_db_post" | awk '{print $1}'`
rm -f "$gsl_file_db_post_hash."*
touch "$gsl_file_db_post_hash.$Hash_DB"
source "$gsl_file_db_post"
DB__create_log "$1"
fi
}