blob: 3064b425ddae258e45598b584805d25f4d94c025 [file] [log] [blame]
pulser73f43592013-09-13 00:09:35 +02001#!/bin/sh
2# Copyright OmniROM Project
3# Licensed under GPLv3
4
5# Configuration
XpLoDWilD0cb714a2014-01-05 15:37:48 +01006ANDROID_ROOT=~/omni
pulser73f43592013-09-13 00:09:35 +02007PREFIX=android_
XpLoDWilD0cb714a2014-01-05 15:37:48 +01008BRANCH=android-4.4
9SOURCE=android-4.4.2_r1
pulser73f43592013-09-13 00:09:35 +020010MANIFEST=android/default.xml
XpLoDWilD0cb714a2014-01-05 15:37:48 +010011GITHUB_ORG=omnirom
12USERNAME=xplodwild
13GERRIT_REMOTE=ssh://gerrit.omnirom.org:29418
14REMOTE_MANIFEST=omnirom
pulser73f43592013-09-13 00:09:35 +020015
16# Script
17if [ $# -lt 1 ]; then
XpLoDWilD0cb714a2014-01-05 15:37:48 +010018 echo Usage: ./fork_aosp.sh path
19 echo Example: ./fork_aosp.sh frameworks/base
pulser73f43592013-09-13 00:09:35 +020020 exit 1
21fi
22
23REPO_NAME=$PREFIX$(echo ${1%/} | sed -e "s/\//_/g")
24
25# Check that folder is a git repo
26pushd $1
27if [ ! -d .git ]; then
28 echo "$1 doesn't appear to be a git repository"
29 popd
30 exit 1
31fi
32popd
33
XpLoDWilD0cb714a2014-01-05 15:37:48 +010034# Create the repo at github
35echo "Creating $REPO_NAME on GitHub..."
36curl --user $USERNAME --data "{\"name\":\"$REPO_NAME\"}" https://api.github.com/orgs/$GITHUB_ORG/repos
pulser73f43592013-09-13 00:09:35 +020037
38# Only works if you are a gerrit admin, will create the named project before pushing (gerrit then replicates to git)
pulser73f43592013-09-13 00:09:35 +020039ssh -p 29418 gerrit.omnirom.org gerrit create-project --name $REPO_NAME
40
41echo "Creating branch $BRANCH..."
XpLoDWilD0cb714a2014-01-05 15:37:48 +010042pushd $1
43git remote rm gerrit
pulser73f43592013-09-13 00:09:35 +020044git remote add gerrit $GERRIT_REMOTE/$REPO_NAME
45git checkout $SOURCE
46git branch $BRANCH
47git push gerrit $BRANCH
48
49echo "Updating manifest..."
XpLoDWilD0cb714a2014-01-05 15:37:48 +010050popd
pulser73f43592013-09-13 00:09:35 +020051SRC_LINE=$(cat $MANIFEST | grep ${1%/} | head -n1)
52if [[ "$SRC_LINE" == *group="pdk"* ]]; then
53 NEW_LINE=" <project path=\"${1%/}\" name=\"$REPO_NAME\" remote=\"$REMOTE_MANIFEST\" revision=\"$BRANCH\" group=\"pdk\" />"
54else
55 NEW_LINE=" <project path=\"${1%/}\" name=\"$REPO_NAME\" remote=\"$REMOTE_MANIFEST\" revision=\"$BRANCH\" />"
56fi
57
58# Update the repo in manifest listing
59
60sed -i "s%$SRC_LINE%$NEW_LINE%g" $MANIFEST
61
62echo "Pushing manifest"
XpLoDWilD0cb714a2014-01-05 15:37:48 +010063pushd android
pulser73f43592013-09-13 00:09:35 +020064git checkout $BRANCH
65git commit -a -m "Replace $1 path to new repository $REPO_NAME"
66git push $GERRIT_REMOTE/android HEAD:refs/for/$BRANCH
XpLoDWilD0cb714a2014-01-05 15:37:48 +010067popd
pulser73f43592013-09-13 00:09:35 +020068
69echo "Now remember to approve the change on gerrit before going further!"
70read -p "Press [Enter] key once you've approved the change on gerrit"
71
72echo "Remember to repo sync before use!"