2022-07-20 19:37:21 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# Name: Statique Littérateur
|
|
|
|
# Type: Article manager
|
|
|
|
# file: manage__articles
|
|
|
|
# Folder: /var/lib/stl/scripts/
|
|
|
|
# By echolib (XMPP: im@echolib.re)
|
|
|
|
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
|
|
|
|
|
|
|
|
|
|
|
#======================================================================
|
|
|
|
# Argument read
|
|
|
|
# $1: read
|
|
|
|
# $2: argument
|
|
|
|
#======================================================================
|
|
|
|
read__OPTIONS() {
|
|
|
|
! [[ "$2" ]] \
|
|
|
|
&& noarg "Cannot be empty"
|
|
|
|
|
|
|
|
case "$2" in
|
|
|
|
*".stl")
|
|
|
|
article__hash "$2"
|
2022-08-13 16:39:58 +02:00
|
|
|
if__file "$uri_article"
|
|
|
|
cat -n "$uri_article"
|
|
|
|
exit
|
2022-07-20 19:37:21 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
conf)
|
|
|
|
domain__get
|
|
|
|
if__file "$stl_file_pwd_conf" read
|
2022-08-13 16:39:58 +02:00
|
|
|
exit
|
2022-07-20 19:37:21 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
noarg "$2"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#======================================================================
|
|
|
|
# Argument read
|
|
|
|
# $1: edit
|
|
|
|
# $2: argument
|
|
|
|
#======================================================================
|
|
|
|
edit__OPTIONS() {
|
|
|
|
! [[ "$2" ]] \
|
|
|
|
&& noarg "Cannot be empty"
|
|
|
|
|
|
|
|
case "$2" in
|
|
|
|
*".stl")
|
|
|
|
article__hash "$2"
|
|
|
|
nano --linenumbers "$uri_article"
|
|
|
|
;;
|
|
|
|
|
|
|
|
conf)
|
|
|
|
domain__get
|
|
|
|
domain__OPTIONS "nc" "edit"
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
noarg "$2"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#======================================================================
|
|
|
|
# Split article in 2 files : metas + content
|
|
|
|
# Get begining article content line
|
|
|
|
# $1: article > $uri_article
|
|
|
|
#======================================================================
|
|
|
|
split_article() {
|
|
|
|
article_tmp_head=`mktemp` # Metas
|
|
|
|
article_tmp_post=`mktemp` # Content
|
|
|
|
|
|
|
|
article_begin=`
|
|
|
|
grep -n "^-----" "$1" \
|
|
|
|
| head -n 1 \
|
|
|
|
| awk -F: '{print $1}'`
|
|
|
|
|
|
|
|
if ! [[ $article_begin ]];then
|
|
|
|
log__add -e -C -A \
|
|
|
|
"No separator before content: use '-----'"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Create file with metas only
|
|
|
|
awk -v end="$article_begin" \
|
|
|
|
'NR >=1 && NR < end-1 {print}' \
|
|
|
|
"$1" \
|
|
|
|
> "$article_tmp_head"
|
|
|
|
|
|
|
|
((article_begin++))
|
|
|
|
|
|
|
|
# Create file with content only
|
|
|
|
awk -v end="$article_begin" \
|
|
|
|
'NR >= end {print}' \
|
|
|
|
"$1" \
|
|
|
|
> "$article_tmp_post"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#======================================================================
|
|
|
|
# Get article line for article_tmp_post. Count from begin - 1
|
|
|
|
#======================================================================
|
|
|
|
article__line() {
|
|
|
|
ln=$(( ln + article_begin - 1 ))
|
|
|
|
}
|
|
|
|
|
|
|
|
#======================================================================
|
|
|
|
# Get article hash + article_db ID from uri
|
|
|
|
# $1: file *.stl from argument
|
|
|
|
#======================================================================
|
|
|
|
article__hash() {
|
|
|
|
domain__get
|
|
|
|
this_article="$1"
|
|
|
|
uri_article="$domain_dir_articles/$1"
|
|
|
|
if__file "$uri_article"
|
|
|
|
|
|
|
|
while read -r "H" "S" "U"
|
|
|
|
do
|
|
|
|
article_hash="$H"
|
|
|
|
article_size="$S"
|
|
|
|
article_id=`echo "$U" | cksum | awk '{print $1}'`
|
|
|
|
article_db="$article_id.db"
|
|
|
|
article_log="$article_id.log"
|
|
|
|
done < <(cksum "$uri_article")
|
2022-08-08 17:34:11 +02:00
|
|
|
|
|
|
|
if [[ $article_size -lt 10 ]];then
|
|
|
|
echo "! This article is nearly empty..."
|
|
|
|
exit
|
|
|
|
|
|
|
|
elif [[ $article_size -lt 60 ]];then
|
|
|
|
echo "! This article is too small to be checked"
|
|
|
|
exit
|
|
|
|
fi
|
2022-07-20 19:37:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#======================================================================
|
|
|
|
# Get values from OPTIONAL metas
|
|
|
|
# $1: marker
|
|
|
|
# $2: from split mktemp > $article_tmp_head
|
|
|
|
# $3: check | make
|
|
|
|
# $4: $article_tmp_post
|
|
|
|
#======================================================================
|
|
|
|
get__content_metas() {
|
|
|
|
unset meta
|
|
|
|
|
|
|
|
while IFS=: read -r "ln" "content"
|
|
|
|
do
|
|
|
|
meta=true
|
|
|
|
header_f0=`awk -F"$1" '{print $2}' <<<"$content"`
|
|
|
|
header_f1=`awk -F" : " '{print $1}' <<<"$header_f0"`
|
|
|
|
header_f2=`awk -F" : " '{print $2}' <<<"$header_f0"`
|
|
|
|
header_f3=`awk -F" : " '{print $3}' <<<"$header_f0"`
|
|
|
|
|
|
|
|
case "$3" in
|
|
|
|
check)
|
|
|
|
case "$1" in
|
|
|
|
"^link: ") check__link ;;
|
|
|
|
"^image: ") check__image ;;
|
|
|
|
"^code: ") check__precode ;;
|
|
|
|
"^brut: ") check__brut ;;
|
|
|
|
"^abbr: ") check__abbr ;;
|
|
|
|
"^file: ") check__link_file ;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
|
|
|
|
make)
|
|
|
|
case "$1" in
|
|
|
|
"^abbr: ") make__abbrs "$4" ;;
|
|
|
|
"^link: ") make__links "$4" ;;
|
|
|
|
"^file: ") make__links_file "$4" ;;
|
|
|
|
"^image: ") make__images "$4" ;;
|
|
|
|
"^code: ") make__precode "$4" ;;
|
|
|
|
"^brut: ") make__brut "$4" ;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done < <(grep -n "$1" "$2" )
|
|
|
|
}
|