OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.2 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: lib/sde-package/.../freshmeat2
  6. # Copyright (C) 2009 The OpenSDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- SDE-COPYRIGHT-NOTE-END ---
  15. #Description: Generates .desc files from the data in freshmeat
  16. #Alias: fm2
  17. [ -n "$SDEROOT" ] ||
  18. export SDEROOT=$(cd "${0%/*}/../../../"; pwd -P)
  19. . "$SDEROOT/lib/libsde.in"
  20. new_usage() {
  21. cat <<EOT >&2
  22. Usage: $0 [-u <auth_code>] <name>
  23. get your personal auth_code from <http://freshmeat.net/account/edit>
  24. EOT
  25. exit 2
  26. }
  27. clean_xml() {
  28. sed -e 's,^[ \t]\+,,' |
  29. tr -d '\r\n' |
  30. sed -e 's,>,>\n,' -e 's,\(</[^>]\+>\),\1\n,g' -e 's,>\(<[^/]\),>\n\1,g'
  31. }
  32. fm_exists() {
  33. local uri="http://freshmeat.net/projects/$1"
  34. local response="$(curl -s -I "$uri" | tr -d '\r' | head -n 1)"
  35. if [ "$response" = "" ]; then
  36. echo_error "freshmeat.net unreachable."
  37. elif [ "$response" = "HTTP/1.1 200 OK" ]; then
  38. return 0
  39. elif [ "$response" = "HTTP/1.1 404 Not Found" ]; then
  40. :
  41. else
  42. echo_error "$uri -> $response"
  43. fi
  44. return 1
  45. }
  46. fm_fetch_xml() {
  47. local uri="http://freshmeat.net/projects/$1.xml?auth_code=$2"
  48. curl -s "$uri" | clean_xml
  49. }
  50. fm_parse_xml() {
  51. local l=
  52. while read l; do
  53. tag=$(echo "$l" | sed -e 's,<\([^ >]\+\)[ >].*,\1,' -e 's,/,-,')
  54. value=$(echo "$l" | sed -n -e 's,.*>\([^<]*\)<.*,\1,p')
  55. echo "$tag: $value"
  56. done
  57. }
  58. shortopts='u:'
  59. longopts=
  60. options=$(getopt -o "$shortopts" -l "$longopts" -- "$@")
  61. if [ $? -ne 0 ]; then
  62. new_usage
  63. fi
  64. eval set -- "$options"
  65. authcode=
  66. # load global settings
  67. eval $("$SDEROOT/bin/sde-config-ini" "--file=$SDESETTINGS" freshmeat)
  68. while [ $# -gt 0 ]; do
  69. case "$1" in
  70. --) shift; break ;;
  71. -u) authcode="$2"; shift ;;
  72. esac
  73. shift
  74. done
  75. [ $# -eq 1 -a -n "$authcode" ] || new_usage
  76. name="$1"
  77. if fm_exists "$name"; then
  78. fm_fetch_xml "$name" "$authcode" | fm_parse_xml
  79. else
  80. echo "$name: NOT FOUND"
  81. fi