#!/bin/sh
fget()
{
fetch -q --no-verify-peer -o - "https://bugs.freebsd.org/bugzilla/jsonrpc.cgi?method=Bug.attachments¶ms=[{\"ids\": [\"$1\"]}]"
}
patch=$1
res=$(fget $patch)
error=$(echo $res | jshon -e error -t)
if [ $error = "object" ]; then
echo $res | jshon -e error -e message
exit 1
fi
nbattach=$(echo $res | jshon -e result -e bugs -e $patch -l)
if [ $nbattach -eq 0 ]; then
echo "No attachement found for #$patch"
exit 1
fi
i=0
while [ $i -lt $nbattach ]; do
obsolete=$(echo $res | jshon -e result -e bugs -e $patch -e $i -e is_obsolete)
if [ $obsolete -eq 1 ]; then
continue
fi
filename=$(echo $res | jshon -e result -e bugs -e $patch -e $i -e file_name -u)
data=$(echo $res | jshon -e result -e bugs -e $patch -e $i -e data -u)
echo "Creating $filename"
echo "${data}==" | b64decode -r > $filename
i=$(($i + 1))
done