Skip to content

Instantly share code, notes, and snippets.

@muojp
Created March 9, 2014 08:35
Show Gist options
  • Save muojp/9444572 to your computer and use it in GitHub Desktop.
Save muojp/9444572 to your computer and use it in GitHub Desktop.
Macでgitリポジトリを毎晩寝てる間に同期する方法 ref: http://qiita.com/muo_jp/items/de57c590942e4ef49c9f
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
<plist version="1.0">
<dict>
<key>Label</key>
<string>jp.muo.gitupdater</string>
<key>EnableGlobbing</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>~/bin/update-git-repos.sh</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>1</integer>
<key>Minute</key>
<integer>30</integer>
</dict>
</dict>
</plist>
#!/bin/bash
REPO_DIR=~/Documents/workspace
REPOS=(mono PlaygroundOSS) # ここに定期更新したいリポジトリの一覧を書く
GIT_OPTS="fetch -a --prune origin"
RETRY_INT=60
LOG_FILE=~/.update_git.log
function fetch_git_reops {
for r in "${REPOS[@]}"
do
echo "fetching... ${r}"
cd $REPO_DIR/$r
git $GIT_OPTS
done
}
if [ ! -t 1 ]; then
exec 1>> $LOG_FILE 2>&1
fi
echo "Starting git repos update at `date`"
# check network connectivity
i=0
while :
do
i=$((i + 1))
QRES=`dig +time=5 +tries=1 +short github.com` ; QRET=$?
if [ $QRET -eq 0 -a -n "$QRES" ]; then
fetch_git_reops
exit 0
fi
if [ $i -eq 5 ]; then
echo "No network access. Giving up."
exit 9
fi
echo "No network access. Retrying in $RETRY_INT seconds."
sleep $RETRY_INT
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment