Generates XML manifest of packages for
[build.git] / packages.sh
1 #!/bin/bash
2 #
3 # Generates XML manifest of packages for
4 # http://www.planet-lab.org/Software/download.php
5 #
6 # Mark Huang <mlhuang@cs.princeton.edu>
7 # Copyright (C) 2004 The Trustees of Princeton University
8 #
9 # $Id$
10 #
11
12 xml_escape_pcdata() {
13     # & to &amp;
14     # " to \"
15     # ' to &apos;
16     # < to &lt;
17     # > to &gt;
18     sed \
19         -e 's/\&/\&amp;/g' | sed \
20         -e 's/"/\&quot;/g' \
21         -e "s/'/\&apos;/g" \
22         -e 's/</\&lt;/g' \
23         -e 's/>/\&gt;/g'
24 }
25
26 xml_escape_cdata() {
27     # & to &amp;
28     # \ to \\
29     # " to \"
30     # ' to &apos;
31     # < to &lt;
32     # > to &gt;
33     sed \
34         -e 's/\&/\&amp;/g' \
35         -e 's/\\/\\\\/g' | sed \
36         -e 's/"/\\"/g' \
37         -e "s/'/\&apos;/g" \
38         -e 's/</\&lt;/g' \
39         -e 's/>/\&gt;/g'
40 }
41
42 # All supported tags
43 TAGS=$(rpm --querytags)
44
45 cat <<EOF
46 <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
47 <!-- $Id$ -->
48 <!-- Generated at $(date) in $PWD on $HOSTNAME by $USER -->
49 <!DOCTYPE PACKAGES [
50   <!ELEMENT PACKAGES (PACKAGE)*>
51   <!ELEMENT PACKAGE (#PCDATA)>
52   <!ATTLIST PACKAGE
53 EOF
54
55 # List each tag as an attribute
56 for tag in $TAGS ; do
57
58 cat <<EOF
59   $tag CDATA #REQUIRED
60 EOF
61
62 done
63
64 cat <<EOF
65   >
66 ]>
67 <PACKAGES>
68 EOF
69
70 # For every RPM in the current directory
71 RPMS=$(find ${1-.} -name '*.rpm')
72 for rpm in $RPMS ; do
73
74 cat <<EOF
75   <PACKAGE
76 EOF
77
78     # Use @QUOTE@ instead of " to prevent it from being escaped
79     QUERYFORMAT=
80     for tag in $TAGS ; do
81         QUERYFORMAT="$QUERYFORMAT  $tag=@QUOTE@%{$tag}@QUOTE@\n"
82     done
83
84     # Print the tags
85     rpmquery --queryformat "$QUERYFORMAT" -p $rpm | xml_escape_cdata | sed -e 's/@QUOTE@/"/g'
86
87 # Print the name of the RPM
88 cat <<EOF
89   >
90   $(basename $rpm | xml_escape_pcdata)
91   </PACKAGE>
92 EOF
93
94 done
95
96 cat <<EOF
97 </PACKAGES>
98 EOF