Last active
June 3, 2021 21:55
-
-
Save poppen/2817445 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# inotify-git | |
# | |
# 対象ディレクトリを再帰的に監視し、 | |
# 変更をすべて git で自動コミットする | |
# | |
# 再起動しても勝手に監視させるには | |
# /etc/rc.local に | |
# /path/to/inotify-git directory & | |
# を書いておく | |
# 初回起動は nohup /path/to/inotify-git > out.log 2> err.log < /dev/null & | |
# | |
# 監視対象から外したいものは.gitignoreに入れ, | |
# inotifywait の --exclude オプションで監視しないようにする | |
# inotifyのmax_user_watchesのデフォルト値は 8192 なので 増やしたい時は | |
# /proc/sys/fs/inotify/max_user_watches を変更する | |
if [ $# -lt 1 ]; then | |
echo "Usage: inotify-git direcotory [branch]" | |
exit 1 | |
fi | |
# gitで自動更新したいディレクトリを指定 | |
INOTIFY_GIT_CHECK_DIRECTORY=$1 | |
if [ $# -eq 2 ]; then | |
INOTIFY_GIT_BRANCH=$2 | |
else | |
INOTIFY_GIT_BRANCH="master" | |
fi | |
while true; do | |
inotifywait -r -qq -e create,delete,modify,move \ | |
--exclude '.*\.git/.*' ${INOTIFY_GIT_CHECK_DIRECTORY}; | |
if [ -e ${INOTIFY_GIT_CHECK_DIRECTORY}/inotify-sleep ]; then | |
sleep 300; | |
else | |
cd ${INOTIFY_GIT_CHECK_DIRECTORY}; | |
git add -A > /dev/null 2>&1; | |
git commit -m 'auto commit' > /dev/null 2>&1 | |
git push origin "$INOTIFY_GIT_BRANCH" > /dev/null 2>&1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment