stl-statilque-litterateur/usr/local/bin/stl

147 lines
4.8 KiB
Bash
Executable File

#!/bin/bash
# Version: 0.2.11
# Name: Statique Littérateur
# Type: Executable
# Description: Static website generator
# file: stl
# Folder: /usr/local/bin/
# By echolib (XMPP: im@echolib.re)
# Repo: https://git.a-lec.org/echolib/stl.git
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
#------------
# funny stats
#------------
# scripts files: 14
# app lines: 4715
# app functions: 106
# lines: 146
# functions: 4
#-----------------------------------------------------------------------
#**********************************************************************
#======================================================================
# Main Tools functions
#======================================================================
#----------------------------------------------------------------------
# Unknown argument
#----------------------------------------------------------------------
noarg() {
echo "! Invalid argument '$1'. $2"
exit
}
#----------------------------------------------------------------------
# Check if file exists
# $1: file
# $2: Options
#----------------------------------------------------------------------
if__file() {
[[ "$1" ]] || exit
! [[ -f "$1" ]] \
&& echo "! Missing file: $1" \
&& exit
case "$2" in
source) source "$1" ;;
read) cat "$sl" "$1" ;;
esac
}
#----------------------------------------------------------------------
# Check if file or directory is writeable
#----------------------------------------------------------------------
if__folder() {
! [[ -d "$1" ]] \
&& echo "! Missing folder $1" \
&& exit
}
#----------------------------------------------------------------------
# Check if file or directory is writeable
#----------------------------------------------------------------------
if__writeable() {
! [[ -w "$1" ]] \
&& echo "! $1 is not writeable" \
&& exit
}
#======================================================================
# Source dependancies from /scripts
# Confirm not missing directories and files
#======================================================================
if__file "/etc/stl/stl.conf" source # Main Config
if__folder "$stl_dir_help"
if__folder "$stl_dir_scripts"
if__folder "$stl_dir_db"
if__writeable "$stl_dir_db"
if__folder "$stl_dir_log"
if__writeable "$stl_dir_log"
touch "$stl_file_log"
if__file "$stl_dir_scripts/manage__domain" source
if__file "$stl_dir_scripts/manage__articles" source
if__file "$stl_dir_scripts/manage__logs" source
if__file "$stl_dir_scripts/manage__db" source
if__file "$stl_dir_scripts/manage__HTML" source
if__file "$stl_dir_scripts/manage__publish" source
if__file "$stl_dir_scripts/manage__sidebar" source
if__file "$stl_dir_scripts/manage__stats" source
if__file "$stl_dir_scripts/manage__update" source
if__file "$stl_dir_scripts/check__article" source
if__file "$stl_dir_scripts/wip__article" source
#======================================================================
# Analyse Arguments from command line
# Check Options in each dedicated files scripts
#======================================================================
case "$1" in
help|-h|--help) if__file "$stl_file_help_args" read;exit ;;
readme) if__file "$stl_dir_help/README.md" read;exit ;;
license) printf '%s %s\n' \
"# GNU AFFERO GENERAL PUBLIC LICENSE" \
"Version 3, 19 November 2007";exit ;;
domain) domain__OPTIONS "$@" ;; # manage__domain
check) check__OPTIONS "$@" ;; # check__article
wip) wip__OPTIONS "$@" ;; # wip__article
sidebar) sidebar__OPTIONS "$@" ;; # manage__sidebar
publish) publish__OPTIONS "$@" ;; # manage__publish
remove) remove__OPTIONS "$@" ;; # manage__article
read) read__OPTIONS "$@" ;; # manage__articles
edit) edit__OPTIONS "$@" ;; # manage__articles
log) log__OPTIONS "$@" ;; # manage__logs
db) db__OPTIONS "$@" ;; # manage__db
stats) stats__OPTIONS ;; # manage__stats
rss) domain__get;create__RSS_feed ;; # mamage__HTML
update) update__OPTIONS "$@" ;; # manage__update
version|-u|-U) update__OPTIONS "$@" ;; # manage__update
*) noarg "$1" "Use: help, -h" ;;
esac
#======================================================================
# Print & create new logs
#======================================================================
logs__print "$stl_file_last_log" # exit if none
# Create whole logs
cat "$stl_file_last_log" >> "$stl_file_log"
echo -e "${NC}---│" >> "$stl_file_log"
# Create session logs for specific article
echo -e "${NC}---│" >> "$stl_dir_log/$article_id.log"
# Remove last log session
rm -f "$stl_file_last_log"
exit