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

147 lines
4.8 KiB
Plaintext
Raw Normal View History

2022-07-20 19:37:21 +02:00
#!/bin/bash
2022-08-24 18:34:46 +02:00
# Version: 0.2.11
2022-07-20 19:37:21 +02:00
# Name: Statique Littérateur
# Type: Executable
2022-08-23 16:48:33 +02:00
# Description: Static website generator
2022-07-20 19:37:21 +02:00
# file: stl
2022-08-23 16:48:33 +02:00
# Folder: /usr/local/bin/
2022-07-20 19:37:21 +02:00
# By echolib (XMPP: im@echolib.re)
# Repo: https://git.a-lec.org/echolib/stl.git
2022-07-20 19:37:21 +02:00
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
2022-08-23 16:48:33 +02:00
#------------
# funny stats
#------------
# scripts files: 14
2022-08-24 18:34:46 +02:00
# app lines: 4715
2022-08-24 12:38:38 +02:00
# app functions: 106
2022-08-23 19:14:41 +02:00
# lines: 146
2022-08-23 16:48:33 +02:00
# functions: 4
#-----------------------------------------------------------------------
#**********************************************************************
2022-07-20 19:37:21 +02:00
#======================================================================
# 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
2022-08-24 12:38:38 +02:00
source) source "$1" ;;
read) cat "$sl" "$1" ;;
2022-07-20 19:37:21 +02:00
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
2022-08-23 16:48:33 +02:00
if__file "$stl_dir_scripts/manage__publish" source
2022-07-20 19:37:21 +02:00
if__file "$stl_dir_scripts/manage__sidebar" source
2022-07-21 16:42:49 +02:00
if__file "$stl_dir_scripts/manage__stats" source
2022-08-23 16:48:33 +02:00
if__file "$stl_dir_scripts/manage__update" source
2022-07-20 19:37:21 +02:00
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
2022-08-24 12:38:38 +02:00
help|-h|--help) if__file "$stl_file_help_args" read;exit ;;
readme) if__file "$stl_dir_help/README.md" read;exit ;;
2022-08-23 19:14:41 +02:00
license) printf '%s %s\n' \
"# GNU AFFERO GENERAL PUBLIC LICENSE" \
2022-08-23 19:14:41 +02:00
"Version 3, 19 November 2007";exit ;;
2022-08-23 16:48:33 +02:00
2022-08-23 19:14:41 +02:00
domain) domain__OPTIONS "$@" ;; # manage__domain
2022-08-23 16:48:33 +02:00
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
2022-07-20 19:37:21 +02:00
2022-08-23 16:48:33 +02:00
update) update__OPTIONS "$@" ;; # manage__update
version|-u|-U) update__OPTIONS "$@" ;; # manage__update
2022-07-20 19:37:21 +02:00
2022-08-23 16:48:33 +02:00
*) noarg "$1" "Use: help, -h" ;;
2022-07-20 19:37:21 +02:00
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"
2022-08-23 16:48:33 +02:00
echo -e "${NC}---│" >> "$stl_file_log"
2022-07-20 19:37:21 +02:00
2022-08-23 16:48:33 +02:00
# Create session logs for specific article
echo -e "${NC}---│" >> "$stl_dir_log/$article_id.log"
2022-07-20 19:37:21 +02:00
# Remove last log session
rm -f "$stl_file_last_log"
exit