#!/bin/bash . $(ffoom path) || exit 3 # # =====BEGIN BUILT PART===== # inigrep_modules() { # # Find existing modules (ini.d sub-folders) # test -d "$1" || return 0 find -L "$1" -mindepth 1 -maxdepth 1 -type d \ | LC_ALL=C sort } inigrep_paths() { # # Assemble list of config paths for FFOO_CONFIG_PATH (path per line) # local userd # user'd modular config (~/.xyz/ini.d) local user # user's generic config local lcal # local admin provided config local distd # distribution-provided config (always modular) userd="__SATURNIN_CONFIG_USER__/ini.d" user="__SATURNIN_CONFIG_USER__" lcal="__SATURNIN_CONFIG_LOCAL__" distd="__SATURNIN_SHARE__/ini.d" inigrep_modules "$userd" echo "$user" echo "$lcal" inigrep_modules "$distd" } export FFOO_PATH FFOO_CONFIG_PATH SATURNIN_VERSION SATURNIN_CACHE_HOME FFOO_CONFIG_PATH="$(inigrep_paths | tr '\n' :)" FFOO_PATH="__SATURNIN_FFOO_DIR__" SATURNIN_CACHE_HOME="__SATURNIN_CACHE_HOME__" SATURNIN_LIBEXEC="__SATURNIN_LIBEXEC__" SATURNIN_VERSION="__VERSION__" # # =====END BUILT PART===== # ffoo import config ffoo import exit ffoo import pretty usage() { usage_is "[-d|-v] command [args...]" \ "help" \ "--version" } print_help() { echo "" echo "built-in sub-commands:" echo "" echo " conf" echo " help" echo "" echo "installed sub-commands:" echo "" find "$SATURNIN_LIBEXEC" \ -mindepth 1 \ -maxdepth 1 \ -executable \ | sed -e 's/.*saturnin-/ /' \ | sort return "$FFOO_EXIT_OK" } version_info() { echo "$(basename $0) (Smart and ready desktop helper) $SATURNIN_VERSION" exit $FFOO_EXIT_OK } run_hook() { inigrep -j -p hook.$SATURNIN_SUBCOMMAND.$1 \ | debug_pipe hook_$1 \ | bash } subcommand() { local sc_es=0 # future exit (return) status local lexpath="$SATURNIN_LIBEXEC/saturnin-$SATURNIN_SUBCOMMAND" debug -v lexpath debug "\$*='$*'" test -x "$lexpath" || { warn "invalid sub-command: $SATURNIN_SUBCOMMAND" print_help return $FFOO_EXIT_USAGE } run_hook pre "$lexpath" "$@" || return $? sc_es=$? run_hook post return $sc_es } while true; do case $1 in -d|--debug) export FFOO_DEBUG=true; shift ;; -v|--verbose) export FFOO_VERBOSE=true; shift ;; --version) version_info ;; --version-semver) echo "$SATURNIN_VERSION"; exit ;; -*) usage; ;; --*) usage; ;; --) shift; break ;; "") usage; ;; *) break; ;; esac done debug -v FFOO_PATH SATURNIN_LIBEXEC FFOO_CONFIG_PATH debug "\$*='$*'" export SATURNIN_SUBCOMMAND="$1" shift case "$SATURNIN_SUBCOMMAND" in conf) inigrep "$@" ;; help) print_help ;; *) subcommand "$@" ;; esac