108 lines
2.9 KiB
Bash
108 lines
2.9 KiB
Bash
#!/bin/bash
|
|
# file: gsl__do_commons
|
|
# Folder: /var/lib/gsl/scripts
|
|
# By echolib (XMPP: im@echolib.re)
|
|
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
|
|
|
|
|
#======================================================================
|
|
# Set/Get NEEDED DATAS from META HEADERS
|
|
# $1: process
|
|
# $2: file: (gsl_tmp_head)
|
|
#======================================================================
|
|
get__needed_headers() {
|
|
gsl__logs_print -i -g \
|
|
"Get" \
|
|
"Needed Metas from header" \
|
|
"$2"
|
|
|
|
read__line_with "^$gsl_marker_type" "$1" \
|
|
"$gsl_marker_type" "meta" "$2"
|
|
|
|
read__line_with "^$gsl_marker_slug" "$1" \
|
|
"$gsl_marker_slug" "meta" "$2"
|
|
|
|
read__line_with "^$gsl_marker_title" "$1" \
|
|
"$gsl_marker_title" "meta" "$2"
|
|
|
|
read__line_with "^$gsl_marker_info" "$1" \
|
|
"$gsl_marker_info" "meta" "$2"
|
|
|
|
read__line_with "^$gsl_marker_author" "$1" \
|
|
"$gsl_marker_author" "meta" "$2"
|
|
|
|
read__line_with "^$gsl_marker_tags" "$1" \
|
|
"$gsl_marker_tags" "meta" "$2"
|
|
|
|
read__line_with "^$gsl_marker_date" "$1" \
|
|
"$gsl_marker_date" "meta" "$2"
|
|
|
|
read__line_with "^$gsl_marker_css" "$1" \
|
|
"$gsl_marker_css" "meta" "$2"
|
|
}
|
|
|
|
|
|
#======================================================================
|
|
# Read line with
|
|
# $1: TERM
|
|
# $2: process
|
|
# $3: marker
|
|
# $4: type (meta/metas)
|
|
# $5: file
|
|
# From "meta" ; check only one marker ; get fields
|
|
# From "metas" ; check multiple markers ; get fields
|
|
# From content ; read line ; no need to get fields
|
|
#======================================================================
|
|
read__line_with() {
|
|
# meta must be set, and no more than one value
|
|
if [[ "$2" == "check" && "$4" == "meta" ]];then
|
|
meta_nbr=`grep -n "$1" "$5" | wc -l`
|
|
if (( $meta_nbr == 0 ));then
|
|
if [[ "$3" == "$gsl_marker_css" ]];then
|
|
gsl__logs_print -w -h \
|
|
"$gsl_marker_css" \
|
|
"Body template: css not customized" \
|
|
"$PWD/$gsl_post"
|
|
gsl_post_css=""
|
|
|
|
else
|
|
gsl__logs_print -e -h \
|
|
"$3" \
|
|
"Unused needed marker" \
|
|
"${PWD}/$gsl_post"
|
|
return
|
|
fi
|
|
|
|
elif (( $meta_nbr > 1 ));then
|
|
gsl__logs_print -e -h \
|
|
"$3" \
|
|
"Set only one marker ; Found $meta_nbr" \
|
|
"${PWD}/$gsl_post"
|
|
return
|
|
fi
|
|
fi
|
|
|
|
# Read line filtered
|
|
while IFS=: read -r "ln" "gsl_line"
|
|
do
|
|
|
|
# Get values if meta(s)
|
|
case "$4" in
|
|
meta|metas)
|
|
header_f1=`awk -F" : " '{print $1}' <<<"$gsl_line"`
|
|
header_f0=`awk -F": " '{print $1}' <<<"$header_f1"`
|
|
header_f1=`awk -F": " '{print $2}' <<<"$header_f1"`
|
|
header_f2=`awk -F" : " '{print $2}' <<<"$gsl_line"`
|
|
header_f3=`awk -F" : " '{print $3}' <<<"$gsl_line"`
|
|
;;
|
|
esac
|
|
|
|
# From process, do
|
|
case "$2" in
|
|
check) check__headers_from_filter "$1" "$2" "$3" "$4" ;;
|
|
make) make__headers_from_filter "$1" "$3" "$5" "$6" "$7" "$8" ;;
|
|
esac
|
|
|
|
done < <(grep -n "$1" "$5")
|
|
}
|