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

187 lines
4.4 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# file: gsl__db_manager
# Folder: /var/lib/gsl/scripts
# By echolib
# 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
#======================================================================
# Get Post Hash & Status From Database
#======================================================================
gsl__db_get_post_datas() {
2022-03-06 01:47:58 +01:00
gsl_db_post_hash=0
2022-03-01 18:39:46 +01:00
if [[ -f "$gsl_file_db_post" ]];then
gsl_db_post_hash=`
awk -F: 'NR == 1 {print $3}' \
"$gsl_file_db_post"`
2022-03-05 18:06:48 +01:00
! [[ "$gsl_db_post_hash" ]] \
&& gsl_db_post_hash=0
2022-03-01 18:39:46 +01:00
gsl_db_post_status=`
awk -F: 'NR == 2 {print $2}' \
"$gsl_file_db_post"`
2022-02-27 19:16:16 +01:00
2022-03-06 01:47:58 +01:00
else
2022-03-27 18:46:48 +02:00
# if check process, do not show (useless)
case "$1" in
check) true ;;
*)
gsl__logs_print \
"$gsl_log_w" \
"DB" \
"File" \
2022-03-27 18:46:48 +02:00
"Missing for $gsl_post. Check it first" \
"$gsl_file_db_post"
gsl_checker_war=true
;;
esac
2022-02-19 18:17:09 +01:00
fi
}
2022-03-01 18:39:46 +01:00
#======================================================================
# Get Post Hash and Compare from Database
#======================================================================
gsl__db_compare_post_hash() {
2022-03-05 18:06:48 +01:00
gsl_checker_war=true
2022-03-06 01:47:58 +01:00
if (( $gsl_post_hash == $gsl_db_post_hash ));then
2022-03-05 18:06:48 +01:00
gsl__logs_print \
2022-04-14 14:14:42 +02:00
"$gsl_log_i" \
"File" \
2022-03-05 18:06:48 +01:00
"Hash" \
2022-04-14 14:14:42 +02:00
"$gsl_post checked with hash:$gsl_db_post_hash" \
2022-03-05 18:06:48 +01:00
"${PWD}/$gsl_post"
else
gsl_post_new_hash=true
case "$gsl_db_post_hash" in
0)
gsl__logs_print \
"$gsl_log_w" \
"File" \
"New" \
"$gsl_post not yet checked" \
"${PWD}/$gsl_post"
2022-04-14 14:14:42 +02:00
gsl_checker_war=true
;;
*)
2022-04-14 14:14:42 +02:00
gsl__logs_print \
"$gsl_log_w" \
"File" \
2022-04-14 14:14:42 +02:00
"Hash" \
"$gsl_post Changed ($gsl_post_hash) !" \
"${PWD}/$gsl_post"
gsl_checker_war=true
;;
esac
2022-03-05 18:06:48 +01:00
fi
}
2022-03-01 18:39:46 +01:00
#======================================================================
# Set Post Status in Database according to proceess
#======================================================================
gsl__db_set_post_status() {
2022-03-27 18:46:48 +02:00
case "$1" in
2022-03-05 18:06:48 +01:00
chk)
2022-03-01 18:39:46 +01:00
case "$gsl_db_post_status" in
"")
gsl_db_post_status=$1
2022-03-01 18:39:46 +01:00
;;
esac
if ! [[ "$gsl_force_check" ]];then
[[ "$gsl_post_new_hash" ]] || return # Do Nothing if same Hash
fi
gsl__db_create_post "$gsl_db_post_status"
2022-03-01 18:39:46 +01:00
;;
2022-03-27 18:46:48 +02:00
2022-03-05 18:06:48 +01:00
wip)
case "$gsl_db_post_status" in
2022-03-27 18:46:48 +02:00
chk|www)
sed -i "2s/.*/Status:$1/" "$gsl_file_db_post" && \
gsl__logs_print \
"$gsl_log_w" \
"DB" \
"File" \
2022-03-27 18:46:48 +02:00
"Status:$1 ; $gsl_post" \
"$gsl_file_db_post"
gsl_checker_war=true
2022-03-27 18:46:48 +02:00
;;
esac
;;
www)
case "$gsl_db_post_status" in
wip)
sed -i "2s/.*/Status:$1/" "$gsl_file_db_post" && \
2022-03-05 18:06:48 +01:00
gsl__logs_print \
"$gsl_log_w" \
"DB" \
"File" \
2022-03-27 18:46:48 +02:00
"Status:$1 ; $gsl_post" \
2022-03-05 18:06:48 +01:00
"$gsl_file_db_post"
gsl_checker_war=true
2022-03-05 18:06:48 +01:00
;;
esac
;;
2022-03-01 18:39:46 +01:00
esac
}
2022-02-17 17:21:35 +01:00
2022-03-01 18:39:46 +01:00
#======================================================================
# Create DB File from Data Post
#======================================================================
gsl__db_create_post() {
2022-03-02 17:25:23 +01:00
if [[ "$gsl_checker_err" ]];then
[[ -f "$gsl_file_db_post" ]] \
&& rm -f "$gsl_file_db_post" \
&& gsl__logs_print \
"$gsl_log_w" \
"DB" \
"File" \
"Remove ; error in $gsl_post" \
2022-03-02 17:25:23 +01:00
"$gsl_file_db_post"
return
fi
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
printf '%s\n%s\n%s\n' \
"$gsl_post_type:${PWD}/$gsl_post:$gsl_post_hash:$gsl_post_size" \
2022-03-27 18:46:48 +02:00
"Status:$1" \
2022-03-01 18:39:46 +01:00
"`cat "$gsl_db_tmp"`" \
> "$gsl_file_db_post"
2022-02-17 11:28:04 +01:00
2022-03-01 18:39:46 +01:00
# Stats Print
printf '\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n' \
"Stats" \
"Author:$gsl_header_author" \
"Date:$gsl_header_date" \
"Words:$gsl_stat_words" \
"Parag:$gsl_stat_p" \
"Links:$gsl_stat_link:$gsl_stat_links" \
"Strongs:$gsl_stat_strongs" \
"Bolds:$gsl_stat_bolds"\
"Italics:$gsl_stat_italics" \
"Abbrs:$gsl_stat_abbr:$gsl_stat_abbrs" \
"Images:$gsl_stat_image" \
"Files:$gsl_stat_file:$gsl_count_files" \
"Cites:$gsl_stat_bq" \
"ICodes:$gsl_stat_icode" \
"FCodes:$gsl_stat_fcode" \
>> "$gsl_file_db_post"
gsl__logs_print \
"$gsl_log_w" \
"DB" \
"File" \
"Create datas from $gsl_post (status: $1)" \
2022-03-01 18:39:46 +01:00
"$gsl_file_db_post"
}