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

651 lines
15 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# file: gsl__post_checkers
# Folder: /var/lib/gsl/scripts
# By echolib
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
2022-02-21 17:25:08 +01:00
#-----------------------------------------------------------------------
# --------------------------------------------------
# From: gsl__loop_posts | MAIN checkers from modules
# --------------------------------------------------
#-----------------------------------------------------------------------
gsl__all_checkers() {
clear
unset gsl_check_done
2022-02-27 19:16:16 +01:00
gsl__check_h1 || return
gsl__get_needed_headers
gsl__check_type
gsl__check_headers
gsl__check_paragraphs
gsl__check_blockquote
gsl__do_header check "$gsl_marker_link" "$gsl_post"
gsl__do_header check "$gsl_marker_abbr" "$gsl_post"
gsl__do_header check "$gsl_marker_file" "$gsl_post"
gsl__do_header check "$gsl_marker_image" "$gsl_post"
gsl__do_header check "$gsl_marker_code" "$gsl_post"
#echo -ne "\r\033[2K: Searching for Content MARKERS..."
#gsl__post_check_markers
#echo -ne "\r\033[2K: Searching for some STATS..."
#gsl__post_check_stats
2022-02-15 12:42:54 +01:00
echo -ne "\r\033[2K"
2022-02-15 17:56:45 +01:00
# End of checkers : show logs for war and err
2022-02-17 11:28:04 +01:00
gsl__db_line_post
}
2022-02-21 17:25:08 +01:00
#-----------------------------------------------------------------------
# -------------------------------------------------
2022-02-27 19:16:16 +01:00
# Modules checkers
2022-02-21 17:25:08 +01:00
# -------------------------------------------------
#-----------------------------------------------------------------------
2022-02-27 19:16:16 +01:00
#=======================================================================
# Check Post for begining content
#=======================================================================
gsl__check_h1() {
echo -ne ": Searching for #1..."
gsl_post_begin=`
grep -n "#1" $gsl_post \
| head -1 \
| awk -F: '{print $1}'`
if ! [[ "$gsl_post_begin" ]];then
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"$gsl_log_c_h1" \
"Missing: #1 TITLE" \
"${PWD}/$gsl_post"
gsl_checker_err=true
fi
}
#=======================================================================
# Check/Set Post Type
#=======================================================================
gsl__check_type() {
echo -ne "\r\033[2K: Searching for Post TYPE..."
case "$gsl_post_type" in
page|post)
gsl__logs_print \
"$gsl_log_i" \
"Post" \
"Set as" \
"$gsl_post_type: $gsl_post" \
"${PWD}/$gsl_post"
;;
*)
sed -i "s|$gsl_marker_type.*|${gsl_marker_type}post|" \
"$gsl_post" && \
gsl__logs_print \
"$gsl_log_w" \
"Post" \
"Set as" \
"Default $gsl_post_type: $gsl_post" \
"${PWD}/$gsl_post"
;;
esac
}
#=======================================================================
# Check for paragraphs ( and )
#=======================================================================
gsl__check_paragraphs() {
echo -ne "\r\033[2K: Searching for Paragraphs..."
gsl_post_p_open=`
awk -v line="$gsl_post_begin" \
-v op="$gsl_mo_p" \
'NR > line && $1 == op' \
"$gsl_post" \
| wc -l`
gsl_post_p_close=`
awk -v line="$gsl_post_begin" \
-v cp="$gsl_mc_p" \
'NR > line && $1 == cp' \
"$gsl_post" \
| wc -l`
if (( "$gsl_post_p_open" == 0 ));then
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"$gsl_loc_c_p" \
"Missing: ( and ) at begining lines" \
"${PWD}/$gsl_post"
gsl_checker_err=true
return
fi
if (( "$gsl_post_p_open" == "$gsl_post_p_close" ));then
gsl_stat_p="$gsl_post_p_open"
else
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"$gsl_log_c_p" \
"Mismatch: (=$gsl_post_p_open ; )=$gsl_post_p_close" \
"${PWD}/$gsl_post"
gsl_checker_err=true
return
fi
}
#=======================================================================
# Check for blockquotes: ---
#=======================================================================
gsl__check_blockquote() {
echo -ne "\r\033[2K: Searching for BLOCKQUOTEs..."
gsl_post_blockquotes_nbr=`
awk -v line="$gsl_post_begin" \
-v bq="$gsl_mark_blockquote" \
'NR > line && $1 == bq' \
"$gsl_post" \
| wc -l`
gsl_post_blockquotes_nbr_r=$(( $gsl_post_blockquotes_nbr % 2 ))
if [[ "$gsl_post_blockquotes_nbr_r" -eq 0 ]];then
gsl_stat_bq=$(( $gsl_post_blockquotes_nbr / 2 ))
else
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"$gsl_log_c_cite" \
"Mismatch: --- not paired" \
"${PWD}/$gsl_post"
gsl_checker_err=true
fi
}
#======================================================================
# From gsl__do_header: Check Link
#======================================================================
gsl__check_link() {
# Get & Check Header CONTENT
gsl__check_header_fields \
"Post" "$gsl_log_h_link" "$gsl_log_act_link" \
|| return
echo -ne "\r\033[2K: Searching for Links... $gsl_post_hf_1"
# No ALT TEXT ?
gsl__check_header_field3 "Post" "$gsl_log_h_link" "$gsl_marker_link"
gsl_count_links=`
gsl__get_content_line "_$gsl_post_hf_1" "$gsl_post" | wc -l
`
if (( "$gsl_count_links" > 0 ));then
# Check URL
gsl_url_online=`
curl -o /dev/null --silent --head --write-out \
'%{http_code}' \
"$gsl_post_hf_2" 2>/dev/null`
if (( $gsl_url_online == 200 )) || \
(( $gsl_url_online == 301 )) || \
(( $gsl_url_online == 302 ));then
gsl__logs_print \
"$gsl_log_i" \
"Post" \
"$gsl_log_h_link" \
"Online:$gsl_url_online ${gsl_post_hf_2:0:40}..." \
"${PWD}/$gsl_post"
else
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"$gsl_log_h_link" \
"Offline:$gsl_url_online ${gsl_post_hf_2:0:40}..." \
"${PWD}/$gsl_post"
gsl_checker_err=true
return
fi
# Stats
((gsl_stat_link++))
gsl_stat_links=$(( gsl_stat_links + gsl_count_links ))
else
gsl__logs_print \
"$gsl_log_i" \
"Post" \
"$gsl_log_c_link" \
"Missing: _$gsl_post_hf_1" \
"${PWD}/$gsl_post"
gsl_checker_err=true
fi
}
#======================================================================
# From gsl__do_header: Check ABBR
#======================================================================
gsl__check_abbr() {
gsl__check_header_fields \
"Post" "$gsl_log_h_abbr" "$gsl_log_act_abbr" \
|| return
echo -ne "\r\033[2K: Searching for ABBRs... $gsl_post_hf_1"
gsl_count_abbrs=`
gsl__get_content_line "$gsl_post_hf_1" "$gsl_post" | wc -l`
if (( "$gsl_count_abbrs" > 0 ));then
((gsl_stat_abbr++))
gsl_stat_abbrs=$(( gsl_stat_abbrs + gsl_count_abbrs ))
else
# Missing CONTENT
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"$gsl_log_c_abbr" \
"Missing: $gsl_post_header_field_1" \
"${PWD}/$gsl_post"
gsl_checker_err=true
fi
}
#======================================================================
# From gsl__do_header: Check Files
#======================================================================
gsl__check_file() {
gsl__check_header_fields \
"Post" "$gsl_log_h_file" "$gsl_log_act_file" \
|| return
echo -ne "\r\033[2K: Searching for Content Files... $gsl_post_hf_1"
gsl__check_header_field3 "Post" "$gsl_log_h_file" "$gsl_marker_file"
# File exists in folder
if ! [[ -f "$gsl_dir_domain_files/$gsl_post_hf_2" ]];then
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"Header $gsl_marker_file" \
"Not found: $gsl_post_hf_2" \
"$gsl_dir_domain_files/$gsl_post_hf_2"
gsl_checker_err=true
else
# Register file to DB with hash
gsl_file_csum=`
cksum "$gsl_dir_domain_files/$gsl_post_hf_2" \
| awk '{print $1}'`
gsl_db_post_files+="$gsl_post_hf_2|"
gsl__db_line_file
fi
# Exists in Content
gsl_count_files=`
gsl__get_content_line "__$gsl_post_hf_1" "$gsl_post" | wc -l`
if (( $gsl_count_files > 0 ));then
((gsl_stat_file++))
else
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"$gsl_log_c_file" \
"Missing: __$gsl_post_hf_1" \
"${PWD}/$gsl_post"
gsl_checker_err=true
fi
}
#======================================================================
# From gsl__do_header: Check Files
#======================================================================
gsl__check_image() {
gsl__check_header_fields \
"Post" "$gsl_log_h_image" "$gsl_log_act_image" \
|| return
echo -ne "\r\033[2K: Searching for Images... $gsl_post_hf_1"
gsl__check_header_field3 "Post" "$gsl_log_h_image" "$gsl_marker_image" \
|| return
# File exists in folder
if ! [[ -f "$gsl_dir_domain_files/$gsl_post_hf_2" ]];then
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"$gsl_log_h_image" \
"Not found: $gsl_post_hf_2" \
"$gsl_dir_domain_files/$gsl_post_hf_2"
gsl_checker_err=true
else
# Register file to DB with hash
gsl_file_csum=`
cksum "$gsl_dir_domain_files/$gsl_post_hf_2" \
| awk '{print $1}'`
gsl_db_post_files+="$gsl_post_hf_2|"
gsl__db_line_file
fi
# Exists in Content
gsl_count_files=`
gsl__get_content_line "__image:$gsl_post_hf_1" "$gsl_post" | wc -l`
if (( $gsl_count_files > 0 ));then
((gsl_stat_file++))
else
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"$gsl_log_c_image" \
"Missing: __image:$gsl_post_hf_1" \
"${PWD}/$gsl_post"
gsl_checker_err=true
fi
}
#======================================================================
# From gsl__do_header: Check Files
#======================================================================
gsl__check_fcode() {
gsl__check_header_fields \
"Post" "$gsl_log_h_code" "$gsl_log_act_code" \
|| return
echo -ne "\r\033[2K: Searching for File Codes... $gsl_post_hf_1"
gsl__check_header_field3 "Post" "$gsl_log_h_code" "$gsl_marker_code" \
# File exists in folder
if ! [[ -f "$gsl_dir_domain_files/$gsl_post_hf_2" ]];then
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"$gsl_log_h_code" \
"Not found: $gsl_post_hf_2" \
"$gsl_dir_domain_files/$gsl_post_hf_2"
gsl_checker_err=true
else
# Register file to DB with hash
gsl_file_csum=`
cksum "$gsl_dir_domain_files/$gsl_post_hf_2" \
| awk '{print $1}'`
gsl_db_post_files+="$gsl_post_hf_2|"
gsl__db_line_file
fi
# Exists in Content
gsl_count_fcodes=`
gsl__get_content_line "__code:$gsl_post_hf_1" "$gsl_post" | wc -l`
if (( $gsl_count_fcodes > 0 ));then
((gsl_stat_fcode+))
else
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"$gsl_log_c_code" \
"Missing: __code:$gsl_post_hf_1" \
"${PWD}/$gsl_post"
gsl_checker_err=true
fi
}
2022-02-21 17:25:08 +01:00
#=======================================================================
2022-02-14 02:57:58 +01:00
# Check Post for MISSING & VALID Content HEADERS
#=======================================================================
2022-02-27 19:16:16 +01:00
gsl__check_headers() {
echo -ne "\r\033[2K: Searching HEADERS..."
#--------------------------------
# Check if Missing NEEDED HEADERS
2022-02-27 19:16:16 +01:00
#--------------------------------
# Title
2022-02-27 19:16:16 +01:00
echo -ne "\r\033[2K: Searching HEADERS... $gsl_header_title"
gsl__check_needed_headers \
2022-02-27 19:16:16 +01:00
"$gsl_header_title" \
"$gsl_marker_title" \
"POST TITLE"
# Slug
2022-02-27 19:16:16 +01:00
echo -ne "\r\033[2K: Searching HEADERS... $gsl_header_slug"
gsl__check_needed_headers \
2022-02-27 19:16:16 +01:00
"$gsl_header_slug" \
"$gsl_marker_slug" \
"POST-TITLE" \
&& gsl_slug_err=true
# Author
2022-02-27 19:16:16 +01:00
echo -ne "\r\033[2K: Searching HEADERS... $gsl_header_author"
gsl__check_needed_headers \
2022-02-27 19:16:16 +01:00
"$gsl_header_author" \
"$gsl_marker_author" \
"REGISTRED NAME" \
&& gsl_author_err=true
# Date
2022-02-27 19:16:16 +01:00
echo -ne "\r\033[2K: Searching HEADERS... $gsl_header_date"
gsl__check_needed_headers \
2022-02-27 19:16:16 +01:00
"$gsl_header_date" \
"$gsl_marker_date" \
"YYYY-MM-DD" \
&& gsl_date_err=true
# Description
2022-02-27 19:16:16 +01:00
echo -ne "\r\033[2K: Searching HEADERS... ${gsl_header_info:0:40}..."
gsl__check_needed_headers \
2022-02-27 19:16:16 +01:00
"$gsl_header_info" \
"$gsl_marker_info" \
"DESCRIPTION"
# Tags
2022-02-27 19:16:16 +01:00
echo -ne "\r\033[2K: Searching HEADERS... ${gsl_header_tags:0:40}..."
gsl__check_needed_headers \
2022-02-27 19:16:16 +01:00
"$gsl_header_tags" \
"$gsl_marker_tags" \
"TAG1,OTHER TAG2,TAG3"
2022-02-27 19:16:16 +01:00
#--------------------------------
2022-02-14 02:57:58 +01:00
# Check for VALID Content HEADERS
2022-02-27 19:16:16 +01:00
#--------------------------------
# Author registred
2022-02-14 02:57:58 +01:00
if ! [[ "$gsl_author_err" ]] && \
! [[ `grep "$gsl_header_author" "$gsl_file_auth_ndd"` ]];then
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"Header $gsl_marker_author" \
"$gsl_header_author not registred for domain $gsl_find_domain" \
"${PWD}/$gsl_post"
2022-02-14 02:57:58 +01:00
gsl_checker_err=true
2022-02-27 19:16:16 +01:00
fi
# Date Format YYYY-MM-DD
2022-02-14 02:57:58 +01:00
if ! [[ "$gsl_date_err" ]] && \
! [[ "$gsl_header_date" =~ $gsl_test_date ]];then
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"Header $gsl_marker_date" \
"$gsl_header_date not YYYY-MM-DD" \
"${PWD}/$gsl_post"
2022-02-14 02:57:58 +01:00
gsl_checker_err=true
2022-02-27 19:16:16 +01:00
fi
# Slug format title-post
2022-02-14 02:57:58 +01:00
if ! [[ "$gsl_slug_err" ]];then
gsl_header_slug_test=${gsl_header_slug// /-}
if ! [[ "$gsl_header_slug" == "$gsl_header_slug_test" ]];then
2022-02-27 19:16:16 +01:00
2022-02-14 02:57:58 +01:00
gsl_new_header_slug="$gsl_marker_slug$gsl_header_slug_test"
sed -i \
"s|$gsl_marker_slug$gsl_header_slug|$gsl_new_header_slug|" \
2022-02-14 02:57:58 +01:00
"$gsl_post" && \
gsl__logs_print \
"$gsl_log_w" \
"Post" \
"Header $gsl_marker_slug" \
"Changed: $gsl_header_slug_test" \
"${PWD}/$gsl_post"
2022-02-14 02:57:58 +01:00
gsl_header_slug=$gsl_header_slug_test
gsl_checker_war=true
2022-02-27 19:16:16 +01:00
fi
2022-02-14 02:57:58 +01:00
fi
}
#=======================================================================
# Check and count MARKERS content (Strong, links...)
#=======================================================================
gsl__post_check_markers() {
gsl_markers_nbr=$(( ${#gsl_o_markers[@]} - 1 ))
gsl_post_stat_m=(0 0 0 0 0 0)
while read -r "gsl_post_line"
do
gsl_line_nbr=`awk -F":" '{print $1}' <<< $gsl_post_line`
for gsl_i in `seq 0 $gsl_markers_nbr`
do
if [[ "$gsl_post_line" =~ ${gsl_o_markers[gsl_i]} ]];then
# Open Marker by Type
gsl_o=`
grep -o "${gsl_o_markers[gsl_i]}" \
<<< $gsl_post_line \
| wc -l`
# Close Marker by Type
gsl_c=`
grep -o "${gsl_c_markers[gsl_i]}" \
<<< $gsl_post_line \
| wc -l`
# Strong Vs Bold | 2= **_ / 3= *_ in array
if (( $gsl_i == 2 ));then
gsl_oS=$gsl_o # Open Strong marker nbr
gsl_cS=$gsl_c # Close Strong marker nbr
elif (( $gsl_i == 3 ));then
# Count difference from Strong
if (( $gsl_oS ));then
gsl_o=$(( $gsl_o - $gsl_oS ))
unset gsl_oS
fi
if (( $gsl_cS ));then
gsl_c=$(( $gsl_c - $gsl_cS ))
unset gsl_cS
fi
fi
# Compare
if ! (( $gsl_o == $gsl_c ));then
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"${gsl_i_markers[gsl_i]}" \
2022-02-17 17:21:35 +01:00
"Line:$gsl_line_nbr > Mismatch ${gsl_u_markers[gsl_i]}" \
2022-02-14 02:57:58 +01:00
"${PWD}/$gsl_post"
gsl_checker_err=true
else
gsl_post_stat_m[gsl_i]=$(( gsl_post_stat_m[gsl_i] + gsl_o ))
fi
fi
done
done < <(awk -v line="$gsl_post_begin" \
'NR >= line {print NR":",$0}' \
"$gsl_post")
2022-02-17 17:21:35 +01:00
gsl_post_stat_mdb=${gsl_post_stat_m[@]}
2022-02-14 02:57:58 +01:00
# Show Counts in logs
for gsl_i in `seq 0 $gsl_markers_nbr`
do
if (( ${gsl_post_stat_m[gsl_i]} >= 1 ));then
gsl__logs_print \
"$gsl_log_i" \
"Post" \
"${gsl_i_markers[gsl_i]}" \
"NBR=${gsl_post_stat_m[gsl_i]} > ${gsl_u_markers[gsl_i]}" \
"${PWD}/$gsl_post"
fi
done
}
2022-02-17 17:21:35 +01:00
#=======================================================================
# Check for more STATS
#=======================================================================
gsl__post_check_stats() {
2022-02-27 19:16:16 +01:00
gsl_stat_words=`
2022-02-21 17:25:08 +01:00
awk -v l="$gsl_post_begin" \
'NR >= l' \
"$gsl_post" \
| wc -w`
2022-02-17 17:21:35 +01:00
2022-02-27 19:16:16 +01:00
gsl_stat_words=$(( $gsl_stat_words - 2*$gsl_stat_p ))
2022-02-17 17:21:35 +01:00
}