wikiimg 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/bash
  2. # wikiimg --- Get and put SVG and PNG files to Oddmuse wikis
  3. #
  4. # Copyright (C) 2006 Alex Schroeder <alex@emacswiki.org>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. if [ -z "$2" ]; then
  19. echo Usage:
  20. echo
  21. echo image get PageName -- gets PageName from the wiki and saves
  22. echo it as PageName.svg in the current directory.
  23. echo
  24. echo image put PageName -- saves PageName.svg as PageNameSource
  25. echo and PageName.png as PageNameImage. You are responsible for
  26. echo exporting the SVG file as PNG when you are done.
  27. exit
  28. fi
  29. WIKI=http://www.communitywiki.org/en
  30. USER=`id -un`
  31. WIKIUSER=${WIKIUSER:-USER}
  32. case $1 in
  33. get)
  34. F=`basename "$2" Image`.svg
  35. # make sure both are accepted
  36. IMG=`basename "$2" Image`Image
  37. wget -O $F $WIKI/$IMG
  38. ;;
  39. put)
  40. # make sure all are accepted
  41. PAGE=$2
  42. PAGE=`basename $PAGE .svg`
  43. PAGE=`basename $PAGE .png`
  44. for f in "$PAGE.svg" "$PAGE.png"; do
  45. if [ ! -f "$f" ]; then
  46. echo There is no file called $f
  47. exit
  48. fi
  49. done
  50. wikiupload -u "$WIKIUSER" "$PAGE.png" "$WIKI/${PAGE}Image"
  51. wikiupload -t "image/svg+xml" -u "$WIKIUSER" \
  52. "$PAGE.svg" "$WIKI/${PAGE}Source"
  53. ;;
  54. *)
  55. echo You must use either get or put as first parameter.
  56. exit
  57. esac