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}'`
|
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
2022-02-19 18:17:09 +01:00
|
|
|
# From checkers (bcodes,images,files): Write DB
|
2022-02-13 17:58:25 +01:00
|
|
|
#=======================================================================
|
2022-02-19 18:17:09 +01:00
|
|
|
gsl__db_line_file() {
|
2022-02-27 19:16:16 +01:00
|
|
|
gsl__db_exists "$gsl_file_db_files" "$gsl_post_hf_2"
|
|
|
|
gsl_db_line_file="$gsl_post_hf_2:$gsl_file_csum"
|
|
|
|
|
2022-02-19 18:17:09 +01:00
|
|
|
if [[ "$gsl_db_file_hash" ]];then
|
2022-02-27 19:16:16 +01:00
|
|
|
|
2022-02-19 18:17:09 +01:00
|
|
|
sed -i "${gsl_db_file_line_nbr}s,.*,$gsl_db_line_file," \
|
|
|
|
"$gsl_file_db_files"
|
2022-02-27 19:16:16 +01:00
|
|
|
|
2022-02-19 18:17:09 +01:00
|
|
|
else
|
2022-02-27 19:16:16 +01:00
|
|
|
|
|
|
|
echo "$gsl_post_hf_2:$gsl_file_csum" \
|
2022-02-19 18:17:09 +01:00
|
|
|
>> "$gsl_file_db_files"
|
2022-02-27 19:16:16 +01:00
|
|
|
|
2022-02-19 18:17:09 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
#=======================================================================
|
|
|
|
# Check Post exists and get line NBR in DB | $1 DB file $2 TERM
|
|
|
|
#=======================================================================
|
|
|
|
gsl__db_exists() {
|
2022-02-17 17:21:35 +01:00
|
|
|
case "$1" in
|
|
|
|
"$gsl_file_db_posts")
|
|
|
|
gsl_db_post_exists=`
|
|
|
|
grep -n "$gsl_post" "$1"`
|
2022-02-19 18:17:09 +01:00
|
|
|
if [[ "$gsl_db_post_exists" ]];then
|
|
|
|
gsl_db_post_line_nbr=`
|
|
|
|
awk -F":" '{print $1}' <<< "$gsl_db_post_exists"`
|
|
|
|
gsl_db_post_status=`
|
|
|
|
awk -F"|" '{print $5}' <<< "$gsl_db_post_exists"`
|
|
|
|
fi
|
2022-02-17 17:21:35 +01:00
|
|
|
;;
|
|
|
|
"$gsl_file_db_stats")
|
|
|
|
gsl_db_stat_exists=`
|
|
|
|
grep -n "$gsl_post" "$1"`
|
2022-02-19 18:17:09 +01:00
|
|
|
if [[ "$gsl_db_stat_exists" ]];then
|
|
|
|
gsl_db_stat_line_nbr=`
|
|
|
|
awk -F":" '{print $1}' <<< "$gsl_db_stat_exists"`
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"$gsl_file_db_files")
|
|
|
|
gsl_db_file_exists=`grep -n "$2" "$1"`
|
|
|
|
if [[ "$gsl_db_file_exists" ]];then
|
|
|
|
gsl_db_file_line_nbr=`
|
|
|
|
awk -F: '{print $1}' <<< "$gsl_db_file_exists"`
|
|
|
|
gsl_db_file_hash=`
|
|
|
|
awk -F: '{print $3}' <<< "$gsl_db_file_exists"`
|
|
|
|
fi
|
2022-02-17 17:21:35 +01:00
|
|
|
;;
|
|
|
|
esac
|
2022-02-13 17:58:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
|
|
|
# From gsl__loop_posts: Write DB
|
|
|
|
#=======================================================================
|
|
|
|
gsl__db_line_post() {
|
|
|
|
case "$gsl_process" in
|
2022-02-14 02:57:58 +01:00
|
|
|
Checked)
|
2022-02-17 17:21:35 +01:00
|
|
|
#-------------------------------------------------------------------
|
|
|
|
# Check if post exists in DB stats.db and get line
|
|
|
|
#-------------------------------------------------------------------
|
2022-02-19 18:17:09 +01:00
|
|
|
gsl_db_stat_line=`
|
|
|
|
printf '%s%s%s%s%s%s%s%s%s%s\n' \
|
|
|
|
"$gsl_post|" \
|
|
|
|
"$gsl_post_stat_w|" \
|
|
|
|
"$gsl_post_stat_p|" \
|
|
|
|
"$gsl_post_stat_abbr|" \
|
|
|
|
"$gsl_post_stat_link|" \
|
|
|
|
"$gsl_post_stat_image|" \
|
|
|
|
"$gsl_post_stat_file|" \
|
|
|
|
"$gsl_post_stat_bq|" \
|
|
|
|
"$gsl_post_stat_bcode|" \
|
|
|
|
"${gsl_post_stat_mdb// /|}|"`
|
2022-02-17 17:21:35 +01:00
|
|
|
|
2022-02-19 18:17:09 +01:00
|
|
|
if ! [[ "$gsl_checker_err" ]];then
|
|
|
|
gsl__db_exists "$gsl_file_db_stats"
|
2022-02-17 17:21:35 +01:00
|
|
|
if [[ "$gsl_db_stat_line_nbr" ]];then
|
2022-02-19 18:17:09 +01:00
|
|
|
sed -i "${gsl_db_stat_line_nbr}s,.*,$gsl_db_stat_line," \
|
2022-02-17 17:21:35 +01:00
|
|
|
"$gsl_file_db_stats" && \
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_w" \
|
|
|
|
"DB" \
|
|
|
|
"Stat" \
|
|
|
|
"Line:$gsl_db_stat_line_nbr $gsl_post" \
|
|
|
|
"$gsl_file_db_stats"
|
|
|
|
else
|
|
|
|
echo "$gsl_db_stat_line" >> "$gsl_file_db_stats" && \
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_w" \
|
|
|
|
"DB" \
|
|
|
|
"Stat" \
|
|
|
|
"Line:NEW $gsl_db_stat_line" \
|
|
|
|
"$gsl_file_db_stats"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------
|
2022-02-17 11:28:04 +01:00
|
|
|
# Check if post exists in DB posts.db and get line / status
|
2022-02-17 17:21:35 +01:00
|
|
|
#-------------------------------------------------------------------
|
2022-02-19 18:17:09 +01:00
|
|
|
gsl__db_exists "$gsl_file_db_posts"
|
|
|
|
if [[ "$gsl_checker_err" ]] && [[ "$gsl_db_post_line_nbr" ]];then
|
2022-02-27 19:16:16 +01:00
|
|
|
sed -i "${gsl_db_post_line_nbr}d" "$gsl_file_db_posts" && \
|
2022-02-19 18:17:09 +01:00
|
|
|
gsl__logs_print \
|
2022-02-17 11:28:04 +01:00
|
|
|
"$gsl_log_w" \
|
|
|
|
"DB" \
|
|
|
|
"Post" \
|
|
|
|
"Line:$gsl_db_post_line_nbr removed. Error in $gsl_post" \
|
2022-02-19 18:17:09 +01:00
|
|
|
"$gsl_file_db_posts"
|
|
|
|
return
|
|
|
|
fi
|
2022-02-27 19:16:16 +01:00
|
|
|
|
2022-02-17 17:21:35 +01:00
|
|
|
gsl_db_post_line=`
|
2022-02-19 18:17:09 +01:00
|
|
|
printf '%s%s%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|" \
|
2022-02-19 18:17:09 +01:00
|
|
|
"$gsl_process|" \
|
|
|
|
"${PWD}/$gsl_post|"\
|
|
|
|
"$gsl_db_post_files"`
|
2022-02-17 11:28:04 +01:00
|
|
|
|
2022-02-14 02:57:58 +01:00
|
|
|
if [[ "$gsl_db_post_exists" ]];then
|
2022-02-19 18:17:09 +01:00
|
|
|
sed -i "${gsl_db_post_line_nbr}s,.*,$gsl_db_post_line," \
|
2022-02-14 02:57:58 +01:00
|
|
|
"$gsl_file_db_posts" && \
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_w" \
|
|
|
|
"DB" \
|
|
|
|
"Post" \
|
2022-02-17 11:28:04 +01:00
|
|
|
"Line:REPLACED - $gsl_post - Hash: $gsl_post_hash" \
|
2022-02-14 02:57:58 +01:00
|
|
|
"$gsl_file_db_posts"
|
|
|
|
gsl_checker_war=true
|
|
|
|
|
|
|
|
else
|
2022-02-17 17:21:35 +01:00
|
|
|
echo "$gsl_db_post_line" \
|
2022-02-14 02:57:58 +01:00
|
|
|
>> "$gsl_file_db_posts" && \
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_i" \
|
|
|
|
"DB" \
|
|
|
|
"Post" \
|
2022-02-17 11:28:04 +01:00
|
|
|
"Line:NEW - $gsl_post - Hash: $gsl_post_hash" \
|
2022-02-14 02:57:58 +01:00
|
|
|
"$gsl_file_db_posts"
|
|
|
|
fi
|
|
|
|
;;
|
2022-02-13 17:58:25 +01:00
|
|
|
esac
|
|
|
|
}
|