From e90bc42dffcb92049fecf17a656474890c45330a Mon Sep 17 00:00:00 2001 From: Martin Roth Date: Tue, 24 Jan 2017 21:13:18 -0700 Subject: [PATCH] UPSTREAM: board_status/to-wiki: Update bucketize script - Fix TODO: restrict $1 to allowed values. - Specifically exclude 'oem' board status directories. - Exclude any directory that doesn't follow the date format to keep the script from breaking again in the future if something it doesn't recognize is pushed. Just ignore it for the wiki. - Fix shellcheck warnings. BUG=none BRANCH=none TEST=none Change-Id: I55cee2d8a6fc1a605d77f6cc6d9eb9e2defa4872 Signed-off-by: Patrick Georgi Original-Commit-Id: 27f3ce6337b293cfc7be0eb8592feb411cf2cc5f Original-Change-Id: I2864f09f5f1b1f5ec626d06e4849830400ef5814 Original-Signed-off-by: Martin Roth Original-Reviewed-on: https://review.coreboot.org/18225 Original-Tested-by: build bot (Jenkins) Original-Reviewed-by: Timothy Pearson Original-Reviewed-by: Patrick Georgi Original-Reviewed-by: Paul Menzel Reviewed-on: https://chromium-review.googlesource.com/433884 --- util/board_status/to-wiki/bucketize.sh | 28 ++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/util/board_status/to-wiki/bucketize.sh b/util/board_status/to-wiki/bucketize.sh index 78906fdd67..cb643e73bc 100755 --- a/util/board_status/to-wiki/bucketize.sh +++ b/util/board_status/to-wiki/bucketize.sh @@ -4,30 +4,42 @@ # into buckets of the given granularity weekly() { - date --date="$1" +%GW%V + date --date="$1" +%GW%V 2>/dev/null + return $? } monthly() { - date --date="$1" +%Y-%m + date --date="$1" +%Y-%m 2>/dev/null + return $? } quarterly() { - date --date="$1" "+%Y %m" | awk '{ q=int(($2-1)/3+1); print $1 "Q" q}' + date --date="$1" "+%Y %m" 2>/dev/null | awk '{ q=int(($2-1)/3+1); print $1 "Q" q}' + return $? } -# TODO: restrict $1 to allowed values +# Restrict $1 to allowed values +if [ "$1" != "weekly" ] && [ "$1" != "monthly" ] && [ "$1" != "quarterly" ]; then + exit 1 +fi curr="" sort -r -k4 -t/ | while read file; do - timestamp=`printf $file | cut -d/ -f4 | tr _ :` - new=`$1 $timestamp` + # Exclude 'oem' directories + if echo "$file" | grep -q '/oem/'; then continue; fi + timestamp=$(printf "%s" "$file" | cut -d/ -f4 | tr _ :) + + # If the directory is not a date, skip it. + new=$($1 "$timestamp");retval=$? + if [ "$retval" != "0" ]; then continue; fi + if [ "$new" != "$curr" ]; then if [ "$curr" != "" ]; then printf "\n" fi - printf "$new:" + printf "%s:" "$new" curr=$new fi - printf "$file " + printf "%s " "$file" done printf "\n"