blob: 946494d8d06a65ba92d0c614dec2bd113f540393 [file] [log] [blame]
Brian O'Connor3fad9bc2016-03-01 17:39:09 -08001#!/bin/bash
Brian O'Connord730b222016-03-01 18:32:38 -08002# ----------------------------------------------------
3# Used to update the project's refs/meta/config
4# ----------------------------------------------------
5
6set -e
Brian O'Connor3fad9bc2016-03-01 17:39:09 -08007
8GERRIT_USER=${GERRIT_USER:-$USER}
9GERRIT_PROJECT=${GERRIT_PROJECT:-onos}
10
Brian O'Connor156c4802016-03-02 15:50:38 -080011function setup {
Brian O'Connor3fad9bc2016-03-01 17:39:09 -080012 DIR=$(mktemp -d /tmp/$GERRIT_PROJECT-config.XXXXX) || { echo "Failed to create temp file"; exit 1; }
13 cd $DIR
14 git init
15 git remote add origin ssh://$GERRIT_USER@gerrit.onosproject.org:29418/$GERRIT_PROJECT
16 git fetch origin refs/meta/config:refs/remotes/origin/meta/config
17 git checkout meta/config
18}
19
Brian O'Connor156c4802016-03-02 15:50:38 -080020function cleanup {
Brian O'Connor3fad9bc2016-03-01 17:39:09 -080021 # clean up the directory
Brian O'Connor156c4802016-03-02 15:50:38 -080022 rm -rf $DIR
23}
24
25function testReleaseMembership {
26 trap "echo 'ERROR: Not a member of the ONOS Release group'; cleanup" ERR
27 ssh -p 29418 gerrit.onosproject.org gerrit ls-members "ONOS\ Release" | grep -q $GERRIT_USER
Brian O'Connor3fad9bc2016-03-01 17:39:09 -080028}
29
30setup
31case $1 in
32 block)
Brian O'Connor156c4802016-03-02 15:50:38 -080033 testReleaseMembership
Brian O'Connor3fad9bc2016-03-01 17:39:09 -080034 sed -i '' "s/submit = group/submit = block group/g" project.config
Brian O'Connor156c4802016-03-02 15:50:38 -080035 sed -i '' "s/push = block group ONOS Release/push = group ONOS Release/g" project.config
Brian O'Connor3fad9bc2016-03-01 17:39:09 -080036 git diff
37 git commit -am"Blocking submit for all users in project"
38 git push origin HEAD:refs/meta/config
39 ;;
40 unblock)
Brian O'Connor156c4802016-03-02 15:50:38 -080041 testReleaseMembership
Brian O'Connor3fad9bc2016-03-01 17:39:09 -080042 sed -i '' "s/submit = block group/submit = group/g" project.config
Brian O'Connor156c4802016-03-02 15:50:38 -080043 sed -i '' "s/push = group ONOS Release/push = block group ONOS Release/g" project.config
Brian O'Connor3fad9bc2016-03-01 17:39:09 -080044 git diff
45 git commit -am"Unblocking submit for all users in project"
46 git push origin HEAD:refs/meta/config
47 ;;
48 edit)
49 echo
50 echo "Make your changes now."
51 echo "To push changes, commit them and exit with 0"
52 echo "To abandon changes, do not commit or exit with non-zero value"
53 bash -i && git push origin HEAD:refs/meta/config || echo "ABANDONED CHANGES"
54 ;;
55 *)
56 echo
57 echo "USAGE: onos-edit-config <option>"
58 echo " block: blocks submits for all users in the project"
59 echo " unblock: unblocks submits for all users in the project"
60 echo " edit: allows you to make arbitrary changes to project config"
61esac
62cleanup