#!/bin/bash # Version: 0.1.10 # file: gsl # Folder: /usr/local/bin # By echolib (XMPP: im@echolib.re) # License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 #======================================================================= # Tools #======================================================================= if__command() { ! [[ `command -v $1` ]] \ && echo -e "$I_Red Missing $1 command" \ && exit } if__file() { if ! [[ -f "$1" ]];then echo "! Missing file: $1" exit fi case "$2" in source) source "$1" || exit ;; read) clear;cat "$1";exit ;; post) gsl_this_post="$1" ;; esac } if__folder() { if ! [[ -d "$1" ]];then echo "! Missing directory: $1" exit fi } gsl__invalid_option() { echo "! Invalid argument '$1': $2" exit } #====================================================================== # Source files for help #====================================================================== source__help() { for file_help in ${gsl_files_help[@]} do if [[ -f "$file_help" ]];then [[ "$file_help" == "$gsl_dir_help/gsl__help" ]] \ && source "$file_help" else echo "! Installation Failure. Missing file: $file_help" exit fi done } #====================================================================== # Helper # $1: arguments list from help #====================================================================== help__OPTIONS() { clear case "$1" in write|-w) cat "$gsl_dir_help/comment_ecrire-article.md" ;; tpl|-T) cat "$gsl_dir_help/template-comment-creer.md" ;; install|-i) cat "$gsl_dir_help/comment_installer-GSL.md" ;; authors|-a) cat "$gsl_dir_help/how-to_add_remove_authors.md" ;; setdir|-d) cat "$gsl_dir_help/how-to_set_directory_for_articles.md" ;; param|-p) cat "$gsl_dir_help/how-to_parameters_conf.md" ;; css) cat "$gsl_dir_help/how-to_CSS_classes.md" ;; tips|-t) cat "$gsl_dir_help/how-to_Tips_Advises.md" ;; ""|*) cat "$gsl_dir_help/gsl_help.md" ;; esac exit } #====================================================================== # Get CONF and source variables #====================================================================== if__file "/etc/gsl/gsl.conf" source #====================================================================== # Check installation and source files #====================================================================== for dir in ${gsl_dirs[@]} do ! [[ -d "$dir" ]] \ && echo "! Installation Failure. Missing directory: $dir" \ && exit done for file_script in ${gsl_files_scripts[@]} do if [[ -f "$file_script" ]];then source "$file_script" else echo "! Installation Failure. Missing file: $file_help" exit fi done for dir_w in ${gsl_dirs_w[@]} do if ! [[ -w "$dir_w" ]];then echo "! Installation Failure. Directory not writeable: $dir_w" exit fi done #======================================================================= # Check ARGUMENTS #======================================================================= case "$1" in new|-N) new__OPTIONS "$2" "$3" ;; author|-A) author__OPTIONS "$2" ;; log|-L) log__OPTIONS "$@" ;; -v|-vv|--version) version__OPTIONS "$1" ;; readme) if__file "$gsl_dir_lib/README.md" read ;; setdir|-D) setdir__OPTIONS ;; help|--help|-h) source__help;help__OPTIONS "$2" ;; esac # Check if registred DOMAIn and authors from PWD domain__check author__check || exit 0 # Check if authors registresd case "$1" in db) db__OPTIONS "$2" ;; sync|-s) sync__OPTIONS "$2" ;; edit|-E) edit__file_OPTIONS "$2" "$3" ;; esac if__gsl_post # from gsl__post_manager: check if .gsl case "$1" in db|sync|-s|edit|-E) true ;; check|-C) check__OPTIONS "$@" ;; make|-M) make__OPTIONS "$@" ;; sidebar|-S) sidebar__OPTIONS "$2" "$3" "$4" ;; www) srv__OPTIONS "$1" "$2" "$3" ;; wip) srv__OPTIONS "$1" "$2" "$3" ;; stats) stats__datas;exit ;; *) gsl__invalid_option "$1" "See help argument";exit ;; esac #====================================================================== # After process, show logs #====================================================================== gsl_logs_last_session=true [[ $gsl_log_order ]] \ && gsl__logs_show \ && exit gsl_logs_inf=true gsl__logs_show if [[ "$gsl_checker_war" ]];then echo gsl_logs_war=true gsl__logs_show fi if [[ "$gsl_checker_err" ]];then echo gsl_logs_err=true gsl__logs_show fi exit