This repository was archived by the owner on Mar 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlive_sync.sh
More file actions
executable file
·131 lines (117 loc) · 2.82 KB
/
live_sync.sh
File metadata and controls
executable file
·131 lines (117 loc) · 2.82 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
ARG1=$1
CWD=$(pwd)
LIVE_SYNC_DIR=$CWD/.live_sync
if [ ! -d $LIVE_SYNC_DIR ];
then
echo "Live Sync Isn't Setup, run live_sync_setup to setup"
exit
else
REMOTE_FILE=$LIVE_SYNC_DIR/live_sync_remote
REMOTE=`cat $REMOTE_FILE`
LOCAL_LOCK_FILE=$LIVE_SYNC_DIR/live_sync.lock
GLOBAL_LOCK_FILE=/tmp/live_sync.lock
EXCLUDE_LIST=$LIVE_SYNC_DIR/exclude-list.txt
TRIGGER=$LIVE_SYNC_DIR/watchman_trigger
TRIGGER_DEL=$LIVE_SYNC_DIR/watchman_trigger-del
LOCK_FILE_DEL_CMD='rm $LOCAL_LOCK_FILE'
WATCH_LOCK_FILE=$LIVE_SYNC_DIR/watching
if [ -f $LOCAL_LOCK_FILE ]
then
PID=$(cat $PID_FILE)
fi
fi
if [ "$ARG1" == "-r" ];
then
if [ -f $LOCAL_LOCK_FILE ]
then
growlnotify -m "$CWD Locked, Cannot Sync To $REMOTE" -t "Live Sync" -a /Applications/LiveReload.app/
exit
fi
if [ -f $GLOBAL_LOCK_FILE ]
then
growlnotify -m "Live Sync Locked, Cannot Sync to Remotes" -t "Live Sync" -a /Applications/LiveReload.app/
exit
fi
rsync -rltvz --exclude=".svn" --exclude-from $EXCLUDE_LIST --delete . $REMOTE
growlnotify -m "$CWD Synced to $REMOTE" -t "Live Sync" -a /Applications/LiveReload.app/
exit
fi
if [ "$ARG1" == "-s" ];
then
if [ -f $WATCH_LOCK_FILE ]
then
cat $TRIGGER_DEL | watchman -j > /dev/null
fi
rsync -rltvz --exclude=".svn" --exclude-from $EXCLUDE_LIST --delete $REMOTE .
wait
growlnotify -m "$REMOTE\
Synced to\
$CWD" -t "Live Sync" -a /Applications/LiveReload.app/
if [ -f $WATCH_LOCK_FILE ]
then
cat $TRIGGER | watchman -j > /dev/null
fi
exit
fi
if [ "$ARG1" == "-w" ]
then
cat $TRIGGER | watchman -j > /dev/null
touch $WATCH_LOCK_FILE
growlnotify -m "$CWD Syncing" -a /Applications/LiveReload.app/ -t "Live Sync"
exit
fi
if [ "$ARG1" == "-x" ]
then
cat $TRIGGER_DEL | watchman -j > /dev/null
if [ -f $WATCH_LOCK_FILE ]
then
rm $WATCH_LOCK_FILE
fi
growlnotify -m "$CWD Syncing Stopped" -a /Applications/LiveReload.app/ -t "Live Sync"
exit
fi
if [ "$ARG1" == "-l" ]
then
touch $LOCAL_LOCK_FILE
growlnotify -m "$CWD Locked" -a /Applications/LiveReload.app/ -t "Live Sync"
exit
fi
if [ "$ARG1" == "-u" ]
then
rm $LOCAL_LOCK_FILE
growlnotify -m "$CWD Unlocked" -a /Applications/LiveReload.app/ -t "Live Sync"
exit
fi
if [ "$ARG1" == "-g" ]
then
touch $GLOBAL_LOCK_FILE
growlnotify -m "Globally Locked" -a /Applications/LiveReload.app/ -t "Live Sync"
exit
fi
if [ "$ARG1" == "-k" ]
then
rm $GLOBAL_LOCK_FILE
growlnotify -m "Globally Unlocked" -a /Applications/LiveReload.app/ -t "Live Sync"
exit
fi
if [ "$ARG1" == "-p" ]
then
echo "Syncing To $REMOTE"
exit
fi
cat << EOF
Live Sync
Syncs directories using rsync
usage: live_sync [-r] [-s] [-l] [-u] [-g] [-k] [-p]
Options:
-r Sync to Remote
-s Sync to Local
-w Start Watching
-x Stop Watching
-l Lock Local Directory
-u Unlock Local Directory
-g Lock Globally
-k Unlock Globally
-p Print Remote
EOF