blob: 111fd62e523033fa221dfb5e22f87a7475bd3364 [file] [log] [blame]
pulser73f43592013-09-13 00:09:35 +02001#!/bin/sh
2# Copyright OmniROM Project
3# Licensed under GPLv3
4
5# Configuration
pulser73f43592013-09-13 00:09:35 +02006PREFIX=android_
maxwen95841aa2016-03-08 23:43:18 +01007BRANCH=android-6.0
8SOURCE=android-6.0.1_<INSERT_CORRECT_TAG>
9USERNAME=<INSERT USER>
pulser73f43592013-09-13 00:09:35 +020010MANIFEST=android/default.xml
XpLoDWilD0cb714a2014-01-05 15:37:48 +010011GITHUB_ORG=omnirom
maxwen95841aa2016-03-08 23:43:18 +010012GERRIT_REMOTE=ssh://$USERNAME@gerrit.omnirom.org:29418
XpLoDWilD0cb714a2014-01-05 15:37:48 +010013REMOTE_MANIFEST=omnirom
pulser73f43592013-09-13 00:09:35 +020014
15# Script
16if [ $# -lt 1 ]; then
XpLoDWilD0cb714a2014-01-05 15:37:48 +010017 echo Usage: ./fork_aosp.sh path
18 echo Example: ./fork_aosp.sh frameworks/base
pulser73f43592013-09-13 00:09:35 +020019 exit 1
20fi
21
22REPO_NAME=$PREFIX$(echo ${1%/} | sed -e "s/\//_/g")
23
24# Check that folder is a git repo
25pushd $1
26if [ ! -d .git ]; then
27 echo "$1 doesn't appear to be a git repository"
28 popd
29 exit 1
30fi
31popd
32
XpLoDWilD0cb714a2014-01-05 15:37:48 +010033# Create the repo at github
34echo "Creating $REPO_NAME on GitHub..."
35curl --user $USERNAME --data "{\"name\":\"$REPO_NAME\"}" https://api.github.com/orgs/$GITHUB_ORG/repos
pulser73f43592013-09-13 00:09:35 +020036
37# Only works if you are a gerrit admin, will create the named project before pushing (gerrit then replicates to git)
maxwen95841aa2016-03-08 23:43:18 +010038ssh -p 29418 $USERNAME@gerrit.omnirom.org gerrit create-project --name $REPO_NAME
pulser73f43592013-09-13 00:09:35 +020039
40echo "Creating branch $BRANCH..."
XpLoDWilD0cb714a2014-01-05 15:37:48 +010041pushd $1
42git remote rm gerrit
pulser73f43592013-09-13 00:09:35 +020043git remote add gerrit $GERRIT_REMOTE/$REPO_NAME
44git checkout $SOURCE
45git branch $BRANCH
46git push gerrit $BRANCH
47
48echo "Updating manifest..."
XpLoDWilD0cb714a2014-01-05 15:37:48 +010049popd
pulser73f43592013-09-13 00:09:35 +020050SRC_LINE=$(cat $MANIFEST | grep ${1%/} | head -n1)
51if [[ "$SRC_LINE" == *group="pdk"* ]]; then
52 NEW_LINE=" <project path=\"${1%/}\" name=\"$REPO_NAME\" remote=\"$REMOTE_MANIFEST\" revision=\"$BRANCH\" group=\"pdk\" />"
53else
54 NEW_LINE=" <project path=\"${1%/}\" name=\"$REPO_NAME\" remote=\"$REMOTE_MANIFEST\" revision=\"$BRANCH\" />"
55fi
56
57# Update the repo in manifest listing
58
59sed -i "s%$SRC_LINE%$NEW_LINE%g" $MANIFEST
60
61echo "Pushing manifest"
XpLoDWilD0cb714a2014-01-05 15:37:48 +010062pushd android
pulser73f43592013-09-13 00:09:35 +020063git checkout $BRANCH
64git commit -a -m "Replace $1 path to new repository $REPO_NAME"
65git push $GERRIT_REMOTE/android HEAD:refs/for/$BRANCH
XpLoDWilD0cb714a2014-01-05 15:37:48 +010066popd
pulser73f43592013-09-13 00:09:35 +020067
68echo "Now remember to approve the change on gerrit before going further!"
69read -p "Press [Enter] key once you've approved the change on gerrit"
70
71echo "Remember to repo sync before use!"