wikiimg 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (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, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  19. # 02111-1307, USA.
  20. if [ -z "$2" ]; then
  21. echo Usage:
  22. echo
  23. echo image get PageName -- gets PageName from the wiki and saves
  24. echo it as PageName.svg in the current directory.
  25. echo
  26. echo image put PageName -- saves PageName.svg as PageNameSource
  27. echo and PageName.png as PageNameImage. You are responsible for
  28. echo exporting the SVG file as PNG when you are done.
  29. exit
  30. fi
  31. WIKI=http://www.communitywiki.org/en
  32. USER=`id -un`
  33. WIKIUSER=${WIKIUSER:-USER}
  34. case $1 in
  35. get)
  36. F=`basename "$2" Image`.svg
  37. # make sure both are accepted
  38. IMG=`basename "$2" Image`Image
  39. wget -O $F $WIKI/$IMG
  40. ;;
  41. put)
  42. # make sure all are accepted
  43. PAGE=$2
  44. PAGE=`basename $PAGE .svg`
  45. PAGE=`basename $PAGE .png`
  46. for f in "$PAGE.svg" "$PAGE.png"; do
  47. if [ ! -f "$f" ]; then
  48. echo There is no file called $f
  49. exit
  50. fi
  51. done
  52. wikiupload -u "$WIKIUSER" "$PAGE.png" "$WIKI/${PAGE}Image"
  53. wikiupload -t "image/svg+xml" -u "$WIKIUSER" \
  54. "$PAGE.svg" "$WIKI/${PAGE}Source"
  55. ;;
  56. *)
  57. echo You must use either get or put as first parameter.
  58. exit
  59. esac