#!/bin/sh
|
|
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
|
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
|
|
#
|
|
# Filename: lib/sde-package/.../freshmeat2
|
|
# Copyright (C) 2009 The OpenSDE Project
|
|
#
|
|
# More information can be found in the files COPYING and README.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; version 2 of the License. A copy of the
|
|
# GNU General Public License can be found in the file COPYING.
|
|
# --- SDE-COPYRIGHT-NOTE-END ---
|
|
|
|
#Description: Generates .desc files from the data in freshmeat
|
|
#Alias: fm2
|
|
|
|
[ -n "$SDEROOT" ] ||
|
|
export SDEROOT=$(cd "${0%/*}/../../../"; pwd -P)
|
|
|
|
. "$SDEROOT/lib/libsde.in"
|
|
|
|
new_usage() {
|
|
cat <<EOT >&2
|
|
Usage: $0 [-u <auth_code>] <name>
|
|
|
|
get your personal auth_code from <http://freshmeat.net/account/edit>
|
|
EOT
|
|
exit 2
|
|
}
|
|
|
|
clean_xml() {
|
|
sed -e 's,^[ \t]\+,,' |
|
|
tr -d '\r\n' |
|
|
sed -e 's,>,>\n,' -e 's,\(</[^>]\+>\),\1\n,g' -e 's,>\(<[^/]\),>\n\1,g'
|
|
}
|
|
|
|
fm_exists() {
|
|
local uri="http://freshmeat.net/projects/$1"
|
|
local response="$(curl -s -I "$uri" | tr -d '\r' | head -n 1)"
|
|
|
|
if [ "$response" = "" ]; then
|
|
echo_error "freshmeat.net unreachable."
|
|
elif [ "$response" = "HTTP/1.1 200 OK" ]; then
|
|
return 0
|
|
elif [ "$response" = "HTTP/1.1 404 Not Found" ]; then
|
|
:
|
|
else
|
|
echo_error "$uri -> $response"
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
fm_fetch_xml() {
|
|
local uri="http://freshmeat.net/projects/$1.xml?auth_code=$2"
|
|
curl -s "$uri" | clean_xml
|
|
}
|
|
|
|
fm_parse_xml() {
|
|
local l=
|
|
while read l; do
|
|
tag=$(echo "$l" | sed -e 's,<\([^ >]\+\)[ >].*,\1,' -e 's,/,-,')
|
|
value=$(echo "$l" | sed -n -e 's,.*>\([^<]*\)<.*,\1,p')
|
|
echo "$tag: $value"
|
|
done
|
|
}
|
|
|
|
shortopts='u:'
|
|
longopts=
|
|
options=$(getopt -o "$shortopts" -l "$longopts" -- "$@")
|
|
if [ $? -ne 0 ]; then
|
|
new_usage
|
|
fi
|
|
eval set -- "$options"
|
|
|
|
authcode=
|
|
# load global settings
|
|
eval $("$SDEROOT/bin/sde-config-ini" "--file=$SDESETTINGS" freshmeat)
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--) shift; break ;;
|
|
|
|
-u) authcode="$2"; shift ;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
[ $# -eq 1 -a -n "$authcode" ] || new_usage
|
|
name="$1"
|
|
|
|
if fm_exists "$name"; then
|
|
fm_fetch_xml "$name" "$authcode" | fm_parse_xml
|
|
else
|
|
echo "$name: NOT FOUND"
|
|
fi
|