saturnin.skel 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 exits
  19. ffoo import pretty
  20. usage() {
  21. usage_is "[-d|-v] command [args...]" \
  22. "help" \
  23. "--version"
  24. }
  25. print_help() {
  26. echo ""
  27. echo "valid sub-commands:"
  28. echo ""
  29. find "$SATURNIN_LIBEXEC" \
  30. -mindepth 1 \
  31. -maxdepth 1 \
  32. -executable \
  33. | sed -e 's/.*saturnin-/ /' \
  34. | sort
  35. return "$FFOO_EXIT_OK"
  36. }
  37. version_info() {
  38. echo "$(basename $0) (Smart and ready desktop helper) $SATURNIN_VERSION"
  39. exit $FFOO_EXIT_OK
  40. }
  41. while true; do case $1 in
  42. -d|--debug) export FFOO_DEBUG=true; shift ;;
  43. -v|--verbose) export FFOO_VERBOSE=true; shift ;;
  44. --version) version_info ;;
  45. --version-semver) echo "$SATURNIN_VERSION"; exit ;;
  46. -*) usage; ;;
  47. --*) usage; ;;
  48. --) shift; break ;;
  49. "") usage; ;;
  50. *) break; ;;
  51. esac done
  52. debug -v FFOO_PATH SATURNIN_LIBEXEC FFOO_CONFIG_PATH
  53. debug "\$*='$*'"
  54. SATURNIN_SUBCOMMAND="$1"
  55. shift
  56. case "$SATURNIN_SUBCOMMAND" in
  57. help) print_help; exit $FFOO_EXIT_OK ;;
  58. *)
  59. lexpath="$SATURNIN_LIBEXEC/saturnin-$SATURNIN_SUBCOMMAND"
  60. debug -v lexpath
  61. debug "\$*='$*'"
  62. test -x "$lexpath" && exec "$lexpath" "$@"
  63. warn "invalid sub-command: $SATURNIN_SUBCOMMAND"
  64. print_help; exit $FFOO_EXIT_USAGE
  65. ;;
  66. esac