2022-02-13 17:58:25 +01:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
# file: gsl__post_manager
|
|
|
|
|
# Folder: /var/lib/gsl/scripts
|
2022-06-14 18:51:19 +02:00
|
|
|
|
# By echolib (XMPP: im@echolib.re)
|
2022-02-13 17:58:25 +01:00
|
|
|
|
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
|
|
|
|
|
2022-02-19 18:17:09 +01:00
|
|
|
|
|
2022-06-14 18:51:19 +02:00
|
|
|
|
#======================================================================
|
|
|
|
|
# ---------------------------------
|
|
|
|
|
# LOOP. Read ALL .gsl files in $PWD
|
|
|
|
|
# ---------------------------------
|
|
|
|
|
#======================================================================
|
|
|
|
|
posts__loop() {
|
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-06-14 18:51:19 +02:00
|
|
|
|
# Do specific asked Post
|
|
|
|
|
[[ "$gsl_this_post" ]] && ! [[ "$gsl_post" == "$gsl_this_post" ]] \
|
|
|
|
|
&& continue
|
2022-03-02 17:25:23 +01:00
|
|
|
|
|
2022-06-14 18:51:19 +02:00
|
|
|
|
# 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"
|
2022-03-02 17:25:23 +01:00
|
|
|
|
|
2022-06-14 18:51:19 +02:00
|
|
|
|
# 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
|
2022-03-29 10:33:52 +02:00
|
|
|
|
|
2022-02-21 17:25:08 +01:00
|
|
|
|
# From COMMAND [OPT]
|
2022-02-14 02:57:58 +01:00
|
|
|
|
case "$1" in
|
2022-06-14 18:51:19 +02:00
|
|
|
|
check) Checkers ;;
|
|
|
|
|
make) Makers ;;
|
2022-06-18 18:02:14 +02:00
|
|
|
|
www) WWW__OPTIONS "$2" ;;
|
|
|
|
|
wip) WIP__remove ;; # wip command is only a remove case || make
|
2022-02-14 02:57:58 +01:00
|
|
|
|
esac
|
2022-06-14 18:51:19 +02:00
|
|
|
|
|
|
|
|
|
# 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_@}
|
2022-02-13 17:58:25 +01:00
|
|
|
|
done
|
|
|
|
|
|
2022-06-14 18:51:19 +02:00
|
|
|
|
# Remove split files
|
|
|
|
|
[[ -f "$gsl_tmp_post" ]] && rm -f "$gsl_tmp_post"
|
|
|
|
|
[[ -f "$gsl_tmp_head" ]] && rm -f "$gsl_tmp_head"
|
2022-02-21 17:25:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-06-14 18:51:19 +02:00
|
|
|
|
#======================================================================
|
|
|
|
|
#---------------------
|
|
|
|
|
# Tools for post files
|
|
|
|
|
#---------------------
|
|
|
|
|
#======================================================================
|
|
|
|
|
#======================================================================
|
|
|
|
|
# Check if .gsl files
|
|
|
|
|
#======================================================================
|
|
|
|
|
if__gsl_post() {
|
|
|
|
|
gsl_nbr_posts=`ls -1 *.gsl 2>/dev/null | wc -l`
|
2022-04-11 18:06:38 +02:00
|
|
|
|
(( $gsl_nbr_posts == 0 )) \
|
2022-06-14 18:51:19 +02:00
|
|
|
|
&& echo "! No .gsl file in this folder" \
|
2022-04-11 18:06:38 +02:00
|
|
|
|
&& exit
|
2022-02-13 17:58:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 18:51:19 +02:00
|
|
|
|
|
2022-03-01 12:39:16 +01:00
|
|
|
|
#======================================================================
|
2022-06-14 18:51:19 +02:00
|
|
|
|
# Get line from first title to split header & content
|
2022-03-01 12:39:16 +01:00
|
|
|
|
#======================================================================
|
2022-06-14 18:51:19 +02:00
|
|
|
|
article__splitter() {
|
2022-03-06 01:47:58 +01:00
|
|
|
|
gsl_post_begin=`
|
2022-03-08 17:53:40 +01:00
|
|
|
|
awk -v m="#1" \
|
2022-04-25 13:17:09 +02:00
|
|
|
|
'match($1,m) {print NR;exit}' \
|
2022-03-08 17:53:40 +01:00
|
|
|
|
"$gsl_post"`
|
2022-06-14 18:51:19 +02:00
|
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#======================================================================
|
|
|
|
|
# Get arguments from COMMAND (create)
|
|
|
|
|
# $2: post type
|
|
|
|
|
# $3: post name
|
|
|
|
|
#======================================================================
|
|
|
|
|
new__article_OPTIONS() {
|
|
|
|
|
gsl__find_domain
|
|
|
|
|
author__check || exit 0
|
|
|
|
|
|
|
|
|
|
# exit if no postname
|
|
|
|
|
! [[ "$3" ]] \
|
|
|
|
|
&& gsl__invalid_option "$3" "Please set a name for your $2"
|
|
|
|
|
|
|
|
|
|
gsl_postname="$3"
|
|
|
|
|
case "$gsl_postname" in
|
|
|
|
|
*".gsl") gsl_postname=${gsl_postname/%.gsl/}
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
# File exists
|
|
|
|
|
[[ -f "$gsl_postname.gsl" ]] \
|
|
|
|
|
&& echo "! $PWD/$gsl_postname.gsl already exists..." \
|
|
|
|
|
&& exit
|
|
|
|
|
|
|
|
|
|
gsl_proc="create"
|
|
|
|
|
[[ `grep -i "fr" <<<"$gsl_site_lang"` ]] \
|
|
|
|
|
&& gsl_today=`printf '%(%d-%m-%Y)T'` \
|
|
|
|
|
|| gsl_today=`date +%F`
|
|
|
|
|
|
|
|
|
|
gsl_post="$gsl_postname.gsl"
|
|
|
|
|
log__process_begin "Create $2"
|
|
|
|
|
|
|
|
|
|
touch "$PWD/$gsl_post"
|
|
|
|
|
cat << EONEWP >> "$PWD/$gsl_post"
|
|
|
|
|
type: $2
|
|
|
|
|
title:
|
|
|
|
|
slug:
|
|
|
|
|
info:
|
|
|
|
|
author:
|
|
|
|
|
tags:
|
|
|
|
|
date: $gsl_today
|
|
|
|
|
|
|
|
|
|
# Uncomment and fill
|
|
|
|
|
#link: NAME : URL : Alt-Text
|
|
|
|
|
#image: NBR : URI : ALT-TEXT
|
|
|
|
|
#abbr: SHORT : LONG
|
|
|
|
|
|
|
|
|
|
#1
|
|
|
|
|
·Bold· •Strong• ”Emphasis” ×Stile× ¤cat -n "$PWD/$gsl_postname.gsl"¤
|
|
|
|
|
EONEWP
|
|
|
|
|
|
|
|
|
|
get__post_sum "$gsl_post"
|
|
|
|
|
gsl__logs_print -i -f -src \
|
|
|
|
|
"Hash: $gsl_post_hash ; Size: $gsl_post_size" \
|
|
|
|
|
"$PWD/$gsl_post"
|
|
|
|
|
|
|
|
|
|
log__process_end "Create $2"
|
|
|
|
|
|
|
|
|
|
cat -n "$PWD/$gsl_post"
|
|
|
|
|
echo
|
|
|
|
|
gsl check "$gsl_post"
|
|
|
|
|
exit
|
2022-03-06 01:47:58 +01:00
|
|
|
|
}
|