1#!/usr/bin/env bash 2 3############################################################################## 4## 5## GitHub Upload/Sync script for Android Samples 6## 7############################################################################## 8 9#replace with auth token for google-automerger GitHub account 10TOKEN=herpderp 11 12#get list of existing GH repos 13EXISTING=`curl -s https://api.github.com/users/googlesamples/repos | grep full_name` 14 15#iterate through samples 16cd ./prebuilts/gradle 17 18for i in $(ls); 19 20##for testing 21#foo="ActionBarCompat-Basic" 22#foo="ActionBarCompat-Basic ActionBarCompat-ListPopupMenu" 23#for i in $foo; 24 25do 26echo $i 27 #checking to see if they're in the list 28 if [[ "$EXISTING" =~ "$i" ]]; then 29 echo "$i already exists as a repo" 30 else 31 echo "A repo for $i does not exist yet" 32 33repoName="googlesamples/android-$i" 34 35#echo " 36#URL Repo Name: 37#"$repoName 38 39 40CREATE="curl -H 'Authorization: token '$TOKEN \ 41 -d '{\"name\":\"android-'$i'\", \"team_id\":889859}' \ 42 https://api.github.com/orgs/googlesamples/repos" 43#echo " 44#Create Script: 45#"$CREATE 46eval $CREATE 47 48#add secondary team permissions (robots) 49ADDTEAM="curl -X PUT \ 50-H 'Authorization: token '$TOKEN \ 51-H 'Content-Length: 0' \ 52https://api.github.com/teams/889856/repos/$repoName" 53#echo " 54#Add Team Robots: 55#"$ADDTEAM 56eval $ADDTEAM 57 58 59URL="https://$TOKEN@github.com/$repoName" 60#echo " 61#Authenticated URL: 62#"$URL 63 64 cd $i 65 git init 66 #overrides .gitconfig just for this project - does not alter your global settings. 67 git config user.name "google-automerger" 68 git config user.email automerger@google.com 69 git add . 70 git commit -m "Initial Commit" 71 git remote add origin $URL 72 git push origin master 73 cd .. 74 fi 75done 76 77