saturnin.skel 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_INIGREP_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_INIGREP_PATH FFOO_PATH FFOO_PRETTY_USAGE \
  32. SATURNIN_VERSION SATURNIN_CACHE_HOME
  33. FFOO_INIGREP_PATH="$(inigrep_paths | tr '\n' :)"
  34. FFOO_PATH="__SATURNIN_FFOO_DIR__"
  35. FFOO_PRETTY_USAGE="subcommand"
  36. SATURNIN_CACHE_HOME="__SATURNIN_CACHE_HOME__"
  37. SATURNIN_LIBEXEC="__SATURNIN_LIBEXEC__"
  38. SATURNIN_VERSION="__VERSION__"
  39. #
  40. # =====END BUILT PART=====
  41. #
  42. ffoo import exit
  43. ffoo import inigrep
  44. ffoo import pretty
  45. usage() {
  46. usage_is "[-d|-v] command [args...]" \
  47. "help" \
  48. "--version"
  49. }
  50. print_help() {
  51. echo ""
  52. echo "built-in sub-commands:"
  53. echo ""
  54. echo " conf"
  55. echo " help"
  56. echo ""
  57. echo "installed sub-commands:"
  58. echo ""
  59. ls_subcommands | sed -e 's/^/ /'
  60. return "$FFOO_EXIT_OK"
  61. }
  62. ls_subcommands() {
  63. find "$SATURNIN_LIBEXEC" \
  64. -mindepth 1 \
  65. -maxdepth 1 \
  66. -executable \
  67. | sed -e 's/.*saturnin-//' \
  68. | sort
  69. }
  70. version_info() {
  71. echo "$(basename $0) (Smart and ready desktop helper) $SATURNIN_VERSION"
  72. exit $FFOO_EXIT_OK
  73. }
  74. run_hook() {
  75. inigrep -j -p hook.$SATURNIN_SUBCOMMAND.$1 \
  76. | debug_pipe hook_$1 \
  77. | bash
  78. }
  79. subcommand() {
  80. local sc_es=0 # future exit (return) status
  81. local lexpath="$SATURNIN_LIBEXEC/saturnin-$SATURNIN_SUBCOMMAND"
  82. debug -v lexpath
  83. debug "\$*='$*'"
  84. test -x "$lexpath" || {
  85. warn "invalid sub-command: $SATURNIN_SUBCOMMAND"
  86. print_help
  87. return $FFOO_EXIT_USAGE
  88. }
  89. run_hook pre
  90. "$lexpath" "$@" || return $?
  91. sc_es=$?
  92. run_hook post
  93. return $sc_es
  94. }
  95. while true; do case $1 in
  96. -d|--debug) export FFOO_DEBUG=true; shift ;;
  97. -v|--verbose) export FFOO_VERBOSE=true; shift ;;
  98. --version) version_info ;;
  99. --version-semver) echo "$SATURNIN_VERSION"; exit ;;
  100. -*) usage; ;;
  101. --*) usage; ;;
  102. --) shift; break ;;
  103. "") usage; ;;
  104. *) break; ;;
  105. esac done
  106. debug -v FFOO_PATH SATURNIN_LIBEXEC FFOO_INIGREP_PATH
  107. debug "\$*='$*'"
  108. export SATURNIN_SUBCOMMAND="$1"
  109. shift
  110. case "$SATURNIN_SUBCOMMAND" in
  111. conf) inigrep "$@" ;;
  112. help) print_help ;;
  113. _ls_subcommands) ls_subcommands ;;
  114. *) subcommand "$@" ;;
  115. esac