1#!/usr/bin/env bash 2 3############################################################################## 4## 5## GitHub Upate script for Android Samples 6## 7############################################################################## 8 9##replace with auth token for google-automerger GitHub account 10TOKEN=herpderp 11 12##make temporary dir to pull code into - delete at end. 13mkdir github-temp 14cd github-temp 15 16##iterate through samples 17for i in $(ls ../prebuilts/gradle); 18 19 20##for testing 21#foo="ActionBarCompat-Basic" 22#foo="ActionBarCompat-Basic herpderp" 23#foo="ActionBarCompat-Basic ActionBarCompat-ListPopupMenu" 24#foo="MediaBrowserService MessagingService" 25#for i in $foo; 26 27do 28echo " 29$i" 30 31URL=https://github.com/googlesamples/android-$i 32 33result=$(curl -o /dev/null --silent --head --write-out '%{http_code}' "$URL") 34#echo "$result $URL" 35 36##checking to see if the repo exists 37if [ "$result" != "200" ]; then 38 echo "Cannot access repo for $i, it may not exist yet" 39else 40 echo "Updating repo for $i" 41 42git clone $URL.git 43##check to make sure it worked and the folder is there 44if [ -d "android-$i" ]; then 45 rsync -az --delete --exclude '*.git' ../prebuilts/gradle/$i/ ./android-$i/ 46 47 cd ./android-$i/ 48 49 git config user.name "google-automerger" 50 git config user.email automerger@google.com 51 52 git add . 53 git status 54 git commit -m "Auto-update" 55 56 git remote set-url origin "https://$TOKEN@github.com/googlesamples/android-$i.git" 57 git push origin master 58 59 cd .. 60else 61 "Something went wrong when cloning $i - result directory does not exist." 62fi 63 64fi 65done 66 67##cleanup 68cd .. 69rm -rf ./github-temp 70