2022-02-13 17:58:25 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# file: gsl__post_manager
|
|
|
|
# Folder: /var/lib/gsl/scripts
|
|
|
|
# By echolib
|
|
|
|
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
|
|
|
|
2022-02-21 17:25:08 +01:00
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
# -----------------------------------------------------------
|
|
|
|
# MAIN LOOP. Read from Post list. Do according to Post Status
|
|
|
|
# -----------------------------------------------------------
|
|
|
|
#-----------------------------------------------------------------------
|
2022-02-13 17:58:25 +01:00
|
|
|
gsl__loop_posts() {
|
2022-04-14 14:14:42 +02:00
|
|
|
gsl__check_nbr_posts
|
|
|
|
(( $gsl_nbr_posts == 0 )) \
|
|
|
|
&& gsl__logs_print \
|
|
|
|
"$gsl_log_i" \
|
|
|
|
"Posts" \
|
|
|
|
"Not found" \
|
|
|
|
"$gsl_nbr_posts post. Nothing to do in" \
|
|
|
|
"${PWD}" \
|
|
|
|
&& return
|
|
|
|
|
2022-02-19 18:17:09 +01:00
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_i" \
|
|
|
|
"Posts" \
|
2022-03-06 01:47:58 +01:00
|
|
|
"Found" \
|
2022-04-13 12:24:39 +02:00
|
|
|
"$gsl_nbr_posts posts in" \
|
2022-02-19 18:17:09 +01:00
|
|
|
"${PWD}"
|
|
|
|
|
2022-02-13 17:58:25 +01:00
|
|
|
for gsl_post in `ls -1 *.gsl 2>/dev/null`
|
|
|
|
do
|
2022-03-01 18:39:46 +01:00
|
|
|
|
2022-02-16 16:57:20 +01:00
|
|
|
# Check specific asked Post
|
|
|
|
if [[ "$gsl_this_post" ]];then
|
2022-03-27 18:46:48 +02:00
|
|
|
! [[ "$gsl_post" == "$gsl_this_post" ]] \
|
|
|
|
&& continue
|
2022-02-16 16:57:20 +01:00
|
|
|
fi
|
2022-03-02 17:25:23 +01:00
|
|
|
|
2022-03-01 18:39:46 +01:00
|
|
|
gsl__get_sum "$gsl_post"
|
2022-03-02 17:25:23 +01:00
|
|
|
|
2022-02-14 02:57:58 +01:00
|
|
|
# Post too small
|
|
|
|
if (( "$gsl_post_size" <= $gsl_post_min_size ));then
|
|
|
|
gsl__logs_print \
|
2022-03-10 14:47:00 +01:00
|
|
|
"$gsl_log_w" \
|
2022-02-14 02:57:58 +01:00
|
|
|
"Post" \
|
|
|
|
"Size" \
|
2022-02-27 19:16:16 +01:00
|
|
|
"$gsl_post - Too small $gsl_post_size <= $gsl_post_min_size" \
|
2022-02-14 02:57:58 +01:00
|
|
|
"${PWD}/$gsl_post"
|
2022-03-10 14:47:00 +01:00
|
|
|
gsl_checker_war=true
|
2022-02-14 02:57:58 +01:00
|
|
|
continue
|
|
|
|
fi
|
2022-03-02 17:25:23 +01:00
|
|
|
|
2022-03-01 18:39:46 +01:00
|
|
|
# Set DB Post file
|
|
|
|
gsl_file_db_post="$gsl_dir_db/$gsl_post.db"
|
2022-03-27 18:46:48 +02:00
|
|
|
gsl__db_get_post_datas "$1"
|
2022-03-06 01:47:58 +01:00
|
|
|
gsl__db_compare_post_hash
|
2022-03-29 10:33:52 +02:00
|
|
|
|
|
|
|
gsl__post_begin
|
|
|
|
gsl__get_needed_headers
|
|
|
|
gsl__page_prepare_datas
|
|
|
|
|
|
|
|
if [[ "$gsl_post_new_hash" ]];then
|
|
|
|
unset gsl_db_post_status
|
|
|
|
if [[ -f "$gsl_srv_wip_page" ]];then
|
|
|
|
rm -f "$gsl_srv_wip_page" && \
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_w" \
|
|
|
|
"wip" \
|
|
|
|
"Delete" \
|
2022-04-14 14:14:42 +02:00
|
|
|
"$gsl_post_type ; $gsl_post has changed !" \
|
2022-03-29 10:33:52 +02:00
|
|
|
"$gsl_srv_wip_page"
|
2022-04-14 14:14:42 +02:00
|
|
|
gsl_checker_war=true
|
2022-04-11 18:06:38 +02:00
|
|
|
fi
|
|
|
|
|
2022-03-29 10:33:52 +02:00
|
|
|
if [[ -f "$gsl_file_db_post" ]];then
|
|
|
|
rm -f "$gsl_file_db_post" && \
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_w" \
|
|
|
|
"DB" \
|
|
|
|
"Delete" \
|
2022-04-14 14:14:42 +02:00
|
|
|
"file ; $gsl_post has changed !" \
|
2022-03-29 10:33:52 +02:00
|
|
|
"$gsl_file_db_post"
|
2022-04-14 14:14:42 +02:00
|
|
|
gsl_checker_war=true
|
2022-03-29 10:33:52 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-02-21 17:25:08 +01:00
|
|
|
# From COMMAND [OPT]
|
2022-02-14 02:57:58 +01:00
|
|
|
case "$1" in
|
|
|
|
check)
|
|
|
|
if ! [[ "$gsl_force_check" ]];then
|
2022-03-05 18:06:48 +01:00
|
|
|
! [[ "$gsl_post_new_hash" ]] && continue
|
2022-02-14 02:57:58 +01:00
|
|
|
fi
|
|
|
|
|
2022-02-13 17:58:25 +01:00
|
|
|
gsl__logs_print \
|
2022-02-14 02:57:58 +01:00
|
|
|
"$gsl_log_i" \
|
|
|
|
"Reading" \
|
|
|
|
"Post" \
|
|
|
|
"$gsl_post" \
|
|
|
|
"${PWD}"
|
2022-02-21 17:25:08 +01:00
|
|
|
gsl__all_checkers
|
2022-02-14 02:57:58 +01:00
|
|
|
;;
|
2022-03-02 17:25:23 +01:00
|
|
|
|
2022-03-06 01:47:58 +01:00
|
|
|
make)
|
|
|
|
case "$gsl_db_post_status" in
|
|
|
|
chk)
|
2022-03-02 17:25:23 +01:00
|
|
|
gsl__all_makers
|
2022-03-06 01:47:58 +01:00
|
|
|
;;
|
|
|
|
|
2022-03-27 18:46:48 +02:00
|
|
|
*)
|
2022-03-29 10:33:52 +02:00
|
|
|
if ! [[ "$gsl_post_new_hash" ]];then
|
2022-03-08 17:53:40 +01:00
|
|
|
# Should not be used...
|
|
|
|
[[ "$gsl_force_make" ]] \
|
|
|
|
&& gsl__all_makers \
|
|
|
|
&& continue
|
|
|
|
|
2022-03-27 18:46:48 +02:00
|
|
|
if [[ -f "$gsl_srv_wip_page" ]];then
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_w" \
|
|
|
|
"Post" \
|
|
|
|
"Make" \
|
|
|
|
"$gsl_post already Converted" \
|
|
|
|
"$gsl_file_db_posts"
|
|
|
|
gsl_checker_war=true
|
|
|
|
continue
|
|
|
|
fi
|
2022-03-06 01:47:58 +01:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2022-03-08 17:53:40 +01:00
|
|
|
|
2022-04-14 14:14:42 +02:00
|
|
|
listing)
|
|
|
|
# Continue if post changed
|
|
|
|
[[ "$gsl_post_new_hash" ]] \
|
|
|
|
&& gsl__logs_print \
|
|
|
|
"$gsl_log_e" \
|
|
|
|
"Listing" \
|
|
|
|
"$gsl_listing_process" \
|
|
|
|
"file ; $gsl_post has changed !" \
|
|
|
|
"$gsl_file_db_post" \
|
|
|
|
&& continue
|
|
|
|
|
|
|
|
case "$gsl_listing_process" in
|
|
|
|
add)
|
|
|
|
echo "> Add $gsl_this_post to listing"
|
|
|
|
;;
|
|
|
|
|
|
|
|
rem)
|
|
|
|
echo "> Remove $gsl_this_post to listing"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
|
2022-03-06 15:57:20 +01:00
|
|
|
post-list)
|
|
|
|
case "$gsl_db_post_status" in
|
2022-03-27 18:46:48 +02:00
|
|
|
wip|www)
|
2022-03-06 15:57:20 +01:00
|
|
|
gsl_process="wip"
|
|
|
|
gsl__post_begin
|
|
|
|
gsl__get_needed_headers
|
|
|
|
gsl__page_prepare_datas
|
2022-03-10 14:47:00 +01:00
|
|
|
gsl__page_listing_create "$gsl_post_list"
|
2022-03-06 15:57:20 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
gsl__logs_print \
|
2022-03-12 16:59:45 +01:00
|
|
|
"$gsl_log_e" \
|
|
|
|
"Post" \
|
|
|
|
"Status" \
|
|
|
|
"$gsl_db_post_status: $gsl_post not Converted" \
|
|
|
|
"$gsl_file_db_posts"
|
|
|
|
gsl_checker_err=true
|
2022-03-06 15:57:20 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2022-03-27 18:46:48 +02:00
|
|
|
|
|
|
|
www)
|
|
|
|
gsl_checker_war=true
|
|
|
|
case "$2" in
|
|
|
|
add)
|
|
|
|
case "$gsl_db_post_status" in
|
2022-03-29 10:33:52 +02:00
|
|
|
wip|www)
|
2022-03-27 18:46:48 +02:00
|
|
|
rsync -a --delete \
|
|
|
|
"$gsl_srv_wip_page" "$gsl_srv_www_page" && \
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_w" \
|
|
|
|
"SRV" \
|
|
|
|
"www" \
|
|
|
|
"Synced: $gsl_post_type $gsl_post" \
|
|
|
|
"$gsl_srv_www_page"
|
|
|
|
gsl__db_set_post_status www
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
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
|
|
|
|
;;
|
|
|
|
remove)
|
|
|
|
case "$gsl_post_type" in
|
|
|
|
post)
|
|
|
|
! [[ -d "$gsl_srv_www_page" ]] \
|
|
|
|
&& return
|
|
|
|
gsl_rm_c="rm -rf"
|
|
|
|
;;
|
|
|
|
page)
|
|
|
|
! [[ -f "$gsl_srv_www_page" ]] \
|
|
|
|
&& return
|
|
|
|
gsl_rm_c="rm -f"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
$gsl_rm_c "$gsl_srv_www_page" && \
|
|
|
|
gsl__logs_print \
|
|
|
|
"$gsl_log_w" \
|
|
|
|
"SRV" \
|
|
|
|
"www" \
|
|
|
|
"REMOVED $gsl_post_type $gsl_post" \
|
|
|
|
"$gsl_srv_www_page"
|
|
|
|
gsl__db_set_post_status wip
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2022-02-14 02:57:58 +01:00
|
|
|
esac
|
2022-02-13 17:58:25 +01:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-02-21 17:25:08 +01:00
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
# --------------------
|
|
|
|
# Doing some checkings
|
|
|
|
# --------------------
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
|
2022-02-13 17:58:25 +01:00
|
|
|
#=======================================================================
|
2022-02-21 17:25:08 +01:00
|
|
|
# Check NAME post from [OPT] ; should be from autocompletion
|
2022-02-13 17:58:25 +01:00
|
|
|
#=======================================================================
|
2022-02-21 17:25:08 +01:00
|
|
|
gsl__check_opt_post() {
|
2022-03-06 15:57:20 +01:00
|
|
|
if [[ `ls -1 *.gsl | grep "$1"` ]];then
|
|
|
|
gsl_this_post="$1"
|
|
|
|
else
|
|
|
|
echo "! $1 Not Found"
|
|
|
|
exit
|
|
|
|
fi
|
2022-02-21 17:25:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#=======================================================================
|
|
|
|
# Check if posts from PWD folder
|
|
|
|
#=======================================================================
|
|
|
|
gsl__check_nbr_posts() {
|
|
|
|
gsl_nbr_posts=`ls -1 *.gsl 2>/dev/null | wc -l`
|
|
|
|
|
2022-04-11 18:06:38 +02:00
|
|
|
(( $gsl_nbr_posts == 0 )) \
|
2022-02-21 17:25:08 +01:00
|
|
|
&& echo "! No Posts found with .gsl extension" \
|
2022-04-11 18:06:38 +02:00
|
|
|
&& exit
|
2022-02-13 17:58:25 +01:00
|
|
|
}
|
|
|
|
|
2022-03-01 12:39:16 +01:00
|
|
|
#======================================================================
|
|
|
|
# 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"
|
2022-02-15 12:42:54 +01:00
|
|
|
}
|
2022-03-06 01:47:58 +01:00
|
|
|
|
|
|
|
gsl__post_begin() {
|
|
|
|
gsl_post_begin=`
|
2022-03-08 17:53:40 +01:00
|
|
|
awk -v m="#1" \
|
|
|
|
'$1 == m {print NR;exit}' \
|
|
|
|
"$gsl_post"`
|
2022-03-06 01:47:58 +01:00
|
|
|
}
|