#!/bin/bash . $(ffoom path) || exit 3 mkconfpath() { local userd="__SATURNIN_CONFIG_USER__/ini.d" local user="__SATURNIN_CONFIG_USER__" local lcal="__SATURNIN_CONFIG_LOCAL__" local distd="__SATURNIN_SHARE__/ini.d" test -d "$userd" && find -L "$userd" -mindepth 1 -maxdepth 1 -type d echo "$user" echo "$lcal" test -d "$distd" && find -L "$distd" -mindepth 1 -maxdepth 1 -type d } export FFOO_PATH="__SATURNIN_FFOO_DIR__" SATURNIN_LIBEXEC="__SATURNIN_LIBEXEC__" export FFOO_CONFIG_PATH=$(mkconfpath | tr '\n' :) export SATURNIN_VERSION="__VERSION__" export SATURNIN_CACHE_HOME="__SATURNIN_CACHE_HOME__" ffoo import config ffoo import exits 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