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

142 lines
3.7 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# file: gsl__sidebar
# Folder: /var/lib/gsl/scripts
# By echolib
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
#======================================================================
# Sidebar Manager | $1=call | $2=process | $3=POS/Post | $4=Post
#======================================================================
gsl__sidebar() {
case "$2" in
"")
ls -1X "$gsl_dir_domain_listings"
exit
;;
create|-C)
! [[ `ls -1 "$gsl_dir_domain_listings"` ]] \
&& echo "! No post in list: $gsl_dir_domain_listings" \
&& exit
gsl__page_sidebar_create
;;
add|-A)
# $2=process | $3=Position | $4=post
gsl_listing_process="add"
! [[ "$3" ]] \
&& echo "! Set a number <= $gsl_list_max_posts ; see help" \
&& exit
! [[ `expr "x$3" : "x[0-9]*$"` -gt 0 ]] \
&& gsl__list_bad_arg nbr $3
! (( $3 <= $gsl_list_max_posts )) \
&& gsl__list_bad_arg nbr $3
! [[ "$4" ]] \
&& gsl__list_bad_arg file
gsl__logs_print \
"$gsl_log_i" \
"Starting" \
"Process" \
"$1 ; $2 ; position $3 ; $4 from domain $gsl_find_domain" \
"$gsl_dir_domain_tpl/last-posts-list.html"
gsl__if_file "$4" post
gsl_listing_file="$gsl_dir_domain_listings/$4.list"
gsl_post_old_inlist=`ls -1 "$gsl_dir_domain_listings/" | grep ".list.$3"`
if [[ `ls -1 "$gsl_listing_file"* 2>/dev/null` ]];then
# Post exists (maybe with different position)
gsl__logs_print \
"$gsl_log_w" \
2022-04-15 09:07:23 +02:00
"Sidebar" \
"Post" \
"$gsl_listing_process $4 ; already in list !" \
"$gsl_dir_domain_listings/"
gsl_checker_war=true
elif [[ "$gsl_post_old_inlist" ]];then
# Another post exists at this position.
# Remove and create new in roller
rm -f "$gsl_dir_domain_listings/$gsl_post_old_inlist"
gsl__logs_print \
"$gsl_log_w" \
2022-04-15 09:07:23 +02:00
"Sidebar" \
"Post" \
"$gsl_listing_process $4 ; replace $gsl_post_old_inlist !" \
"$gsl_dir_domain_listings/$gsl_post_old_inlist"
gsl_checker_war=true
gsl__page_sidebar $2 $3 $4
else
# Not gound in list, create for roller
gsl__page_sidebar $2 $3 $4
fi
gsl__logs_print \
"$gsl_log_i" \
"Stopping" \
"Process" \
"$1 ; $2 ; position $3 ; $4 from domain $gsl_find_domain" \
"$gsl_dir_domain_tpl/last-posts-list.html"
;;
remove|-R)
gsl_listing_process="remove"
! [[ "$3" ]] \
&& gsl__list_bad_arg file $3
gsl__if_file "$3" post
gsl__logs_print \
"$gsl_log_i" \
"Starting" \
"Process" \
"$1 ; $2 ; $3 from domain $gsl_find_domain" \
"$gsl_dir_domain_tpl/last-posts-list.html"
gsl_post_rm_list=`ls -1 "$gsl_dir_domain_listings/" | grep "$3.list"`
rm -f "$gsl_dir_domain_listings/$gsl_post_rm_list" && \
gsl__logs_print \
"$gsl_log_w" \
"Sidebar" \
"$2" \
"$3 from domain $gsl_find_domain in list" \
"$gsl_dir_domain_listings/$gsl_post_rm_list"
gsl_checker_war=true
gsl__page_sidebar_create
gsl__logs_print \
"$gsl_log_i" \
"Stopping" \
"Process" \
"$1 ; $2 ; $3 from domain $gsl_find_domain" \
"$gsl_dir_domain_tpl/last-posts-list.html"
;;
*)
echo "! Bad argument: add|-A/remove|-R"
exit
;;
esac
}
#======================================================================
# Sidebar Return bad argument
#======================================================================
gsl__list_bad_arg() {
case "$1" in
nbr)
echo "! $2 is not a number <= $gsl_list_max_posts ; see help"
;;
file)
echo "! Set post [FILE]"
;;
esac
exit
}