My dotfiles. Period.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. . "$(shellfu-get path)" || exit 3
  3. shellfu import pretty
  4. usage() {
  5. mkusage "[options] ACTION" \
  6. -o \
  7. "-c DIR change to DIR before doing anything" \
  8. "-d turn on debugging mode" \
  9. -- \
  10. "imapdomo will try to read .imapdomo/host/HOSTNAME/init.lua and" \
  11. ".imapdomo/host/HOSTNAME/handlers/ACTION.lua, where HOSTNAME is your" \
  12. "short hostname (eg. 'foo' in 'foo.example.com')." \
  13. "" \
  14. "four valid actions are understood; since you must write handler for" \
  15. "each action you want to use, the meanings below are purely a guide:" \
  16. "" \
  17. " newmail - check for and file new mail" \
  18. " rewind - re-add messages from FILTER_FAIL back to FILTER_QUEUE" \
  19. " cleanup - delete or archive old messages" \
  20. " migrate - move mail between mailboxes" \
  21. "" \
  22. "See imapfilter_config(5)) for guide and API reference. Few functions"\
  23. "are also available in .imapdomo/common.lua"
  24. }
  25. mkcmd() {
  26. #
  27. # Compose imapfilter command
  28. #
  29. echo -n "IMAPDOMO_ACTION=$Action"
  30. echo -n " IMAPDOMO_HEADERS=$HeaderDir"
  31. echo -n " IMAPFILTER_HOME=$CfgDir"
  32. echo -n " imapfilter"
  33. if $Debug
  34. then
  35. mkdir -p "$LogDir"
  36. echo -n " -d $LogDir/debug.log"
  37. echo -n " -v"
  38. fi
  39. echo -n " -c $CfgDir/main.lua"
  40. }
  41. main() {
  42. local Action # what to do
  43. local Debug # true if debugging
  44. local cmd # imapfilter command
  45. local CfgDir # config directory
  46. local LogDir # directory to store logs
  47. local HeaderDir # directory to store headers by save_header()
  48. local CdTo # change dir to this before running imapfilter
  49. CfgDir="$HOME/.imapdomo"
  50. LogDir="$HOME/.local/share/imapdomo/logs"
  51. HeaderDir="$HOME/.local/share/imapdomo/headers"
  52. Debug=false
  53. #shellcheck disable=SC2034
  54. while true; do case $1 in
  55. -c) CdTo="$2"; shift 2 || usage ;;
  56. -d) Debug=true; PRETTY_DEBUG=true; shift ;;
  57. -*) usage ;;
  58. *) break ;;
  59. esac done
  60. Action="$1"; shift
  61. grep -qw "$Action" <<< "newmail|rewind|cleanup|migrate" || usage
  62. cmd=$(mkcmd)
  63. debug -v cmd
  64. bash -n <<<"$cmd" || die
  65. if test -n "$CdTo";
  66. then
  67. cd "$CdTo" || die
  68. fi
  69. mkdir -p "$HeaderDir" || die
  70. eval "$cmd"
  71. }
  72. main "$@"