summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README13
-rwxr-xr-xrfc.sh233
2 files changed, 182 insertions, 64 deletions
diff --git a/README b/README
index 6d391bb..a4e1e4b 100644
--- a/README
+++ b/README
@@ -1,14 +1,13 @@
-Nagios Gluster Add-ons:
+Nagios Gluster Common:
=======================
-Nagios plugin, scripts, configuration files etc for gluster nodes.
-
+Common libraries, tools, configurations for Gluster node and Nagios
+server add-ons
Installation
============
-The Nagios Gluster Add-ons can be used by following the standard
-autotools installation process, documented in the INSTALL file. As a
-quick start you can do
+This can be used by following the standard autotools installation
+process, documented in the INSTALL file. As a quick start you can do
./configure --prefix=/usr --sysconfdir=/etc \
--localstatedir=/var --libdir=/usr/lib
@@ -18,7 +17,7 @@ quick start you can do
Packaging
=========
-The 'nagios-gluster-addons.spec' file demonstrates how to distribute
+The 'nagios-gluster-common.spec' file demonstrates how to distribute
this as an RPM package.
diff --git a/rfc.sh b/rfc.sh
index fdb22ef..dfbfde0 100755
--- a/rfc.sh
+++ b/rfc.sh
@@ -1,113 +1,232 @@
-#!/bin/sh -e
+#!/bin/bash
+ME=$(basename $0)
-branch="master";
+editormode=0
+askbugid=0
+branch="master"
+dryrun=0
+fetch=1
+topic=""
-set_hooks_commit_msg()
+show_help()
{
- f=".git/hooks/commit-msg";
- u="https://10.70.35.186:8443/tools/hooks/commit-msg";
+ cat 1>&2 <<EOF
+Usage: $ME [OPTION]... [ <REVIEWER> ]...
- if [ -x "$f" ]; then
- return;
- fi
+Options:
+ -a ask for Bug ID addition. This option is set by default for
+ non 'master' branches.
+ -b BRANCH use BRANCH to submitting patch. Default branch is 'master'.
+ -d dry run. Show what command to run.
+ -n do not fetch origin.
+ -t TOPIC use TOPIC to submitting patch.
+ -h display this help text and exit.
- curl -k -o $f $u || wget --no-check-certificate -O $f $u;
- chmod +x .git/hooks/commit-msg;
+By default, BUGID is used as topic in patch submission. If TOPIC and
+BUGID are used together, TOPIC gets used.
- # Let the 'Change-Id: ' header get assigned on first run of rfc.sh
- GIT_EDITOR=true git commit --amend;
-}
+Examples:
+# submit patch to master branch without reviewer
+$ $ME
-is_num()
-{
- local num;
+# submit patch to master branch with reviewer
+$ $ME charlie@example.com
- num="$1";
+# submit patch to release-3.0 branch with topic "awesome feature" and
+# reviewers charlie@example.com alice@example.com
+$ $ME -b release-3.0 -t "awesome feature" charlie@example.com alice@example.com
- [ -z "$(echo $num | sed -e 's/[0-9]//g')" ]
+EOF
}
-rebase_changes()
+is_num()
{
- git fetch origin;
-
- GIT_EDITOR=$0 git rebase -i origin/$branch;
+ test "$1" -eq "$1" 2>/dev/null
}
-editor_mode()
+exit_editor_mode()
{
- if [ $(basename "$1") = "git-rebase-todo" ]; then
- sed 's/^pick /reword /g' "$1" > $1.new && mv $1.new $1;
- return;
+ if [[ "$1" =~ /git-rebase-todo$ ]]; then
+ sed -i 's/^pick /reword /' "$1"
+ exit 0
fi
- if [ $(basename "$1") = "COMMIT_EDITMSG" ]; then
- if grep -qi '^BUG: ' $1; then
- return;
+ if [[ "$1" =~ /COMMIT_EDITMSG$ ]]; then
+ if grep -qi '^BUG:' "$1"; then
+ exit 0
fi
+
+ if [ "$askbugid" -eq 0 ]; then
+ #echo "warning: no Bug ID found" 1>&2
+ exit 0
+ fi
+
while true; do
- echo Commit: "\"$(head -n 1 $1)\""
+ echo "Commit: $(head -n 1 $1)"
echo -n "Enter Bug ID: "
read bug
+
if [ -z "$bug" ]; then
- return;
+ echo -e "ignored adding Bug ID\n" 1>&2
+ exit 0
fi
+
if ! is_num "$bug"; then
- echo "Invalid Bug ID ($bug)!!!";
- continue;
+ echo "invalid Bug ID '$bug'" 1>&2
+ continue
fi
- sed "/^Change-Id:/{p; s/^.*$/BUG: $bug/;}" $1 > $1.new && \
- mv $1.new $1;
- return;
+ echo
+ sed "/^Change-Id:/i BUG: $bug" "$1"
+ exit 0
done
fi
- cat <<EOF
-$0 - editor_mode called on unrecognized file $1 with content:
-$(cat $1)
-EOF
- return 1;
+ exit 1
}
-assert_diverge()
+add_hook_commit_msg()
{
- git diff origin/$branch..HEAD | grep -q .;
+ f=".git/hooks/commit-msg"
+ u="http://review.gluster.org/tools/hooks/commit-msg"
+
+ if [ -x "$f" ]; then
+ return
+ fi
+
+ curl -k -o $f $u || wget --no-check-certificate -O $f $u
+
+ chmod +x .git/hooks/commit-msg
+
+ # Let the 'Change-Id: ' header get assigned on first run of rfc.sh
+ GIT_EDITOR=true git commit --signoff --cleanup=whitespace --amend
}
-main()
+assert_python_check()
{
- set_hooks_commit_msg;
+ pyfiles=$(git diff --name-only origin/$branch..HEAD 2>/dev/null | grep -e '\.py$' -e '\.py\.in$')
+ if [ -z "$pyfiles" ]; then
+ return
+ fi
+ if ! pyflakes $pyfiles; then
+ echo -e "\nPlease clear pyflakes error(s) before submission" 1>&2
+ exit 1
+ fi
+ if ! pep8 -r --show-pep8 $pyfiles; then
+ echo -e "\nPlease clear pep8 error(s) before submission" 1>&2
+ exit 1
+ fi
+}
- if [ -e "$1" ]; then
- editor_mode "$@";
- return;
+
+assert_rebase()
+{
+ if [ "$askbugid" -eq 1 -o "$branch" != "master" ]; then
+ GIT_EDITOR="$0 -E -a" git -c 'commit.status=false' -c 'commit.cleanup=whitespace' rebase -i origin/$branch || exit 2
+ else
+ GIT_EDITOR="$0 -E" git -c 'commit.status=false' -c 'commit.cleanup=whitespace' rebase -i origin/$branch || exit 2
fi
+}
- rebase_changes;
- assert_diverge;
+assert_nochange()
+{
+ if ! git diff origin/$branch..HEAD 2>/dev/null | grep -q .; then
+ echo "No change to submit" 1>&2
+ exit 3
+ fi
+}
- bug=$(git show --format='%b' | grep -i '^BUG: ' | awk '{print $2}');
- if [ "$DRY_RUN" = 1 ]; then
- drier='echo -e Please use the following command to send your commits to review:\n\n'
+main()
+{
+ # A POSIX variable
+ OPTIND=1 # Reset in case getopts has been used previously in the shell.
+
+ while getopts "Eab:dnt:h" opt; do
+ case "$opt" in
+ E)
+ editormode=1
+ ;;
+ a)
+ askbugid=1
+ ;;
+ b)
+ branch=$OPTARG
+ ;;
+ d)
+ dryrun=1
+ ;;
+ n)
+ fetch=0
+ ;;
+ t)
+ topic="$OPTARG"
+ ;;
+ h)
+ show_help
+ exit 0
+ ;;
+ \?)
+ show_help
+ exit -1
+ ;;
+ esac
+ done
+
+ shift $((OPTIND-1))
+
+ [ "$1" = "--" ] && shift
+
+ if [ $editormode -eq 1 ]; then
+ exit_editor_mode "$@"
+ fi
+
+ for i; do
+ if [[ ! "$i" =~ .*@.*\..*$ ]]; then
+ echo "invalid email id: $i" 1>&2
+ show_help
+ exit -1
+ fi
+ done
+
+ ref="HEAD:refs/for/${branch}%"
+
+ if [ $dryrun -eq 1 ]; then
+ drier='echo command: '
else
drier=
fi
- if [ -z "$bug" ]; then
- $drier git push origin HEAD:refs/for/$branch/rfc;
- else
- $drier git push origin HEAD:refs/for/$branch/bug-$bug;
+ if [ -n "$topic" ]; then
+ topic=$(echo $topic | sed 's| |/|g')
+ ref="${ref}topic=$topic,"
+ elif [ -n "$bugid" ]; then
+ ref="${ref}topic=bug-$bugid,"
+ fi
+
+ reviewers=( "$@" )
+ reviewers=$(IFS=,; echo "${reviewers[*]/#/r=}")
+ [ -n "$reviewers" ] && ref="$ref$reviewers"
+
+ add_hook_commit_msg
+ assert_python_check
+ [ $fetch -eq 1 ] && git fetch origin
+ assert_rebase
+ assert_nochange
+
+ $drier git push origin $ref
+
+ if [ -z "$reviewers" ]; then
+ echo -e "\nPatch is submitted without any reviewer. Please add manually"
fi
}