saturnin.skel 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/bin/bash
  2. . $(ffoom path) || exit 3
  3. #
  4. # =====BEGIN BUILT PART=====
  5. #
  6. inigrep_modules() {
  7. #
  8. # Find existing modules (ini.d sub-folders)
  9. #
  10. test -d "$1" || return 0
  11. find -L "$1" -mindepth 1 -maxdepth 1 -type d \
  12. | LC_ALL=C sort
  13. }
  14. inigrep_paths() {
  15. #
  16. # Assemble list of config paths for FFOO_CONFIG_PATH (path per line)
  17. #
  18. local userd # user'd modular config (~/.xyz/ini.d)
  19. local user # user's generic config
  20. local lcal # local admin provided config
  21. local distd # distribution-provided config (always modular)
  22. userd="__SATURNIN_CONFIG_USER__/ini.d"
  23. user="__SATURNIN_CONFIG_USER__"
  24. lcal="__SATURNIN_CONFIG_LOCAL__"
  25. distd="__SATURNIN_SHARE__/ini.d"
  26. inigrep_modules "$userd"
  27. echo "$user"
  28. echo "$lcal"
  29. inigrep_modules "$distd"
  30. }
  31. export FFOO_PATH FFOO_CONFIG_PATH SATURNIN_VERSION SATURNIN_CACHE_HOME
  32. FFOO_CONFIG_PATH="$(inigrep_paths | tr '\n' :)"
  33. FFOO_PATH="__SATURNIN_FFOO_DIR__"
  34. SATURNIN_CACHE_HOME="__SATURNIN_CACHE_HOME__"
  35. SATURNIN_LIBEXEC="__SATURNIN_LIBEXEC__"
  36. SATURNIN_VERSION="__VERSION__"
  37. #
  38. # =====END BUILT PART=====
  39. #
  40. ffoo import config
  41. ffoo import exits
  42. ffoo import pretty
  43. usage() {
  44. usage_is "[-d|-v] command [args...]" \
  45. "help" \
  46. "--version"
  47. }
  48. print_help() {
  49. echo ""
  50. echo "built-in sub-commands:"
  51. echo ""
  52. echo " conf"
  53. echo " help"
  54. echo ""
  55. echo "installed sub-commands:"
  56. echo ""
  57. find "$SATURNIN_LIBEXEC" \
  58. -mindepth 1 \
  59. -maxdepth 1 \
  60. -executable \
  61. | sed -e 's/.*saturnin-/ /' \
  62. | sort
  63. return "$FFOO_EXIT_OK"
  64. }
  65. version_info() {
  66. echo "$(basename $0) (Smart and ready desktop helper) $SATURNIN_VERSION"
  67. exit $FFOO_EXIT_OK
  68. }
  69. run_hook() {
  70. inigrep -j -p hook.$SATURNIN_SUBCOMMAND.$1 \
  71. | debug_pipe hook_$1 \
  72. | bash
  73. }
  74. subcommand() {
  75. local sc_es=0 # future exit (return) status
  76. local lexpath="$SATURNIN_LIBEXEC/saturnin-$SATURNIN_SUBCOMMAND"
  77. debug -v lexpath
  78. debug "\$*='$*'"
  79. test -x "$lexpath" || {
  80. warn "invalid sub-command: $SATURNIN_SUBCOMMAND"
  81. print_help
  82. return $FFOO_EXIT_USAGE
  83. }
  84. run_hook pre
  85. "$lexpath" "$@" || return $?
  86. sc_es=$?
  87. run_hook post
  88. return $sc_es
  89. }
  90. while true; do case $1 in
  91. -d|--debug) export FFOO_DEBUG=true; shift ;;
  92. -v|--verbose) export FFOO_VERBOSE=true; shift ;;
  93. --version) version_info ;;
  94. --version-semver) echo "$SATURNIN_VERSION"; exit ;;
  95. -*) usage; ;;
  96. --*) usage; ;;
  97. --) shift; break ;;
  98. "") usage; ;;
  99. *) break; ;;
  100. esac done
  101. debug -v FFOO_PATH SATURNIN_LIBEXEC FFOO_CONFIG_PATH
  102. debug "\$*='$*'"
  103. export SATURNIN_SUBCOMMAND="$1"
  104. shift
  105. case "$SATURNIN_SUBCOMMAND" in
  106. conf) inigrep "$@" ;;
  107. help) print_help ;;
  108. *) subcommand "$@" ;;
  109. esac