2022-02-13 17:58:25 +01:00
|
|
|
#!/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 FROM DB posts.db
|
|
|
|
#=======================================================================
|
|
|
|
gsl__db_post_hash() {
|
|
|
|
gsl_db_post_hash=`
|
2022-02-14 02:57:58 +01:00
|
|
|
grep "$gsl_post" \
|
|
|
|
"$gsl_file_db_posts" \
|
2022-02-13 17:58:25 +01:00
|
|
|
| awk -F"|" '{print $3}'`
|
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
|
|
|
# Check Post exists and get line NBR in DB
|
|
|
|
#=======================================================================
|
|
|
|
gsl__db_post_exists() {
|
|
|
|
gsl_db_post_exists=`grep -n "$gsl_post" "$1"`
|
|
|
|
gsl_db_post_line_nbr=`awk -F":" '{print $1}' <<< "$gsl_db_post_exists"`
|
|
|
|
gsl_db_post_status=`awk -F"|" '{print $4}' <<< "$gsl_db_post_exists"`
|
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
|
|
|
# From gsl__loop_posts: Write DB
|
|
|
|
#=======================================================================
|
|
|
|
gsl__db_line_post() {
|
|
|
|
case "$gsl_process" in
|
2022-02-14 02:57:58 +01:00
|
|
|
Checked)
|
|
|
|
gsl_db_line=`
|
|
|
|
printf '%s%s%s%s%s\n' \
|
2022-02-17 11:03:25 +01:00
|
|
|
"$gsl_post_type|" \
|
2022-02-14 02:57:58 +01:00
|
|
|
"$gsl_post|" \
|
|
|
|
"$gsl_post_hash|" \
|
|
|
|
"$gsl_post_size|" \
|
|
|
|
"$gsl_process|"`
|
|
|
|
|
|
|
|
# case if post exists in DB posts.db ?
|
|
|
|
gsl__db_post_exists "$gsl_file_db_posts"
|
|
|
|
|
|
|
|
if [[ "$gsl_db_post_exists" ]];then
|
|
|
|
sed -i "${gsl_db_post_line_nbr}s/.*/$gsl_db_line/" \
|
|
|
|
"$gsl_file_db_posts" && \
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_w" \
|
|
|
|
"DB" \
|
|
|
|
"Post" \
|
|
|
|
"$gsl_post - Replaced Hash: $gsl_post_hash" \
|
|
|
|
"$gsl_file_db_posts"
|
|
|
|
gsl_checker_war=true
|
|
|
|
|
|
|
|
else
|
|
|
|
echo "$gsl_db_line" \
|
|
|
|
>> "$gsl_file_db_posts" && \
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_i" \
|
|
|
|
"DB" \
|
|
|
|
"Post" \
|
|
|
|
"$gsl_post - New Line. Hash: $gsl_post_hash" \
|
|
|
|
"$gsl_file_db_posts"
|
|
|
|
fi
|
|
|
|
;;
|
2022-02-13 17:58:25 +01:00
|
|
|
esac
|
|
|
|
}
|