imapsync_shell_wrapper 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/sh
  2. # $Id: imapsync_shell_wrapper,v 1.6 2020/03/26 22:24:10 gilles Exp gilles $
  3. ## A pure working wrapper is like this one for example:
  4. ## Uncomment the following lines to test it
  5. #/usr/lib/cgi-bin/imapsync
  6. #date
  7. #id
  8. #cal
  9. #exit
  10. ## but the previous is a little useless and uneasy to add extra parameters
  11. ## We need a little extra work.
  12. # Count characters in files, except the \r \n characters
  13. count_chars_but_nl()
  14. {
  15. cat "$@" | tr -d '\r\n' | wc -c
  16. }
  17. # Run imapsync with parameters written in files given in arguments
  18. imapsync_with_extra_param()
  19. {
  20. # Update the environment variable CONTENT_LENGTH
  21. # This update is mandatory or the augmented parameters list will be truncated by imapsync.
  22. CONTENT_LENGTH=`count_chars_but_nl "$@"`
  23. cat "$@" | tr -d '\r\n' | /usr/lib/cgi-bin/imapsync
  24. }
  25. # The actual stuff
  26. # Save the UI parameters in a file
  27. cat > /tmp/imapsync_shell_wrapper_from_ui.txt
  28. # Now run imapsync with the UI parameters and the extra parameters
  29. imapsync_with_extra_param /tmp/imapsync_shell_wrapper_from_ui.txt /tmp/imapsync_shell_wrapper_extra.txt
  30. echo imapsync first run exited with return code $?
  31. echo
  32. who
  33. date
  34. # A second run with other some extra_2 parameters
  35. imapsync_with_extra_param /tmp/imapsync_shell_wrapper_from_ui.txt /tmp/imapsync_shell_wrapper_extra_2.txt
  36. echo imapsync last run exited with return code $?
  37. echo
  38. cal
  39. echo
  40. echo Bye bye
  41. # Got the picture?