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 | |
Thomas Vachuska | 0416f94 | 2016-08-22 13:30:31 -0700 | [diff] [blame^] | 6 | GERRIT_URL=$(git remote show origin | grep "Fetch URL" | cut -d: -f2- | grep ssh) |
| 7 | |
Brian O'Connor | d730b22 | 2016-03-01 18:32:38 -0800 | [diff] [blame] | 8 | set -e |
Brian O'Connor | 3fad9bc | 2016-03-01 17:39:09 -0800 | [diff] [blame] | 9 | |
Thomas Vachuska | 0416f94 | 2016-08-22 13:30:31 -0700 | [diff] [blame^] | 10 | if [ -z "$GERRIT_URL" ]; then |
| 11 | GERRIT_USER=${GERRIT_USER:-$USER} |
| 12 | GERRIT_PROJECT=${GERRIT_PROJECT:-onos} |
| 13 | GERRIT_URL="ssh://$GERRIT_USER@gerrit.onosproject.org:29418/$GERRIT_PROJECT" |
| 14 | else |
| 15 | GERRIT_PROJECT=${GERRIT_URL##*/} |
| 16 | GERRIT_USER=$(echo ${GERRIT_URL#*//} | cut -d@ -f1) |
| 17 | fi |
Brian O'Connor | 3fad9bc | 2016-03-01 17:39:09 -0800 | [diff] [blame] | 18 | |
Brian O'Connor | 156c480 | 2016-03-02 15:50:38 -0800 | [diff] [blame] | 19 | function setup { |
Brian O'Connor | 3fad9bc | 2016-03-01 17:39:09 -0800 | [diff] [blame] | 20 | DIR=$(mktemp -d /tmp/$GERRIT_PROJECT-config.XXXXX) || { echo "Failed to create temp file"; exit 1; } |
| 21 | cd $DIR |
| 22 | git init |
Thomas Vachuska | 0416f94 | 2016-08-22 13:30:31 -0700 | [diff] [blame^] | 23 | git remote add origin $GERRIT_URL |
Brian O'Connor | 3fad9bc | 2016-03-01 17:39:09 -0800 | [diff] [blame] | 24 | git fetch origin refs/meta/config:refs/remotes/origin/meta/config |
| 25 | git checkout meta/config |
| 26 | } |
| 27 | |
Brian O'Connor | 156c480 | 2016-03-02 15:50:38 -0800 | [diff] [blame] | 28 | function cleanup { |
Brian O'Connor | 3fad9bc | 2016-03-01 17:39:09 -0800 | [diff] [blame] | 29 | # clean up the directory |
Brian O'Connor | 156c480 | 2016-03-02 15:50:38 -0800 | [diff] [blame] | 30 | rm -rf $DIR |
| 31 | } |
| 32 | |
| 33 | function testReleaseMembership { |
Thomas Vachuska | 0416f94 | 2016-08-22 13:30:31 -0700 | [diff] [blame^] | 34 | ssh -p 29418 gerrit.onosproject.org gerrit ls-members "ONOS\ Release" | grep -q $GERRIT_USER || |
| 35 | (echo 'ERROR: Not a member of the ONOS Release group'; cleanup; exit 1) |
Brian O'Connor | 3fad9bc | 2016-03-01 17:39:09 -0800 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | setup |
| 39 | case $1 in |
| 40 | block) |
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 = group/submit = block group/g" project.config |
Brian O'Connor | 156c480 | 2016-03-02 15:50:38 -0800 | [diff] [blame] | 43 | 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] | 44 | git diff |
| 45 | git commit -am"Blocking submit for all users in project" |
| 46 | git push origin HEAD:refs/meta/config |
| 47 | ;; |
| 48 | unblock) |
Brian O'Connor | 156c480 | 2016-03-02 15:50:38 -0800 | [diff] [blame] | 49 | testReleaseMembership |
Brian O'Connor | 3fad9bc | 2016-03-01 17:39:09 -0800 | [diff] [blame] | 50 | sed -i '' "s/submit = block group/submit = group/g" project.config |
Brian O'Connor | 156c480 | 2016-03-02 15:50:38 -0800 | [diff] [blame] | 51 | 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] | 52 | git diff |
| 53 | git commit -am"Unblocking submit for all users in project" |
| 54 | git push origin HEAD:refs/meta/config |
| 55 | ;; |
| 56 | edit) |
| 57 | echo |
| 58 | echo "Make your changes now." |
| 59 | echo "To push changes, commit them and exit with 0" |
| 60 | echo "To abandon changes, do not commit or exit with non-zero value" |
| 61 | bash -i && git push origin HEAD:refs/meta/config || echo "ABANDONED CHANGES" |
| 62 | ;; |
| 63 | *) |
| 64 | echo |
| 65 | echo "USAGE: onos-edit-config <option>" |
| 66 | echo " block: blocks submits for all users in the project" |
| 67 | echo " unblock: unblocks submits for all users in the project" |
| 68 | echo " edit: allows you to make arbitrary changes to project config" |
| 69 | esac |
| 70 | cleanup |