saturnin.skel 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. . $(ffoom path) || exit 3
  3. mkconfpath() {
  4. local userd="__SATURNIN_CONFIG_USER__/ini.d"
  5. local user="__SATURNIN_CONFIG_USER__"
  6. local lcal="__SATURNIN_CONFIG_LOCAL__"
  7. local distd="__SATURNIN_SHARE__/ini.d"
  8. test -d "$userd" && find -L "$userd" -mindepth 1 -maxdepth 1 -type d
  9. echo "$user"
  10. echo "$lcal"
  11. test -d "$distd" && find -L "$distd" -mindepth 1 -maxdepth 1 -type d
  12. }
  13. export FFOO_PATH="__SATURNIN_SHARE__/ffoo"
  14. SATURNIN_LIBEXEC="__SATURNIN_LIBEXEC__"
  15. export FFOO_CONFIG_PATH=$(mkconfpath | tr '\n' :)
  16. export SATURNIN_VERSION="__VERSION__"
  17. export SATURNIN_CACHE_HOME="__SATURNIN_CACHE_HOME__"
  18. ffoo import config
  19. ffoo import exits
  20. ffoo import pretty
  21. usage() {
  22. usage_is "[-d|-v] command [args...]" \
  23. "help" \
  24. "--version"
  25. }
  26. print_help() {
  27. echo ""
  28. echo "built-in sub-commands:"
  29. echo ""
  30. echo " conf"
  31. echo " help"
  32. echo ""
  33. echo "installed sub-commands:"
  34. echo ""
  35. find "$SATURNIN_LIBEXEC" \
  36. -mindepth 1 \
  37. -maxdepth 1 \
  38. -executable \
  39. | sed -e 's/.*saturnin-/ /' \
  40. | sort
  41. return "$FFOO_EXIT_OK"
  42. }
  43. version_info() {
  44. echo "$(basename $0) (Smart and ready desktop helper) $SATURNIN_VERSION"
  45. exit $FFOO_EXIT_OK
  46. }
  47. run_hook() {
  48. inigrep -j -p hook.$SATURNIN_SUBCOMMAND.$1 \
  49. | debug_pipe hook_$1 \
  50. | bash
  51. }
  52. subcommand() {
  53. local sc_es=0 # future exit (return) status
  54. local lexpath="$SATURNIN_LIBEXEC/saturnin-$SATURNIN_SUBCOMMAND"
  55. debug -v lexpath
  56. debug "\$*='$*'"
  57. test -x "$lexpath" || {
  58. warn "invalid sub-command: $SATURNIN_SUBCOMMAND"
  59. print_help
  60. return $FFOO_EXIT_USAGE
  61. }
  62. run_hook pre
  63. "$lexpath" "$@" || return $?
  64. sc_es=$?
  65. run_hook post
  66. return $sc_es
  67. }
  68. while true; do case $1 in
  69. -d|--debug) export FFOO_DEBUG=true; shift ;;
  70. -v|--verbose) export FFOO_VERBOSE=true; shift ;;
  71. --version) version_info ;;
  72. --version-semver) echo "$SATURNIN_VERSION"; exit ;;
  73. -*) usage; ;;
  74. --*) usage; ;;
  75. --) shift; break ;;
  76. "") usage; ;;
  77. *) break; ;;
  78. esac done
  79. debug -v FFOO_PATH SATURNIN_LIBEXEC FFOO_CONFIG_PATH
  80. debug "\$*='$*'"
  81. export SATURNIN_SUBCOMMAND="$1"
  82. shift
  83. case "$SATURNIN_SUBCOMMAND" in
  84. conf) inigrep "$@" ;;
  85. help) print_help ;;
  86. *) subcommand "$@" ;;
  87. esac