341 lines
8.0 KiB
Bash
341 lines
8.0 KiB
Bash
#!/bin/bash
|
|
# file: gsl__srv_manager
|
|
# Folder: /var/lib/gsl/scripts
|
|
# By echolib (XMPP: im@echolib.re)
|
|
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
|
|
|
|
|
#======================================================================
|
|
# w<< (ARGUMENT)
|
|
# $1: process
|
|
# $2: file / all
|
|
#======================================================================
|
|
srv__OPTIONS() {
|
|
case "$2" in
|
|
sync) sync__OPTIONS $1 ;;
|
|
add) true ;;
|
|
remove) true ;;
|
|
*) gsl__invalid_option "$2" "add|remove|sync"
|
|
esac
|
|
|
|
case "$3" in
|
|
*".gsl")
|
|
if__file "$3" post
|
|
gsl_post="$3"
|
|
post_only="$3"
|
|
case "$1" in
|
|
wip)
|
|
gsl make "$3"
|
|
exit
|
|
;;
|
|
esac
|
|
;;
|
|
|
|
all)
|
|
case "$1" in
|
|
www)
|
|
echo "! You're about to put online all wip articles"
|
|
read -rp "- Continue (YES|*)" www_confirm
|
|
case "www_confirm" in
|
|
YES) gsl_www="$3" ;;
|
|
*) echo "# Abandon"; exit ;;
|
|
esac
|
|
;;
|
|
|
|
wip)
|
|
gsl make
|
|
exit
|
|
;;
|
|
esac
|
|
;;
|
|
|
|
"")
|
|
gsl__invalid_option "$3" "all|file"
|
|
;;
|
|
esac
|
|
|
|
www_process=true
|
|
|
|
[[ "$gsl_post" ]] || log_info_all=" ALL"
|
|
|
|
log__process_begin "Server ($1 online)${log_info_all}"
|
|
posts__loop "$1" "$2"
|
|
|
|
# For logs ; set post or unset if all
|
|
[[ $log_info_all ]] && unset gsl_post
|
|
[[ $post_only ]] && gsl_post="$post_only"
|
|
|
|
log__process_end "Server ($1 online)${log_info_all}"
|
|
}
|
|
|
|
|
|
#======================================================================
|
|
# wip: remove online
|
|
#======================================================================
|
|
WIP__remove() {
|
|
case "$1" in
|
|
remove)
|
|
if [[ -f "$gsl_srv_post_wip" ]];then
|
|
rm -f "$gsl_srv_post_wip" && \
|
|
gsl__logs_print -w -srv wip \
|
|
"Article deleted ; no more online" \
|
|
"$gsl_srv_post_wip"
|
|
|
|
find "$gsl_srv_wip" -type d -empty -delete && \
|
|
gsl__logs_print -w -srv wip \
|
|
"Cleaned empty directories" \
|
|
"$gsl_srv_wip"
|
|
|
|
DB__set_status "wip-del"
|
|
fi
|
|
return
|
|
;;
|
|
esac
|
|
}
|
|
|
|
|
|
#======================================================================
|
|
# www: Valid online
|
|
#======================================================================
|
|
WWW__validate() {
|
|
case "$1" in
|
|
remove)
|
|
if [[ -f "$gsl_srv_post_www" ]];then
|
|
rm -f "$gsl_srv_post_www" && \
|
|
gsl__logs_print -w -srv www \
|
|
"Article deleted ; no more online" \
|
|
"$gsl_srv_post_www"
|
|
|
|
find "$gsl_srv_www" -type d -empty -delete && \
|
|
gsl__logs_print -w -srv www \
|
|
"Cleaned empty directories" \
|
|
"$gsl_srv_www"
|
|
|
|
DB__set_status "www-del"
|
|
fi
|
|
create__RSS_feed
|
|
stats__datas # Statoolinfos
|
|
return
|
|
;;
|
|
esac
|
|
|
|
if ! [[ $article_Status_chk ]];then
|
|
gsl__logs_print -e -srv www \
|
|
"Article not yet checked" \
|
|
"$PWD/$gsl_post"
|
|
return
|
|
|
|
elif (( $article_Status_chk != $article_Status_wip ));then
|
|
gsl__logs_print -e -srv www \
|
|
"Article not yet converted with make" \
|
|
"$gsl_srv_post_wip"
|
|
return
|
|
|
|
elif (( $article_Status_chk == $article_Status_www )) && \
|
|
[[ -f "$gsl_srv_post_www" ]];then
|
|
gsl__logs_print -w -srv www \
|
|
"Article already online" \
|
|
"$gsl_srv_post_www"
|
|
return
|
|
|
|
else
|
|
if (( $article_Status_chk == $article_Status_wip ));then
|
|
[[ "$article_Type" == "post" ]] \
|
|
&& mkdir -p "$gsl_slug_dir_www"
|
|
|
|
rsync -a "$gsl_srv_post_wip" "$gsl_srv_post_www" && \
|
|
gsl__logs_print -i -srv www \
|
|
"Article validated online" \
|
|
"$gsl_srv_post_www" && \
|
|
DB__set_status "www"
|
|
create__RSS_feed
|
|
stats__datas # Statoolinfos
|
|
fi
|
|
fi
|
|
}
|
|
|
|
|
|
#======================================================================
|
|
# Get arguments from COMMAND (sync)
|
|
# $2: process (wip|www|"")
|
|
#======================================================================
|
|
sync__OPTIONS() {
|
|
gsl_srv_wip="$site_server/$site_ndd/wip"
|
|
gsl_srv_www="$site_server/$site_ndd/www"
|
|
|
|
case "$1" in
|
|
""|www|wip)
|
|
! [[ "$1" ]] \
|
|
&& srv_proc="wip+www" \
|
|
|| srv_proc="$1"
|
|
|
|
log__process_begin "Sync $srv_proc"
|
|
case "$1" in
|
|
"")
|
|
sync__srv "$srv_proc" "$gsl_srv_wip"
|
|
sync__srv "$srv_proc" "$gsl_srv_www"
|
|
;;
|
|
www)
|
|
sync__srv "$srv_proc" "$gsl_srv_www"
|
|
;;
|
|
wip)
|
|
sync__srv "$srv_proc" "$gsl_srv_wip"
|
|
;;
|
|
esac
|
|
log__process_end "Sync $srv_proc"
|
|
;;
|
|
|
|
*)
|
|
gsl__invalid_option "$2" "www|wip"
|
|
;;
|
|
esac
|
|
exit
|
|
}
|
|
|
|
|
|
#======================================================================
|
|
# Sync Files from Templates to webserver
|
|
# $1: process (wip|www|wip+www)
|
|
# $2: Folder
|
|
#======================================================================
|
|
sync__srv() {
|
|
# Sync Files and Folders
|
|
mkdir -p "$2"
|
|
rsync -a --delete "$gsl_dir_domain_tpl" "$2"
|
|
rsync -a --delete "$gsl_dir_domain_files" "$2"
|
|
rsync -a --delete "$gsl_dir_domain_images" "$2"
|
|
rsync -a --delete "$gsl_dir_domain_listings" "$2"
|
|
|
|
gsl__logs_print -i -srv $1 \
|
|
"Sync: $gsl_dir_domain/" \
|
|
"$2/"
|
|
}
|
|
|
|
|
|
#======================================================================
|
|
# Set Post/Page file for www+wip from page type and slug
|
|
# Find server post/page file and log
|
|
#======================================================================
|
|
srv__files() {
|
|
gsl_srv_wip="$site_server/$site_ndd/wip"
|
|
gsl_srv_www="$site_server/$site_ndd/www"
|
|
|
|
case "$1" in
|
|
datas)
|
|
unset srv_uri
|
|
case "$article_Type" in
|
|
post)
|
|
gsl_srv_post_wip="$gsl_srv_wip/$article_Slug/index.html"
|
|
gsl_srv_post_www="$gsl_srv_www/$article_Slug/index.html"
|
|
gsl_slug_file="$article_Slug/index.html"
|
|
gsl_slug_dir_wip=${gsl_srv_post_wip%\/*}
|
|
gsl_slug_dir_www=${gsl_srv_post_www%\/*}
|
|
|
|
# Count sub directories
|
|
sub_uri="${article_Slug//[^\/]}"
|
|
srv_uri+=`printf '%0.s../' $(seq 0 ${#sub_uri})`
|
|
;;
|
|
|
|
page)
|
|
gsl_srv_post_wip="$gsl_srv_wip/$article_Slug.html"
|
|
gsl_srv_post_www="$gsl_srv_www/$article_Slug.html"
|
|
gsl_slug_file="$article_Slug.html"
|
|
|
|
srv_uri='./'
|
|
;;
|
|
|
|
*)
|
|
return
|
|
;;
|
|
esac
|
|
|
|
# wip file ?
|
|
if [[ -f "$gsl_srv_post_wip" ]];then
|
|
[[ "$article_Status_wip" == "$article_Status_chk" ]] \
|
|
&& wip_status="(current)" \
|
|
|| wip_status="(old)"
|
|
|
|
gsl_srv_wip_file=true
|
|
|
|
else
|
|
unset gsl_srv_wip_file
|
|
fi
|
|
|
|
# www file ?
|
|
if [[ -f "$gsl_srv_post_www" ]];then
|
|
[[ "$article_Status_www" == "$article_Status_chk" ]] \
|
|
&& www_status="(current)" \
|
|
|| www_status="(old)"
|
|
|
|
gsl_srv_www_file=true
|
|
|
|
else
|
|
unset gsl_srv_www_file
|
|
fi
|
|
;;
|
|
|
|
logs)
|
|
# WIP file
|
|
if [[ $gsl_srv_wip_file ]];then
|
|
gsl__logs_print -i -srv -wip \
|
|
"HTML $article_Type Found $wip_status" \
|
|
"$gsl_srv_post_wip"
|
|
|
|
else
|
|
gsl__logs_print -w -srv -wip \
|
|
"HTML $article_Type not created yet" \
|
|
"$gsl_srv_post_wip"
|
|
fi
|
|
|
|
# WWW file
|
|
if [[ $gsl_srv_www_file ]];then
|
|
gsl__logs_print -i -srv -www \
|
|
"HTML $article_Type Found $www_status" \
|
|
"$gsl_srv_post_www"
|
|
else
|
|
gsl__logs_print -w -srv -www \
|
|
"HTML $article_Type not created yet" \
|
|
"$gsl_srv_post_www"
|
|
fi
|
|
;;
|
|
esac
|
|
}
|
|
|
|
|
|
#======================================================================
|
|
# Remove WIP page
|
|
# If error from check and exists
|
|
#======================================================================
|
|
wip__remove() {
|
|
! [[ -f "$gsl_srv_post_wip" ]] && return
|
|
|
|
log_Type="in $article_Slug"
|
|
|
|
# Remove from old slug, if new article Type set
|
|
[[ "$old_Type" ]] \
|
|
&& article_Type="$old_Type" \
|
|
&& article_Slug="$old_Slug" \
|
|
&& log_Type="from old $old_Type"
|
|
|
|
rm -f "$gsl_srv_post_wip" && \
|
|
gsl__logs_print -w -S -wip \
|
|
"Article deleted ; no more preview" \
|
|
"$gsl_srv_post_wip"
|
|
|
|
find "$gsl_srv_wip" -type d -empty -delete && \
|
|
gsl__logs_print -w -S -wip \
|
|
"Cleaned empty directories" \
|
|
"$gsl_srv_wip"
|
|
|
|
gsl__logs_print -w -R -wip \
|
|
"Found $1 $log_Type" \
|
|
"$gsl_srv_post_wip"
|
|
|
|
if [[ "$old_Type" ]];then
|
|
unset old_Type old_Slug log_Type
|
|
|
|
[[ -f "$gsl_file_db_post" ]] \
|
|
&& source "$gsl_file_db_post"
|
|
fi
|
|
}
|