Skip to content

Instantly share code, notes, and snippets.

@simonsickle-old
Last active August 29, 2015 14:09
Show Gist options
  • Save simonsickle-old/126a8de77d0332e744ac to your computer and use it in GitHub Desktop.
Save simonsickle-old/126a8de77d0332e744ac to your computer and use it in GitHub Desktop.
Android Mirroring
#!/bin/bash
######################################################
# Copyright 2014 (c) Simon Sickle #
# MIT LICENSE #
######################################################
# Notes: Run this script from the directory containing
# the android source. Modify variables at the top to
# customize the upload. Meant for AOSP. Enjoy!
# The place you want the script to upload to on github
GITHUB=CarbonROM/
# The name of the branch that will be used on upload
NEWBRANCH="lollipop"
# GIT upload url
GITURL="git@github.com"
MANIFEST_HEAD='<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="carbon"
fetch=".."
review="review.carbonrom.org" />
<default revision="lollipop"
remote="carbon"
sync-j="4" />'
# Absolute path to this script. /home/user/bin/foo.sh
SCRIPT=$(readlink -f $0)
# Absolute path this script is in. /home/user/bin
SCRIPTPATH=`dirname $SCRIPT`
# Read the manifest
for item in $(cat .repo/manifest.xml | grep "<project "); do
echo -n ${item} | grep "name=" | cut -f2 -d'"' | sed "s#platform#android#" | sed "s#device#android_device#" | tr / _ >> names.txt
echo -n ${item} | grep "path=" | cut -f2 -d'"' >> paths.txt
done
# Setup empty arrays
paths=()
names=()
# Get all paths
for path in $(cat paths.txt); do
paths+=(${path})
done
# Get all names
for name in $(cat names.txt); do
names+=(${name})
done
# Set array length
tLen=${#paths[@]}
# Setup manifest header
echo ${MANIFEST_HEAD} > newmanifest.xml
# Loop through the all the combos
for ((i=0; i<${tLen}; i++)); do
echo " <project path=\"${paths[$i]}\" name=\"${GITHUB}${names[$i]}\" />" >> newmanifest.xml
done
# Close manifest
echo "</manifest>" >> newmanifest.xml
# Notify that manifest is created
echo "Manifest Created. Moving to push sequence"
# Give user a few seconds to read this
sleep 6
# Loop through the all the combos again. Upload sources.
for ((i=0; i<${tLen}; i++)); do
cd ${paths[$i]}
git branch ${NEWBRANCH}
git checkout ${NEWBRANCH}
echo " ${GITURL}:${GITHUB}${names[$i]}.git ${NEWBRANCH}"
git push -u ${GITURL}:${GITHUB}${names[$i]}.git ${NEWBRANCH}
cd $SCRIPTPATH
done
# Create manifest
#mkdir -p ./manifest-new
#cp ./newmanifest.xml ./manifest-new/default.xml
#touch ./manifest-new/README.md
#cd ./manifest-new/
#git init
#git add .
#git commit -sam "Inital script generated manifest"
#git branch ${NEWBRANCH}
#git push -u ${GITURL}:${GITHUB}android.git ${NEWBRANCH}
# Clean up
cd $SCRIPTPATH
rm -rf manifest-new/
rm names.txt paths.txt newmanifest.xml
# Everything is finished
echo "All tasks completed. Happy coding!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment