123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- #!/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_INIGREP_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_INIGREP_PATH FFOO_PATH FFOO_PRETTY_USAGE \
- SATURNIN_VERSION SATURNIN_CACHE_HOME
-
- FFOO_INIGREP_PATH="$(inigrep_paths | tr '\n' :)"
- FFOO_PATH="__SATURNIN_FFOO_DIR__"
- FFOO_PRETTY_USAGE="subcommand"
- SATURNIN_CACHE_HOME="__SATURNIN_CACHE_HOME__"
- SATURNIN_LIBEXEC="__SATURNIN_LIBEXEC__"
- SATURNIN_VERSION="__VERSION__"
-
- #
- # =====END BUILT PART=====
- #
-
- ffoo import exit
- ffoo import inigrep
- 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 ""
- ls_subcommands | sed -e 's/^/ /'
- return "$FFOO_EXIT_OK"
- }
-
- ls_subcommands() {
- find "$SATURNIN_LIBEXEC" \
- -mindepth 1 \
- -maxdepth 1 \
- -executable \
- | sed -e 's/.*saturnin-//' \
- | sort
- }
-
- 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_INIGREP_PATH
- debug "\$*='$*'"
-
- export SATURNIN_SUBCOMMAND="$1"
- shift
-
- case "$SATURNIN_SUBCOMMAND" in
- conf) inigrep "$@" ;;
- help) print_help ;;
- _ls_subcommands) ls_subcommands ;;
- *) subcommand "$@" ;;
- esac
|