#!/bin/bash # file: gsl__db_manager # Folder: /var/lib/gsl/scripts # By echolib (XMPP: im@echolib.re) # License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 #====================================================================== # Get arguments from COMMAND (db) # $1 File #====================================================================== db__OPTIONS() { author__check || exit 0 # Check if authors registresd ! [[ "$1" ]] \ && gsl__invalid_option "$1" "[File]" if__file "$1" post [[ -f "$gsl_dir_db_domain/$gsl_this_post.db" ]] \ && cat "$gsl_dir_db_domain/$gsl_this_post.db" \ || echo "! No DB yet for $gsl_this_post. Check it first." exit } #====================================================================== # Get Post Hash & Status From Database #====================================================================== DB__datas() { if ! [[ -f "$gsl_file_db_post" ]];then gsl__logs_print -w -D -f \ "Article not yet checked" \ "$gsl_file_db_post" article_is_new=true else # Check corrupted file Hash_DB=`cksum "$gsl_file_db_post" | awk '{print $1}'` if ! [[ -f $gsl_file_db_post_hash.$Hash_DB ]];then db_corrupt=true [[ `grep "article_Status_www=" "$gsl_file_db_post"` \ || `grep "article_Status_wip=" "$gsl_file_db_post"` ]] \ || return fi source "$gsl_file_db_post" fi } #====================================================================== # Compare post Hash from Database #====================================================================== DB__compare_hash() { case "$1" in check) gsl_do_check=true [[ $article_is_new ]] && return [[ $db_corrupt ]] && gsl_force_check=true if [[ $article_Errors == "no" ]];then if (( $article_Hash == $article_Status_chk ));then if ! [[ $gsl_force_check ]];then gsl__logs_print -w -g -C \ "Already done ; Use -F to force" \ "$PWD/$gsl_post" unset gsl_do_check fi else gsl__logs_print -w -g \ "Compare" \ "Old Hash: $article_Status_chk" \ "${PWD}/$gsl_post" fi fi ;; make|www) [[ $db_corrupt ]] \ && gsl__logs_print -e -D -f \ "Corrupted ; Check again first" \ "$gsl_file_db_post" \ && return [[ $article_is_new ]] && return if (( $article_Hash != $article_Status_chk ));then gsl__logs_print -e -A -inv \ "Article not checked yet" \ "$PWD/$gsl_post" return elif [[ $article_Errors == "yes" ]];then gsl__logs_print -e -A -inv \ "Found errors ; Cannot continue" \ "$PWD/$gsl_post" return fi gsl_do_make=true ;; esac } #====================================================================== # Logger #====================================================================== DB__create_log() { gsl__logs_print -i -D -c \ "$article_Type ; Hash: $article_Hash" \ "$gsl_file_db_post" } #====================================================================== # Set Post Statuses (chk, wip, www) in Database according to proceess #====================================================================== DB__set_status() { case "$1" in chk) article_Status_chk="article_Status_chk=$article_Hash" ! [[ $article_Status_wip ]] \ && article_Status_wip="article_Status_wip=0" \ || article_Status_wip="article_Status_wip=$article_Status_wip" ! [[ $article_Status_www ]] \ && article_Status_www="article_Status_www=0" \ || article_Status_www="article_Status_www=$article_Status_www" DB__create_datas DB__create_sum ;; wip) sed -i "s/article_Status_wip=.*/article_Status_wip=$article_Hash/" \ "$gsl_file_db_post" DB__create_sum ;; wip-del) sed -i "s/article_Status_wip=.*/article_Status_wip=0/" \ "$gsl_file_db_post" DB__create_sum ;; www) sed -i "s/article_Status_www=.*/article_Status_www=$article_Hash/" \ "$gsl_file_db_post" DB__create_sum ;; www-del) sed -i "s/article_Status_www=.*/article_Status_www=0/" \ "$gsl_file_db_post" DB__create_sum ;; esac } #====================================================================== # Create DB File for this article #====================================================================== DB__create_datas() { ! [[ -d "$gsl_dir_db_domain" ]] \ && mkdir -p "$gsl_dir_db_domain" [[ -f "$gsl_file_db_post" ]] \ && rm -f "$gsl_file_db_post" rm -f "$gsl_file_db_post_hash."* touch "$gsl_file_db_post" # Main Print cat << EODB > "$gsl_file_db_post" # File article_domain="$domain_name" article_URI="${PWD}/$gsl_post" $article_Status_chk $article_Status_wip $article_Status_www article_epoch=$date_epoch # Article article_Errors="$article_Errors" article_Type=$gsl_post_type article_CSS="$gsl_post_css" article_Date="$gsl_post_date" article_Title="$gsl_post_title" article_Info="$gsl_post_info" article_Slug="$gsl_post_slug" article_Author="$gsl_post_author" article_Tags="$gsl_post_tags" # Import $(cat "$gsl_tmp_db") # Stats stat_Titles=$gsl_stat_titles stat_Tags=$gsl_stat_tags stat_Words=$gsl_stat_words stat_Paragraphs=$gsl_stat_p stat_Links=$gsl_stat_links stat_Links_Online=$gsl_stat_links_online stat_ABBRS=$gsl_stat_abbrs stat_Strongs=$gsl_stat_strongs stat_Bolds=$gsl_stat_bolds stat_Emphasis=$gsl_stat_italics stat_Strikes=$gsl_stat_strikes stat_Icodes=$gsl_stat_icodes stat_Lists=$gsl_stat_lists stat_Lists_Items=$gsl_list_items stat_Quotes=$gsl_stat_bq stat_Images=$gsl_stat_images stat_max_Images=$gsl_total_images stat_Flinks=$gsl_stat_flinks stat_Fcodes=$gsl_stat_fcodes stat_max_Fcodes=$gsl_total_fcodes stat_Fbruts=$gsl_stat_fbruts stat_max_Fbruts=$gsl_total_fbruts EODB } #====================================================================== # Create DB File.HASH for this article (avoid corruption) #====================================================================== DB__create_sum() { if [[ -f "$gsl_file_db_post" ]];then Hash_DB=`cksum "$gsl_file_db_post" | awk '{print $1}'` rm -f "$gsl_file_db_post_hash."* touch "$gsl_file_db_post_hash.$Hash_DB" source "$gsl_file_db_post" DB__create_log "$1" fi }