Dash:
[t2-trunk.git] / misc / archive / AuditBuild.sh
blob48a3190ed32042a7ebf1da4734ead362271e0a1a
1 #!/bin/sh
2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 #
5 # T2 SDE: misc/archive/AuditBuild.sh
6 # Copyright (C) 2004 - 2005 The T2 SDE Project
7 #
8 # More information can be found in the files COPYING and README.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- T2-COPYRIGHT-NOTE-END ---
16 MATRIX=http://www.t2-project.org/packages
18 config=default
19 enabled='X'
20 repositories=
21 VERBOSE=
22 HTMLDIR=
23 root=
25 show_usage() {
26 cat<<-EOT
27 usage: $0 [-v] [-cfg <config>] [--no-enabled-too] [-repository <repositories>]
28 EOT
31 while [ $# -gt 0 ]; do
32 case "$1" in
33 -cfg) config="$2"; shift ;;
34 -v) VERBOSE=1 ;;
35 -w) HTMLDIR="$2"; shift ;;
36 --help) show_usage; exit 1 ;;
37 -R) root="$2"; shift ;;
38 --no-enabled-too)
39 enabled=. ;;
40 -repository)
41 shift; repositories="$*"
42 break ;;
43 *) show_usage; exit 2 ;;
44 esac
45 shift
46 done
48 if [ ! -f config/$config/packages ]; then
49 echo "ERROR: '$config' is not a valid config"
50 exit 1
53 eval `grep 'SDECFG_ID=' config/$config/config 2> /dev/null`
54 if [ "$root" ]; then
55 LOGSDIR=$root/var/adm/logs
56 else
57 LOGSDIR=build/$SDECFG_ID/var/adm/logs
59 if [ -z "$SDECFG_ID" -o ! -d $LOGSDIR ]; then
60 echo "ERROR: 'build/$SDECFG_ID/' is not a valid build root (sandbox)"
61 exit 1
64 if [ "$HTMLDIR" ]; then
65 mkdir -p $HTMLDIR/$config.$$/{diff,log}
68 expand_stages() {
69 local array="$1" stage=
70 while [ "$array" ]; do
71 stage=${array:0:1}
72 array=${array:1}
73 if [ "$stage" != "-" ]; then
74 echo -n "$stage "
76 done
79 audit_package() {
80 local pkg="$1" repo="$2" ver="$3" enabled="$4"
81 local stages= svndiff= oldver= newver= lchanges= stage=
82 local svnst= lstatus= lbuild= file=
83 shift 4; stages="$*"
85 svnst=`svn st package/$repo/$pkg`
86 if [ "$svnst" ]; then
87 svndiff=`svn diff package/$repo/$pkg`
88 if [ "$svndiff" ]; then
89 lchanges="CHANGED"
90 oldver=`echo "$svndiff" | grep '^-\[V\]' | cut -d' ' -f2`
91 newver=`echo "$svndiff" | grep '^+\[V\]' | cut -d' ' -f2`
93 if [ "$oldver" ]; then
94 ver="$oldver -> $newver"
95 lchanges="UPDATED"
96 elif [ "$newver" ]; then
97 lchanges="ADDED"
100 if [ "$HTMLDIR" ]; then
102 echo "$svnst"
103 echo ""
104 echo "$svndiff"
105 } > $HTMLDIR/$config.$$/diff/$pkg.diff.txt
106 lchanges="<a href=\"diff/$pkg.diff.txt\">$lchanges</a>"
110 if [ "$enabled" == "O" ]; then
111 for stage in $stages; do
112 lbuild="$lbuild NO($stage)"
113 done
114 lstatus=3
115 else
116 for stage in $stages; do
117 file=`ls -1 $LOGSDIR/$stage-$pkg.{err,log,out} 2> /dev/null`
118 lstatus=
119 if [ "$file" ]; then
120 case "$file" in
121 *.log) [ "$lstatus" ] || lstatus=1
122 lbuild="$lbuild OK($stage)" ;;
123 *.out) [ "$lstatus" != "2" ] || lstatus=0
124 lbuild="$lbuild NO($stage)" ;;
125 *) lstatus=2
126 if [ "$HTMLDIR" ]; then
127 lbuild="$lbuild <a href=\"log/$stage-$pkg.err.txt\">ERR($stage)</a>"
128 cp $file $HTMLDIR/$config.$$/log/$stage-$pkg.err.txt
129 else
130 lbuild="$lbuild ERR($stage)"
131 fi ;;
132 esac
133 else
134 lbuild="$lbuild NO($stage)"
135 [ "$lstatus" ] || lstatus=0
137 done
139 case "$lstatus" in
140 3) lstatus=DISABLED ;;
141 2) lstatus=FAILED ;;
142 1) lstatus=SUCCESSFUL ;;
143 *) lstatus=PENDING ;;
144 esac
145 if [ "$HTMLDIR" ]; then
146 cat <<EOT
147 <tr><td>package/$repo/<a href="$MATRIX/$pkg.html" name="$pkg">$pkg</a></td><td>$lchanges</td><td>(${ver//>/&gt;})</td><td>$lbuild</td><td>$lstatus</td></tr>
149 else
150 echo -e "package/$repo/$pkg\t$lchanges\t($ver)\t$lbuild\t$lstatus"
154 if [ "$HTMLDIR" ]; then
155 cat <<EOT
156 <html>
157 <head><title>Audit Build $config over revision $( svn info | grep Revision | cut -d' ' -f2 )</title>
158 <body>
159 $( [ "$repositories" ] && echo "<h3>$repositories</h3>" )
160 <table><tr>
161 <th>Package</th>
162 <th>SVN Status</th>
163 <th>Version</th>
164 <th>Build Status</th>
165 <th>Result</th>
166 </tr>
170 if [ "$repositories" ]; then
171 for repo in $repositories; do
172 repo=${repo#package/}; repo=${repo%/}
173 if [ -d package/$repo/ ]; then
174 grep -e "^$enabled.* $repo " config/$config/packages | while \
175 read e stages x repo pkg ver x; do
176 audit_package $pkg $repo $ver $e `expand_stages $stages`
177 done
179 done
180 else
181 grep -e "^$enabled" config/$config/packages | while \
182 read e stages x repo pkg ver x; do
183 audit_package $pkg $repo $ver $e `expand_stages $stages`
184 done
187 if [ "$HTMLDIR" ]; then
188 echo "<body><html>"
190 if [ -d "$HTMLDIR/$config" ]; then
191 mv $HTMLDIR/$config $HTMLDIR/$config.$$-old
193 mv $HTMLDIR/$config.$$ $HTMLDIR/$config/
194 rm -rf $HTMLDIR/$config.$$-old