~rcj/vmbuilder/jenkins_kvm-test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash

fail() { echo "${@}"; exit 1;}

rss_head() {
cat <<EOF
<rss version="2.0">
<channel>
<title></title>
<link>http://cloud-images.ubuntu.com</link>
<description>Ubuntu Cloud Images Feed for ${1}</description>
<lastBuildDate>$(date | sed 's| |, |')</lastBuildDate>
EOF
}

rss_item() {
    ele_date=$(stat /srv/ec2-images/${2} | awk '/Modify/ {print$2" "$3}')
    rss_date=$(date -d "${ele_date}" | sed 's| |, |')
    unpacked_d="/srv/ec2-images/${2}/unpacked"
    pub_d="/srv/ec2-images/${2}"

    [ -e "/srv/ec2-images/${2}/HEADER.html" ] && { 
        cat <<EOF
<item>
    <title>${1}</title>
    <link>http://cloud-images.ubuntu.com/${2}</link>
    <guid>http://cloud-images.ubuntu.com/${2}</guid>
    <pubDate>${rss_date}</pubDate>
EOF
    } || return

    [ -e "${pub_d}/published-ec2-daily.txt" ] &&
        published="${pub_d}/published-ec2-daily.txt"

    [ -e "${pub_d}/published-ec2-release.txt" ] &&
        published="${pub_d}/published-ec2-release.txt"

    amis=$(cat ${published} | grep -v kernel | awk '{print"<br>"$1"\t"$2"\t"$3"\t"$4}')

    changelog=$(find ${unpacked_d}  -iname '${SUITE}-release*-to-daily.changelog' 2> /dev/null)

    [ -n "${changelog}" ] &&
        changelog_text=$(cat ${changelog} | sed ':a;N;$!ba;s|\n|<br>|g')

    cat <<EOF
    <description><![CDATA[<p>${1} Build
EOF

    [ -n "${amis}" ] &&
    cat <<EOF
<p>EC2 Publication Information:
${amis}
EOF

    [ -n "${changelog_text}" ]  &&
    cat <<EOF

<p>Changelog from previous released image:
${changelog_text}
EOF

    cat <<EOF
    ]]></description>
</item>
EOF
}

rss_footer() {
cat <<EOF
</channel>
</rss>
EOF
}
PATH="$(dirname $0):${PATH}"
SUITE="${SUITE:-$1}"
MILESTONE="${MILESTONE:-$2}"

srv_d="${SUITE}"
adj2version=$(which ubuntu-adj2version)
version=$(${adj2version} ${SUITE})

[ "${MILESTONE}" != "daily" ] && srv_d="releases/${SUITE}"

elements=()

[ "${MILESTONE}" == "daily" ] && {
    elements=($(find /srv/ec2-images/${srv_d} -maxdepth 1 -type d | awk -F/ '{print$5}' | grep . | sort)) ||
    fail "Unable to determine serials for inclusion"
    } || {
    elements=($(find /srv/ec2-images/${srv_d} -maxdepth 1 -type d | awk -F/ '{print$6}' | grep . | sort)) ||
    fail "Unable to determine serials for inclusion"
    }

[ "${#elements[@]}" -ge 1 ] ||
    fail "Aborting! No directory contents available!"

{
    rss_head "${version} (${SUITE}) ${MILESTONE}"
    for item in ${elements[@]}; do
        rss_item "${item}" "${srv_d}/${item}"
    done
    rss_footer
} > /srv/ec2-images/rss/${SUITE}-${MILESTONE}.xml