upload_supertux_wiki.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #! /bin/bash
  2. # This is a little Shell Script that allows you to upload files to the
  3. # SuperTux MediaWiki. To use it to create a file ~/.supertux-wiki.sh
  4. # and fill it with:
  5. #
  6. # WIKI_USERNAME=""
  7. # WIKI_PASSWORD=""
  8. #
  9. # Then just upload files with:
  10. #
  11. # upload_supertux_wiki.sh your_file.png "Your Description"
  12. #
  13. set -e
  14. function rc_error() {
  15. echo "Create a file ~/.supertux-wiki.sh with the following syntax: "
  16. echo ""
  17. echo "WIKI_USERNAME=\"your_username\""
  18. echo "WIKI_PASSWORD=\"your_password\""
  19. echo ""
  20. exit 1;
  21. }
  22. if [ ! -f ~/.supertux-wiki.sh ]; then
  23. echo "Error: Couldn't find ~/.supertux-wiki.sh"
  24. echo ""
  25. rc_error
  26. fi
  27. source "$HOME/.supertux-wiki.sh"
  28. if [ -z "$WIKI_PASSWORD" -o -z "$WIKI_USERNAME" ]; then
  29. echo "Error: WIKI_PASSWORD or WIKI_USERNAME not set"
  30. echo ""
  31. rc_error
  32. fi
  33. usage="\
  34. Usage: $0 [OPTIONS] FILENAME DESCRIPTION
  35. --overwrite Overwrite a file in the wiki with the same filename
  36. "
  37. if [ ! $# -eq 2 ]; then
  38. if [ $# -eq 3 -a "x$1" = "x--overwrite" ]; then
  39. FILENAME="$2"
  40. DESCRIPTION="$3"
  41. IGNORE_WARNING="-F wpIgnoreWarning=1"
  42. else
  43. echo "${usage}" 1>&2
  44. exit 1
  45. fi
  46. else
  47. FILENAME="$1"
  48. DESCRIPTION="$2"
  49. IGNORE_WARNING=""
  50. fi
  51. if [ ! -r "$FILENAME" ]; then
  52. echo "Error: Can't read $FILENAME"
  53. exit 1
  54. fi
  55. # MD5SUM=`md5sum "$1" | cut -c "1-32"`
  56. # echo "MD5Sum: $MD5SUM"
  57. STEP1_FILE="`tempfile`"
  58. STEP2_FILE="`tempfile`"
  59. COOKIES_FILE="`tempfile`"
  60. curl \
  61. -c "$COOKIES_FILE" \
  62. -F "wpName=$WIKI_USERNAME" \
  63. -F "wpPassword=$WIKI_PASSWORD" \
  64. -F "wpLoginattempt=Log in" \
  65. "http://supertux.lethargik.org/wiki/index.php?title=Special:Userlogin&action=submitlogin&returnto=Main_Page" > "$STEP1_FILE"
  66. curl \
  67. -b "${COOKIES_FILE}" \
  68. -F "wpUploadFile=@${FILENAME}" \
  69. -F "wpUploadDescription=${DESCRIPTION}" \
  70. -F "wpUploadAffirm=1" \
  71. -F "wpUpload='Upload file'" \
  72. $IGNORE_WARNING \
  73. "http://supertux.lethargik.org/wiki/Special:Upload" > "$STEP2_FILE"
  74. echo "------------------------------------------------------------------------"
  75. # links -dump $STEP2_FILE | sed "s/ *Views/## EOF ##/;/## EOF ##/q"
  76. links -dump $STEP2_FILE
  77. rm -f "$STEP1_FILE" "$STEP2_FILE" "$COOKIES_FILE"
  78. WIKI_FILENAME="$(basename "$FILENAME" | sed -n "s/^\(.\).*/\1/p" | tr '[a-z]' '[A-Z]')$(basename "$FILENAME" | sed "s/^.\(.*\)/\1/")"
  79. echo ""
  80. echo "Link to the Image list:"
  81. echo " http://supertux.lethargik.org/wiki/index.php/Special:Imagelist"
  82. echo " "
  83. echo "Link to the Image page:"
  84. echo " http://supertux.lethargik.org/wiki/index.php/Image:${WIKI_FILENAME}"
  85. echo ""
  86. echo "Wiki Link (first without thumbnail, second with):"
  87. echo " [[:Image:$WIKI_FILENAME|$DESCRIPTION]]"
  88. echo " [[Image:$WIKI_FILENAME|$DESCRIPTION]]"
  89. echo ""
  90. # EOF #