-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-auto-push.sh
74 lines (64 loc) · 1.65 KB
/
git-auto-push.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
#Automatically pushes any changes to the sqlite db, generated from a tool.
usage() { echo "
Complete list of arguments, all are required:
-w <string> The path to the file to watch.
-s <string> The path to the source.
-d <string> The destination path (somewhere in the source).
-m <string> The git commit message.
-t <int> The time to wait after the first
Tools needed:
1. sudo apt-get install inotify-tools
2. ssh (otherwise git will require password on push)" 1>&2; exit 1; }
while getopts ":w:s:d:m:t:" o; do
case "${o}" in
w)
w=${OPTARG}
;;
s)
s=${OPTARG}
;;
d)
d=${OPTARG}
;;
m)
m=${OPTARG}
;;
t)
t=${OPTARG}
((t >= 10)) || usage
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${w}" ] || [ -z "${s}" ] || [ -z "${m}" ] || [ -z "${t}" ]; then
usage
fi
auto_gen_file=$w
auto_mod_path=${w%/*}
base_name="$(basename $auto_gen_file)"
source_name="$d$base_name"
source_path=$s
destination_path="$s/$d"
commit_message=$m
delay_for=$t
echo $source_name
echo "Watching file: $auto_gen_file in folder: $auto_mod_path"
export GIT_WORK_TREE=$source_path
export GIT_DIR="${GIT_WORK_TREE}/.git"
while true
do
#the algorithm actually watches the folder of the file -
#that is because inotifywait does not behave properly when watching a single file
if inotifywait -e modify $auto_mod_path; then
sleep $delay_for
cp $auto_gen_file $destination_path
sleep 5
git add $source_name
git commit -m "$commit_message"
git push
fi
done