#!/bin/bash # file: gsl__post_manager # Folder: /var/lib/gsl/scripts # By echolib (XMPP: im@echolib.re) # License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 #====================================================================== # --------------------------------- # LOOP. Read ALL .gsl files in $PWD # --------------------------------- #====================================================================== posts__loop() { for gsl_post in `ls -1 *.gsl 2>/dev/null` do # Do specific asked Post [[ "$gsl_this_post" ]] && ! [[ "$gsl_post" == "$gsl_this_post" ]] \ && continue # 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" # 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 # From COMMAND [OPT] case "$1" in check) Checkers ;; make) Makers ;; www) WWW__validate "$2" ;; wip) WIP__remove "$2" ;; esac # 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_@} done # Remove split files [[ -f "$gsl_tmp_post" ]] && rm -f "$gsl_tmp_post" [[ -f "$gsl_tmp_head" ]] && rm -f "$gsl_tmp_head" } #====================================================================== #--------------------- # Tools for post files #--------------------- #====================================================================== #====================================================================== # Check if .gsl files #====================================================================== if__gsl_post() { gsl_nbr_posts=`ls -1 *.gsl 2>/dev/null | wc -l` (( $gsl_nbr_posts == 0 )) \ && echo "! No .gsl file in this folder" \ && exit } #====================================================================== # Get line from first title to split header & content #====================================================================== article__splitter() { gsl_post_begin=` awk -v m="#1" \ 'match($1,m) {print NR;exit}' \ "$gsl_post"` 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 }