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

157 lines
4.0 KiB
Bash

#!/bin/bash
# file: gsl__post_manager
# Folder: /var/lib/gsl/scripts
# By echolib (XMPP: im@echolib.re)
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
#======================================================================
# ---------------------------------
# LOOP. Read ALL .gsl files in $PWD
# ---------------------------------
#======================================================================
posts__loop() {
for gsl_post in `ls -1 *.gsl 2>/dev/null`
do
# Do specific asked Post
[[ "$gsl_this_post" ]] && ! [[ "$gsl_post" == "$gsl_this_post" ]] \
&& continue
# Set DB files (here, for newer post)
gsl_file_db_post="$gsl_dir_db_domain/$gsl_post.db"
gsl_file_db_post_hash="$gsl_dir_db_domain/.$gsl_post.db"
# check newer only
[[ $gsl_check_newer ]] && [[ -f "$gsl_file_db_post" ]] \
&& continue
article__sum "$gsl_post" || continue
article__splitter || return
DB__datas "$1"
DB__compare_hash "$1"
[[ "$article_Type" ]] \
&& srv__files datas
# From COMMAND [OPT]
case "$1" in
check) Checkers ;;
make) Makers ;;
www) WWW__OPTIONS "$2" ;;
wip) WIP__remove ;; # wip command is only a remove case || make
esac
# In DB, show logs for server
if [[ "$article_Type" ]];then
if [[ $article_new_hash ]];then
[[ "$old_Type" ]] \
&& log_content="new TYPE" \
|| log_content="new content"
wip__remove "$log_content"
fi
srv__files datas
srv__files logs
fi
unset ${!article_@}
done
# Remove split files
[[ -f "$gsl_tmp_post" ]] && rm -f "$gsl_tmp_post"
[[ -f "$gsl_tmp_head" ]] && rm -f "$gsl_tmp_head"
}
#======================================================================
#---------------------
# Tools for post files
#---------------------
#======================================================================
#======================================================================
# Check if .gsl files
#======================================================================
if__gsl_post() {
gsl_nbr_posts=`ls -1 *.gsl 2>/dev/null | wc -l`
(( $gsl_nbr_posts == 0 )) \
&& echo "! No .gsl file in this folder" \
&& exit
}
#======================================================================
# Get line from first title to split header & content
#======================================================================
article__splitter() {
gsl_post_begin=`
awk -v m="#1" \
'match($1,m) {print NR;exit}' \
"$gsl_post"`
if ! [[ "$gsl_post_begin" ]];then
gsl__logs_print -e -c \
"Begins" \
"Unused: '#1' TITLE" \
"${PWD}/$gsl_post"
return 1
fi
file__header_only
file__post_only
gsl__logs_print -i -g \
"Split" \
"line: $gsl_post_begin ; Header + Content" \
"$gsl_tmp_head + $gsl_tmp_post"
}
#======================================================================
# Create TMP file > Get Headers metas Only (before #1)
#======================================================================
file__header_only() {
gsl_tmp_head=`mktemp`
awk -v l="$gsl_post_begin" \
'NR < l' \
"$gsl_post" \
> "$gsl_tmp_head"
}
#======================================================================
# Create TMP file > Get Content Post Only (after #1)
#======================================================================
file__post_only() {
gsl_tmp_post=`mktemp`
awk -v l="$gsl_post_begin" \
'NR >= l' \
"$gsl_post" \
> "$gsl_tmp_post"
}
#======================================================================
# Get Size & cksum Hash from File... $1: File
#======================================================================
article__sum() {
article_Sum=`cksum "$1"`
article_Hash=`awk '{print $1}' <<< "$article_Sum"`
article_Size=`awk '{print $2}' <<< "$article_Sum"`
case "$gsl_proc" in
create|edit) return ;;
esac
# Post too small ?
if (( "$article_Size" <= $gsl_article_min_Size ));then
gsl__logs_print -w -A -sk \
"Not enough content ($article_Size < $gsl_article_min_Size)" \
"${PWD}/$1"
return 1
fi
gsl__logs_print -i -A -src \
"Hash: $article_Hash ; Size: $article_Size" \
"${PWD}/$1"
}