git_atom_releases.sh - randomcrap - random crap programs of varying quality
(HTM) git clone git://git.codemadness.org/randomcrap
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
git_atom_releases.sh (2401B)
---
1 #!/bin/sh
2 # Create Atom feeds for releases based on git tag name per repository.
3
4 srcdir="/home/src/src/"
5 # NOTE: appends repo directory and "atom.xml".
6 outputdir="/home/www/domains/www.codemadness.org/htdocs/releases/"
7
8 cd "${srcdir}" || exit 1
9
10 header() {
11 cat <<!__EOF__
12 <?xml version="1.0" encoding="UTF-8"?>
13 <feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
14 <title type="text">$1</title>
15 <subtitle type="text">$2</subtitle>
16 <updated>$(date +%Y-%m-%d)T00:00:00Z</updated>
17
18 !__EOF__
19 }
20
21 formatatom() {
22 LC_ALL=C awk '
23 BEGIN {
24 FS = OFS = "\t";
25 }
26 function escape(s) {
27 gsub("&", "\\&", s);
28 gsub("<", "\\<", s);
29 gsub(">", "\\>", s);
30 gsub("'"'"'", "\\'", s);
31 gsub("\"", "\\"", s);
32 return s;
33 }
34 {
35 author = length($3) ? $3 : $4;
36
37 print "\t<entry>";
38 print "\t\t<title type=\"text\">" escape($2) " " escape($1) "</title>";
39 print "\t\t<updated>" escape($6) "</updated>";
40 print "\t\t<published>" escape($6) "</published>";
41 # link to commit page.
42 print "\t\t<link rel=\"alternate\" type=\"text/plain\" href=\"https://git.codemadness.org/" escape($2) "/commit/" escape($7) ".html\" />";
43 # link to tarball (enclosure).
44 print "\t\t<link rel=\"enclosure\" href=\"https://codemadness.org/releases/" escape($2) "/" escape($2) "-" escape($1) ".tar.gz\" />";
45 print "\t\t<author><name>" escape(author) "</name></author>";
46 print "\t</entry>";
47 }'
48 }
49
50 footer() {
51 cat <<!__EOF__
52 </feed>
53 !__EOF__
54 }
55
56 for d in */; do
57 cd "$d" || exit 1
58
59 n=$(basename "$d")
60 n="${n%.git}" # strip .git suffix
61 # try to use stagit owner file, else use tagger or commit name.
62 owner=$(cat "owner" 2>/dev/null)
63 tmpfile=$(mktemp)
64
65 (header "$n - codemadness.org" "$n releases"
66
67 # just use the day (without time and timezone) of the tag (if available)
68 # or commit.
69 git for-each-ref --format="%(refname) $n $owner "\
70 "%(if)%(taggerdate)%(then)"\
71 "%(taggername) %(taggerdate:unix) %(taggerdate:format:%Y-%m-%dT00:00:00Z)"\
72 "%(else)"\
73 "%(authorname) %(authordate:unix) %(authordate:format:%Y-%m-%dT00:00:00Z)"\
74 "%(end) %(objectname)" 'refs/tags' | \
75 sed 's@^refs/tags/@@' | \
76 sort -t ' ' -k5,5rn | \
77 formatatom
78
79 footer) > "${tmpfile}"
80
81 # there must be at least one entry.
82 if ! grep -F -m 1 -q '<entry>' "${tmpfile}"; then
83 rm "${tmpfile}"
84 cd ../
85 continue
86 fi
87
88 mkdir -p "${outputdir}/${n}"
89 mv "${tmpfile}" "${outputdir}/${n}/atom.xml"
90 chmod 644 "${outputdir}/${n}/atom.xml"
91
92 cd ../
93 done