124 lines
4.0 KiB
Bash
Executable File
124 lines
4.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# Version: 0.2.0
|
|
# Name: Statique Littérateur
|
|
# Type: Executable
|
|
# file: stl
|
|
# Folder: /usr/local/bin
|
|
# By echolib (XMPP: im@echolib.re)
|
|
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
|
|
|
|
|
|
#======================================================================
|
|
# 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" || exit ;;
|
|
read) cat -n "$1";exit ;;
|
|
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__sidebar" 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
|
|
domain) domain__OPTIONS "$@" ;; # manage__domain
|
|
help|-h) if__file "$stl_file_help_args" read;exit ;;
|
|
readme) if__file "$stl_dir_help/README.md" read;exit ;;
|
|
|
|
check) check__OPTIONS "$@" ;; # check__article
|
|
wip) wip__OPTIONS "$@" ;; # wip__article
|
|
sidebar) sidebar__OPTIONS "$@" ;; # manage__sidebar
|
|
rss) domain__get;create__RSS_feed ;; # mamage__HTML
|
|
sync) sync_wip_to_www ;; # manage__HTML
|
|
|
|
read) read__OPTIONS "$@" ;; # manage__articles
|
|
edit) edit__OPTIONS "$@" ;; # manage__articles
|
|
log) log__OPTIONS "$@" ;; # manage__articles
|
|
db) db__OPTIONS "$@" ;; # manage__db
|
|
*) noarg "$1" ;;
|
|
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 "---\t" >> "$stl_file_log"
|
|
|
|
# Create logs for specific article
|
|
cat "$stl_file_last_log" >> "$stl_dir_log/$article_id.log"
|
|
echo -e "---\t" >> "$stl_dir_log/$article_id.log"
|
|
|
|
# Remove last log session
|
|
rm -f "$stl_file_last_log"
|
|
|
|
exit
|