|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# Script to make entering and progressing issues easier. |
| 4 | +# |
| 5 | +# The issues are contained in an issues.db file, as a sequence of lines of |
| 6 | +# tab-separated fields: |
| 7 | +# |
| 8 | +# - one-line description |
| 9 | +# - resolution |
| 10 | +# - reference mail thread (preferrably a URL) |
| 11 | +# - raised on (date) |
| 12 | +# - resolved on (date) |
| 13 | +# - specification up-to-date? |
| 14 | +# |
| 15 | + |
| 16 | +ISSUES=`dirname $0`/../issues.db |
| 17 | +HTML=`dirname $0`/../issues.srb |
| 18 | +DATEFRM="+%d %b %Y" |
| 19 | +TMP=${TMPDIR:-/tmp}/issue.$$ |
| 20 | +ARCH=`uname` |
| 21 | + |
| 22 | +pr () |
| 23 | +{ |
| 24 | + if [ $ARCH = "Linux" ]; then |
| 25 | + echo -e "$*" |
| 26 | + else |
| 27 | + echo "$*" |
| 28 | + fi |
| 29 | +} |
| 30 | + |
| 31 | +quick_help () |
| 32 | +{ |
| 33 | + pr |
| 34 | + pr "\tThis program updates issues.db and issues.srb" |
| 35 | + pr |
| 36 | + pr "\tTo see the issues (plain text): issue -l" |
| 37 | + pr "\tTo see the issues (HTML table): issue -g" |
| 38 | + pr "\tTo see the unresolved issues: issue -t" |
| 39 | + pr "\tTo see issues yet to be updated: issue -y" |
| 40 | + pr "\tTo enter a new issue: issue -a [reference [description]]" |
| 41 | + pr "\tTo resolve an issue: issue -r [number [resolution-text]]" |
| 42 | + pr "\tTo mark the spec as up-to-date: issue -u [number]" |
| 43 | + pr "\tTo be prompted for all arguments: issue" |
| 44 | + pr "\tTo get quick help: issue -?" |
| 45 | + pr |
| 46 | + pr "\tYou'll be prompted for all missing arguments" |
| 47 | + pr |
| 48 | +} |
| 49 | + |
| 50 | +list_issues () |
| 51 | +{ |
| 52 | + ( |
| 53 | + IFS=' ' |
| 54 | + num=0 |
| 55 | + while read desc res ref date1 date2 spec; do |
| 56 | + num=`expr $num + 1` |
| 57 | + pr "Number : $num" |
| 58 | + pr "Description : $desc" |
| 59 | + pr "Resolution : $res" |
| 60 | + pr "Reference : $ref" |
| 61 | + pr "Archived on : $date1" |
| 62 | + pr "Resolved on : $date2" |
| 63 | + pr "Spec up-to-date : $spec" |
| 64 | + pr |
| 65 | + done |
| 66 | + ) < $ISSUES |
| 67 | +} |
| 68 | + |
| 69 | +list_unresolved () |
| 70 | +{ |
| 71 | + ( |
| 72 | + IFS=' ' |
| 73 | + num=0 |
| 74 | + while read desc res ref date1 date2 spec; do |
| 75 | + num=`expr $num + 1` |
| 76 | + if [ "$res" = "-" ]; then |
| 77 | + pr "Number : $num" |
| 78 | + pr "Description : $desc" |
| 79 | + pr "Resolution : $res" |
| 80 | + pr "Reference : $ref" |
| 81 | + pr "Archived on : $date1" |
| 82 | + pr "Resolved on : $date2" |
| 83 | + pr "Spec up-to-date : $spec" |
| 84 | + pr |
| 85 | + fi |
| 86 | + done |
| 87 | + ) < $ISSUES |
| 88 | +} |
| 89 | + |
| 90 | +list_to_be_updated () |
| 91 | +{ |
| 92 | + ( |
| 93 | + IFS=' ' |
| 94 | + num=0 |
| 95 | + while read desc res ref date1 date2 spec; do |
| 96 | + num=`expr $num + 1` |
| 97 | + if [ "$spec" = "no" ]; then |
| 98 | + pr "Number : $num" |
| 99 | + pr "Description : $desc" |
| 100 | + pr "Resolution : $res" |
| 101 | + pr "Reference : $ref" |
| 102 | + pr "Archived on : $date1" |
| 103 | + pr "Resolved on : $date2" |
| 104 | + pr "Spec up-to-date : $spec" |
| 105 | + pr |
| 106 | + fi |
| 107 | + done |
| 108 | + ) < $ISSUES |
| 109 | +} |
| 110 | + |
| 111 | +add_issue () |
| 112 | +{ |
| 113 | + if [ -z "$ref" ]; then |
| 114 | + pr "Reference (URL): \c" |
| 115 | + read ref |
| 116 | + fi |
| 117 | + if [ -z "$desc" ]; then |
| 118 | + pr "Description: \c" |
| 119 | + read desc |
| 120 | + fi |
| 121 | + ref=`echo $ref | tr "& " " "` |
| 122 | + desc=`echo $desc | tr "& " " "` |
| 123 | + pr "$desc - $ref "`date "$DATEFRM"`" - no" >>$ISSUES |
| 124 | +} |
| 125 | + |
| 126 | +resolve_issue () |
| 127 | +{ |
| 128 | + if [ -z "$num" ]; then |
| 129 | + pr "Number: \c" |
| 130 | + read num |
| 131 | + fi |
| 132 | + if [ -z "$res" ]; then |
| 133 | + pr "Resolution: \c" |
| 134 | + read res |
| 135 | + fi |
| 136 | + case "$num" in |
| 137 | + [0-9] | [0-9][0-9] | [0-9][0-9][0-9] | [0-9][0-9][0-9][0-9]) ;; |
| 138 | + *) pr "Error: not a valid issue number: $num" >&2; exit 2;; |
| 139 | + esac |
| 140 | + res=`echo $res | tr "& " " "` |
| 141 | + date=`date "$DATEFRM"` |
| 142 | + ( |
| 143 | + IFS=' ' |
| 144 | + i=0 |
| 145 | + while read desc h1 ref date1 h2 spec; do |
| 146 | + i=`expr $i + 1` |
| 147 | + if [ $i = "$num" ]; then |
| 148 | + echo "$desc $res $ref $date1 $date $spec" |
| 149 | + else |
| 150 | + echo "$desc $h1 $ref $date1 $h2 $spec" |
| 151 | + fi |
| 152 | + done < $ISSUES >$TMP |
| 153 | + ) |
| 154 | + mv $TMP $ISSUES |
| 155 | +} |
| 156 | + |
| 157 | +update_issue () |
| 158 | +{ |
| 159 | + if [ -z "$num" ]; then |
| 160 | + pr "Number: \c" |
| 161 | + read num |
| 162 | + fi |
| 163 | + case "$num" in |
| 164 | + [0-9] | [0-9][0-9] | [0-9][0-9][0-9] | [0-9][0-9][0-9][0-9]) ;; |
| 165 | + *) pr "Error: not a valid issue number: $num" >&2; exit 2;; |
| 166 | + esac |
| 167 | + ( |
| 168 | + IFS=' ' |
| 169 | + i=0 |
| 170 | + while read desc res ref date1 date2 spec; do |
| 171 | + i=`expr $i + 1` |
| 172 | + if [ $i != "$num" ]; then |
| 173 | + echo "$desc $res $ref $date1 $date2 $spec" |
| 174 | + elif [ "$ref" = "-" ]; then |
| 175 | + pr "Error: cannot update; the issue must be resolved first" >&2 |
| 176 | + echo "$desc $res $ref $date1 $date2 $spec" |
| 177 | + else |
| 178 | + echo "$desc $res $ref $date1 $date2 yes" |
| 179 | + fi |
| 180 | + done < $ISSUES >$TMP |
| 181 | + ) |
| 182 | + mv $TMP $ISSUES |
| 183 | +} |
| 184 | + |
| 185 | +generate_html () |
| 186 | +{ |
| 187 | + pr "<table border=1>" |
| 188 | + echo "<tr>" |
| 189 | + echo " <th>#" |
| 190 | + echo " <th>Description" |
| 191 | + echo " <th>Resolution" |
| 192 | + echo " <th>Reference" |
| 193 | + echo " <th>Archived on" |
| 194 | + echo " <th>Resolved on" |
| 195 | + echo " <th>Spec up-to-date?" |
| 196 | + ( |
| 197 | + IFS=' ' |
| 198 | + i=0 |
| 199 | + while read desc res ref date1 date2 spec; do |
| 200 | + i=`expr $i + 1` |
| 201 | + echo "<tr valign=baseline>" |
| 202 | + echo " <td>$i" |
| 203 | + echo " <td>$desc" |
| 204 | + echo " <td>$res" |
| 205 | + case "$ref" in |
| 206 | + http:* | ftp:*) echo " <td><a href='$ref'>here</a>";; |
| 207 | + *) echo " <td>$ref";; |
| 208 | + esac |
| 209 | + |
| 210 | + echo " <td>$date1" |
| 211 | + echo " <td>$date2" |
| 212 | + echo " <td>$spec" |
| 213 | + done < $ISSUES |
| 214 | + ) |
| 215 | + pr "</table>" |
| 216 | + pr "<p>Last update: "`ls -l $ISSUES | cut -c 42-47`\ |
| 217 | + " (HTML version generated: "`date "$DATEFRM"`")" |
| 218 | + |
| 219 | +} |
| 220 | + |
| 221 | +interactive () |
| 222 | +{ |
| 223 | + pr "Choose one of:" |
| 224 | + while [ "$reply" = "" ]; do |
| 225 | + pr " l list the issues" |
| 226 | + pr " t list only unresolved issues" |
| 227 | + pr " y list issues to be updated in the spec" |
| 228 | + pr " a add an issue" |
| 229 | + pr " r mark an issue as resolved" |
| 230 | + pr " u mark the spec as up-to-date w.r.t. an issue" |
| 231 | + pr " g generate HTML page with the issues" |
| 232 | + pr " q quit" |
| 233 | + pr "? \c" |
| 234 | + read reply |
| 235 | + case "$reply" in |
| 236 | + l) list_issues;; |
| 237 | + a) add_issue; generate_html >$HTML;; |
| 238 | + r) resolve_issue; generate_html >$HTML;; |
| 239 | + u) update_issue; generate_html >$HTML;; |
| 240 | + g) generate_html;; |
| 241 | + t) list_unresolved;; |
| 242 | + y) list_to_be_updated;; |
| 243 | + q) ;; |
| 244 | + *) pr "Not understood, please try again"; reply=;; |
| 245 | + esac |
| 246 | + done |
| 247 | +} |
| 248 | + |
| 249 | +if [ $# = 0 ]; then |
| 250 | + interactive |
| 251 | +else |
| 252 | + case "$1" in |
| 253 | + -l) list_issues;; |
| 254 | + -a) ref=$2; shift 2; desc="$*"; add_issue; generate_html >$HTML;; |
| 255 | + -r) num=$2; shift 2; res="$*"; resolve_issue; generate_html >$HTML;; |
| 256 | + -u) num=$2; update_issue; generate_html >$HTML;; |
| 257 | + -g) generate_html;; |
| 258 | + -t) list_unresolved;; |
| 259 | + -y) list_to_be_updated;; |
| 260 | + *) quick_help; exit 1;; |
| 261 | + esac |
| 262 | +fi |
| 263 | + |
0 commit comments