Brian O'Connor | 3fad9bc | 2016-03-01 17:39:09 -0800 | [diff] [blame] | 1 | #!/bin/bash |
Brian O'Connor | d730b22 | 2016-03-01 18:32:38 -0800 | [diff] [blame] | 2 | # ---------------------------------------------------- |
| 3 | # Used to update the project's refs/meta/config |
| 4 | # ---------------------------------------------------- |
| 5 | |
| 6 | set -e |
Brian O'Connor | 3fad9bc | 2016-03-01 17:39:09 -0800 | [diff] [blame] | 7 | |
| 8 | GERRIT_USER=${GERRIT_USER:-$USER} |
| 9 | GERRIT_PROJECT=${GERRIT_PROJECT:-onos} |
| 10 | |
Brian O'Connor | 156c480 | 2016-03-02 15:50:38 -0800 | [diff] [blame] | 11 | function setup { |
Brian O'Connor | 3fad9bc | 2016-03-01 17:39:09 -0800 | [diff] [blame] | 12 | 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'Connor | 156c480 | 2016-03-02 15:50:38 -0800 | [diff] [blame] | 20 | function cleanup { |
Brian O'Connor | 3fad9bc | 2016-03-01 17:39:09 -0800 | [diff] [blame] | 21 | # clean up the directory |
Brian O'Connor | 156c480 | 2016-03-02 15:50:38 -0800 | [diff] [blame] | 22 | rm -rf $DIR |
| 23 | } |
| 24 | |
| 25 | function 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'Connor | 3fad9bc | 2016-03-01 17:39:09 -0800 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | setup |
| 31 | case $1 in |
| 32 | block) |
Brian O'Connor | 156c480 | 2016-03-02 15:50:38 -0800 | [diff] [blame] | 33 | testReleaseMembership |
Brian O'Connor | 3fad9bc | 2016-03-01 17:39:09 -0800 | [diff] [blame] | 34 | sed -i '' "s/submit = group/submit = block group/g" project.config |
Brian O'Connor | 156c480 | 2016-03-02 15:50:38 -0800 | [diff] [blame] | 35 | sed -i '' "s/push = block group ONOS Release/push = group ONOS Release/g" project.config |
Brian O'Connor | 3fad9bc | 2016-03-01 17:39:09 -0800 | [diff] [blame] | 36 | 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'Connor | 156c480 | 2016-03-02 15:50:38 -0800 | [diff] [blame] | 41 | testReleaseMembership |
Brian O'Connor | 3fad9bc | 2016-03-01 17:39:09 -0800 | [diff] [blame] | 42 | sed -i '' "s/submit = block group/submit = group/g" project.config |
Brian O'Connor | 156c480 | 2016-03-02 15:50:38 -0800 | [diff] [blame] | 43 | sed -i '' "s/push = group ONOS Release/push = block group ONOS Release/g" project.config |
Brian O'Connor | 3fad9bc | 2016-03-01 17:39:09 -0800 | [diff] [blame] | 44 | 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" |
| 61 | esac |
| 62 | cleanup |