Skip to content

Instantly share code, notes, and snippets.

@CoRfr
Last active February 20, 2018 09:19
Show Gist options
  • Save CoRfr/e2c3e4030b2bfa63bf53f954423130c2 to your computer and use it in GitHub Desktop.
Save CoRfr/e2c3e4030b2bfa63bf53f954423130c2 to your computer and use it in GitHub Desktop.
Update Gerrit Administrators group id
#!/bin/bash
set -e
GIT_ROOT=${GIT_ROOT:-"/storage/git"}
TMP_GIT=${TMP_GIT:-"/home/core/test"}
OLD_ID=$1
NEW_ID=$2
if [ -z "$OLD_ID" ] || [ -z "$NEW_ID" ]; then
echo "Usage: $0 <old id> <new id>"
exit 1
fi
if ! [ -e "${TMP_GIT}" ]; then
git init "${TMP_GIT}"
git --git-dir="${TMP_GIT}" remote add origin http://dummy
fi
fix_project() {
local proj=$1
cd "${TMP_GIT}"
git remote set-url origin "${proj}"
git fetch origin refs/meta/config
git checkout FETCH_HEAD
if ! grep "$NEW_ID" groups && grep Administrators groups; then
sed -i "s/$OLD_ID/$NEW_ID/g" groups
git commit -am "Fix Administrators group"
sudo git push origin HEAD:refs/meta/config
sudo chown -R 1000:1000 ${proj}
fi
}
for proj in $(find /storage/git -name "*.git"); do
echo $proj
fix_project "${proj}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment