186 lines
4.8 KiB
Bash
186 lines
4.8 KiB
Bash
#!/bin/bash
|
|
# file: gsl__post_manager
|
|
# Folder: /var/lib/gsl/scripts
|
|
# By echolib
|
|
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
|
|
|
#-----------------------------------------------------------------------
|
|
# -----------------------------------------------------------
|
|
# MAIN LOOP. Read from Post list. Do according to Post Status
|
|
# -----------------------------------------------------------
|
|
#-----------------------------------------------------------------------
|
|
gsl__loop_posts() {
|
|
gsl__logs_print \
|
|
"$gsl_log_i" \
|
|
"Found" \
|
|
"Posts" \
|
|
"$gsl_nbr_posts" \
|
|
"${PWD}"
|
|
|
|
for gsl_post in `ls -1 *.gsl 2>/dev/null`
|
|
do
|
|
# Check specific asked Post
|
|
if [[ "$gsl_this_post" ]];then
|
|
! [[ "$gsl_post" == "$gsl_this_post" ]] && continue
|
|
fi
|
|
|
|
# Post too small
|
|
gsl__post_hash_size
|
|
if (( "$gsl_post_size" <= $gsl_post_min_size ));then
|
|
gsl__logs_print \
|
|
"$gsl_log_e" \
|
|
"Post" \
|
|
"Size" \
|
|
"$gsl_post - Too small $gsl_post_size <= $gsl_post_min_size" \
|
|
"${PWD}/$gsl_post"
|
|
continue
|
|
fi
|
|
|
|
# From COMMAND [OPT]
|
|
case "$1" in
|
|
check)
|
|
if ! [[ "$gsl_force_check" ]];then
|
|
gsl__post_compare_hash || continue
|
|
fi
|
|
|
|
gsl__logs_print \
|
|
"$gsl_log_i" \
|
|
"Reading" \
|
|
"Post" \
|
|
"$gsl_post" \
|
|
"${PWD}"
|
|
gsl_process="Checked"
|
|
gsl__all_checkers
|
|
;;
|
|
|
|
make)
|
|
gsl_process="Made"
|
|
gsl__db_exists "$gsl_file_db_posts"
|
|
case "$gsl_db_post_status" in
|
|
Checked)
|
|
gsl__post_compare_hash || continue
|
|
gsl__all_makers
|
|
;;
|
|
|
|
Made)
|
|
gsl__logs_print
|
|
"$gsl_log_w" \
|
|
"Post" \
|
|
"Make" \
|
|
"$gsl_post already Converted" \
|
|
"$gsl_file_db_posts"
|
|
continue
|
|
;;
|
|
esac
|
|
;;
|
|
esac
|
|
done
|
|
|
|
[[ "$gsl_checker_war" ]] \
|
|
&& gsl log -s -w
|
|
|
|
[[ "$gsl_checker_err" ]] \
|
|
&& gsl log -s -e
|
|
|
|
[[ "$gsl_check_done" ]] \
|
|
&& echo "# Check already done"
|
|
}
|
|
|
|
#-----------------------------------------------------------------------
|
|
# --------------------
|
|
# Doing some checkings
|
|
# --------------------
|
|
#-----------------------------------------------------------------------
|
|
|
|
#=======================================================================
|
|
# Check NAME post from [OPT] ; should be from autocompletion
|
|
#=======================================================================
|
|
gsl__check_opt_post() {
|
|
[[ `ls -1 *.gsl | grep "$1"` ]] \
|
|
&& gsl_this_post="$1"
|
|
}
|
|
|
|
#=======================================================================
|
|
# Check if posts from PWD folder
|
|
#=======================================================================
|
|
gsl__check_nbr_posts() {
|
|
gsl_nbr_posts=`ls -1 *.gsl 2>/dev/null | wc -l`
|
|
|
|
! (( $gsl_nbr_posts >= 1 )) \
|
|
&& echo "! No Posts found with .gsl extension" \
|
|
&& exit 1
|
|
}
|
|
|
|
#======================================================================
|
|
# Check if Post has same Hash
|
|
#======================================================================
|
|
gsl__post_compare_hash() {
|
|
gsl__db_post_hash
|
|
|
|
case "$gsl_process" in
|
|
Checked)
|
|
if [[ "$gsl_db_post_hash" == "$gsl_post_hash" ]];then
|
|
gsl__logs_print \
|
|
"$gsl_log_i" \
|
|
"Post" \
|
|
"Hash" \
|
|
"$gsl_post already Checked from $gsl_post_hash" \
|
|
"$gsl_file_db_posts"
|
|
gsl_check_done=true
|
|
return 1
|
|
fi
|
|
;;
|
|
|
|
Made)
|
|
if ! [[ "$gsl_db_post_hash" == "$gsl_post_hash" ]];then
|
|
gsl__logs_print \
|
|
"$gsl_log_e" \
|
|
"Post" \
|
|
"Hash" \
|
|
"$gsl_post has changed. Check it again" \
|
|
"$gsl_file_db_posts"
|
|
unset gsl_check_done
|
|
gsl_checker_err=true
|
|
return 1
|
|
fi
|
|
|
|
# Compare external content hash
|
|
while read "gsl_content_filename"
|
|
do
|
|
#unset gsl_db_file_hash gsl_file_hash
|
|
! [[ "$gsl_content_filename" ]] && continue
|
|
gsl_db_file_hash=`
|
|
grep "$gsl_content_filename" "$gsl_file_db_files" \
|
|
| awk -F: '{print $2}'`
|
|
gsl_file_hash=`
|
|
cksum "$gsl_dir_domain_files/$gsl_content_filename" \
|
|
| awk '{print $1}'`
|
|
|
|
if ! [[ "$gsl_db_file_hash" == "$gsl_file_hash" ]];then
|
|
gsl__logs_print \
|
|
"$gsl_log_w" \
|
|
"File" \
|
|
"Hash" \
|
|
"$gsl_content_filename has changed. $gsl_db_file_hash $gsl_file_hash" \
|
|
"$gsl_file_db_files"
|
|
gsl_checker_war=true
|
|
return 1
|
|
fi
|
|
done < <(grep "$gsl_post" "$gsl_file_db_posts" \
|
|
| awk -F"|" \
|
|
'{for(i=7;i<=NF;i++){print $i}}')
|
|
;;
|
|
esac
|
|
}
|
|
|
|
#======================================================================
|
|
# Create TMP file > Get Content Post Only (after #1)
|
|
#======================================================================
|
|
gsl__post_content_only() {
|
|
gsl_tmp_post=`mktemp`
|
|
awk -v l="$gsl_post_begin" \
|
|
'NR >= l' \
|
|
"$gsl_post" \
|
|
> "$gsl_tmp_post"
|
|
}
|