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

190 lines
4.7 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" \
"Posts" \
"Found" \
"$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
gsl__get_sum "$gsl_post"
# Post too small
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
# Set DB Post file
gsl_file_db_post="$gsl_dir_db/$gsl_post.db"
gsl__db_get_post_datas
gsl__db_compare_post_hash
# From COMMAND [OPT]
case "$1" in
check)
gsl_process="chk"
if ! [[ "$gsl_force_check" ]];then
! [[ "$gsl_post_new_hash" ]] && continue
fi
gsl__logs_print \
"$gsl_log_i" \
"Reading" \
"Post" \
"$gsl_post" \
"${PWD}"
gsl__all_checkers
;;
make)
gsl_process="wip"
gsl__post_begin
gsl__get_needed_headers
gsl__page_prepare_datas
# echo "D> $gsl_this_conf_domain/$gsl_find_domain.conf"
case "$gsl_db_post_status" in
chk)
gsl__all_makers
;;
wip)
# Should not be used...
[[ "$gsl_force_make" ]] \
&& gsl__all_makers \
&& continue
if [[ "$gsl_post_new_hash" ]];then
rm -f "$gsl_srv_wip_page" && \
gsl__logs_print \
"$gsl_log_w" \
"wip" \
"Delete" \
"file ; changes in $gsl_post" \
"$gsl_srv_wip_page"
rm -f "$gsl_file_db_post" && \
gsl__logs_print \
"$gsl_log_w" \
"DB" \
"Delete" \
"file ; changes in $gsl_post" \
"$gsl_file_db_post"
else
gsl__logs_print \
"$gsl_log_w" \
"Post" \
"Make" \
"$gsl_post already Converted" \
"$gsl_file_db_posts"
gsl_checker_war=true
continue
fi
;;
esac
;;
post-list)
case "$gsl_db_post_status" in
wip|online)
gsl_process="wip"
gsl__post_begin
gsl__get_needed_headers
gsl__page_prepare_datas
gsl__page_create_listing selected
;;
*)
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"Status" \
"$gsl_db_post_status: $gsl_post not Converted" \
"$gsl_file_db_posts"
gsl_checker_err=true
;;
esac
;;
esac
done
# End of checkers : show logs for war and err
[[ "$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() {
if [[ `ls -1 *.gsl | grep "$1"` ]];then
gsl_this_post="$1"
else
echo "! $1 Not Found"
exit
fi
}
#=======================================================================
# 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
}
#======================================================================
# 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"
}
gsl__post_begin() {
gsl_post_begin=`
grep -n "#1" $gsl_post \
| head -1 \
| awk -F: '{print $1}'`
}