180 lines
4.2 KiB
Bash
180 lines
4.2 KiB
Bash
#!/bin/bash
|
|
# file: gsl__db_manager
|
|
# Folder: /var/lib/gsl/scripts
|
|
# By echolib
|
|
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
|
|
|
|
|
#======================================================================
|
|
# Get Post Hash & Status From Database
|
|
#======================================================================
|
|
gsl__db_get_post_datas() {
|
|
gsl_db_post_hash=0
|
|
|
|
if [[ -f "$gsl_file_db_post" ]];then
|
|
|
|
gsl_db_post_hash=`
|
|
awk -F: 'NR == 1 {print $3}' \
|
|
"$gsl_file_db_post"`
|
|
|
|
! [[ "$gsl_db_post_hash" ]] \
|
|
&& gsl_db_post_hash=0
|
|
|
|
gsl_db_post_status=`
|
|
awk -F: 'NR == 2 {print $2}' \
|
|
"$gsl_file_db_post"`
|
|
|
|
else
|
|
|
|
case "$gsl_process" in
|
|
chk)
|
|
true
|
|
;;
|
|
*)
|
|
gsl__logs_print \
|
|
"$gsl_log_w" \
|
|
"DB" \
|
|
"Post" \
|
|
"Missing from $gsl_post. Check it first" \
|
|
"$gsl_file_db_post"
|
|
gsl_checker_war=true
|
|
;;
|
|
esac
|
|
fi
|
|
}
|
|
|
|
#======================================================================
|
|
# Get Post Hash and Compare from Database
|
|
#======================================================================
|
|
gsl__db_compare_post_hash() {
|
|
gsl_checker_war=true
|
|
|
|
if (( $gsl_post_hash == $gsl_db_post_hash ));then
|
|
|
|
gsl__logs_print \
|
|
"$gsl_log_w" \
|
|
"Post" \
|
|
"Hash" \
|
|
"$gsl_post checked with hash:$gsl_db_post_hash " \
|
|
"${PWD}/$gsl_post"
|
|
|
|
else
|
|
|
|
gsl_post_new_hash=true
|
|
case "$gsl_db_post_hash" in
|
|
0)
|
|
gsl__logs_print \
|
|
"$gsl_log_w" \
|
|
"Post" \
|
|
"New" \
|
|
"$gsl_post not yet checked" \
|
|
"${PWD}/$gsl_post"
|
|
;;
|
|
*)
|
|
gsl__logs_print \
|
|
"$gsl_log_w" \
|
|
"Post" \
|
|
"Hash" \
|
|
"$gsl_post Changed ($gsl_post_hash)" \
|
|
"${PWD}/$gsl_post"
|
|
;;
|
|
esac
|
|
|
|
fi
|
|
}
|
|
|
|
#======================================================================
|
|
# Set Post Status in Database according to proceess
|
|
#======================================================================
|
|
gsl__db_set_post_status() {
|
|
case "$gsl_process" in
|
|
chk)
|
|
case "$gsl_db_post_status" in
|
|
chk)
|
|
[[ "$gsl_post_new_hash" ]] || return # Do Nothing if same Hash
|
|
gsl__db_create_post
|
|
;;
|
|
wip)
|
|
[[ "$gsl_post_new_hash" ]] || return # Do Nothing if same Hash
|
|
gsl_process="wip"
|
|
gsl__db_create_post
|
|
;;
|
|
www)
|
|
[[ "$gsl_post_new_hash" ]] || return # Do Nothing if same Hash
|
|
gsl_process="www"
|
|
gsl__db_create_post
|
|
;;
|
|
""|=)
|
|
gsl__db_create_post
|
|
;;
|
|
esac
|
|
;;
|
|
wip)
|
|
case "$gsl_db_post_status" in
|
|
chk)
|
|
sed -i "2s/.*/Status:$gsl_process/" "$gsl_file_db_post" && \
|
|
gsl__logs_print \
|
|
"$gsl_log_w" \
|
|
"DB" \
|
|
"Post" \
|
|
"Status:$gsl_process ; $gsl_post" \
|
|
"$gsl_file_db_post"
|
|
gsl_checker_war=true
|
|
;;
|
|
esac
|
|
;;
|
|
esac
|
|
}
|
|
|
|
#======================================================================
|
|
# Create DB File from Data Post
|
|
#======================================================================
|
|
gsl__db_create_post() {
|
|
if [[ "$gsl_checker_err" ]];then
|
|
[[ -f "$gsl_file_db_post" ]] \
|
|
&& rm -f "$gsl_file_db_post" \
|
|
&& gsl__logs_print \
|
|
"$gsl_log_w" \
|
|
"DB" \
|
|
"Delete" \
|
|
"file ; error in $gsl_post" \
|
|
"$gsl_file_db_post"
|
|
return
|
|
fi
|
|
|
|
touch "$gsl_file_db_post"
|
|
|
|
# Main Print
|
|
printf '%s\n%s\n%s\n' \
|
|
"Post:${PWD}/$gsl_post:$gsl_post_hash:$gsl_post_size" \
|
|
"Status:$gsl_process" \
|
|
"`cat "$gsl_db_tmp"`" \
|
|
> "$gsl_file_db_post"
|
|
|
|
# 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" \
|
|
"Create" \
|
|
"Datas from $gsl_post" \
|
|
"$gsl_file_db_post"
|
|
}
|