blob: 8917d41f6a833cf5029f98858da19836d6d00dd0 [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
Thomas Vachuska0416f942016-08-22 13:30:31 -07006GERRIT_URL=$(git remote show origin | grep "Fetch URL" | cut -d: -f2- | grep ssh)
7
Brian O'Connord730b222016-03-01 18:32:38 -08008set -e
Brian O'Connor3fad9bc2016-03-01 17:39:09 -08009
Thomas Vachuska0416f942016-08-22 13:30:31 -070010if [ -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"
14else
15 GERRIT_PROJECT=${GERRIT_URL##*/}
16 GERRIT_USER=$(echo ${GERRIT_URL#*//} | cut -d@ -f1)
17fi
Brian O'Connor3fad9bc2016-03-01 17:39:09 -080018
Brian O'Connor156c4802016-03-02 15:50:38 -080019function setup {
Brian O'Connor3fad9bc2016-03-01 17:39:09 -080020 DIR=$(mktemp -d /tmp/$GERRIT_PROJECT-config.XXXXX) || { echo "Failed to create temp file"; exit 1; }
21 cd $DIR
22 git init
Thomas Vachuska0416f942016-08-22 13:30:31 -070023 git remote add origin $GERRIT_URL
Brian O'Connor3fad9bc2016-03-01 17:39:09 -080024 git fetch origin refs/meta/config:refs/remotes/origin/meta/config
25 git checkout meta/config
26}
27
Brian O'Connor156c4802016-03-02 15:50:38 -080028function cleanup {
Brian O'Connor3fad9bc2016-03-01 17:39:09 -080029 # clean up the directory
Brian O'Connor156c4802016-03-02 15:50:38 -080030 rm -rf $DIR
31}
32
33function testReleaseMembership {
Thomas Vachuska0416f942016-08-22 13:30:31 -070034 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'Connor3fad9bc2016-03-01 17:39:09 -080036}
37
38setup
39case $1 in
40 block)
Brian O'Connor156c4802016-03-02 15:50:38 -080041 testReleaseMembership
Brian O'Connor3fad9bc2016-03-01 17:39:09 -080042 sed -i '' "s/submit = group/submit = block group/g" project.config
Brian O'Connor156c4802016-03-02 15:50:38 -080043 sed -i '' "s/push = block group ONOS Release/push = group ONOS Release/g" project.config
Brian O'Connor3fad9bc2016-03-01 17:39:09 -080044 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'Connor156c4802016-03-02 15:50:38 -080049 testReleaseMembership
Brian O'Connor3fad9bc2016-03-01 17:39:09 -080050 sed -i '' "s/submit = block group/submit = group/g" project.config
Brian O'Connor156c4802016-03-02 15:50:38 -080051 sed -i '' "s/push = group ONOS Release/push = block group ONOS Release/g" project.config
Brian O'Connor3fad9bc2016-03-01 17:39:09 -080052 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"
69esac
70cleanup