-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateme.sh
83 lines (70 loc) · 2.35 KB
/
updateme.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
75
76
77
78
79
80
81
82
83
#/bin/sh
# This file was downloaded from
# https://github.com/gdi3d/js-hmr-osx-docker-helper
# check the repo for docs
# <config>
# Define the absolute path where your files are
# Ex.: /users/bob/workspace/myAwsomeApp
PATH_TO_WATCH=""
# Available events at https://linux.die.net/man/1/inotifywait
# on Events section
# Note: I have experienced some infinite loops if
# the event close_write was added.
# DO NOT ADD THE DELETE EVENT since it will create
# an empty file after you delete your own
EVENTS_TO_LISTEN="create,modify,moved_from,moved_to"
# Use regular expressions here to select all files
# that you want to exclude from beign watch
FILES_TO_EXCLUDE="(\.git|.log|.md|.lock|.json.gz)"
# Log to terminal the filenames and events
# to help you debug
DEBUG=1
# </config>
# =================================================
# This is where the magic happens :D
# Don't touch it unless you know what you're doing
# let's check inotify-tools package is present
CMD_CHECK=$(inotifywait 2> /dev/null)
PACKAGE_STATUS=$?
if [ $PACKAGE_STATUS -eq 127 ]; then
_OS_NAME=$(cat /etc/os-release|grep "^ID"|awk '{split($0, a, "="); print a[2]}')
clear
echo "Woow, something failed!"
echo "======================="
echo
echo "inotify-tools package not present on your system. Install it first!"
echo
echo "How?"
echo
echo "I can see you're using $_OS_NAME linux."
echo "So just search for: install inotify-tools package on $_OS_NAME linux"
echo "or click here https://duckduckgo.com/?q=install+inotify-tools+package+on+$_OS_NAME+linux"
echo
echo "Try again after that ;)..."
echo
exit 1;
fi
# check path is given
if [ -z "$PATH_TO_WATCH" ]; then
clear
echo "Hold on!"
echo
echo "You didn't set a path on the var PATH_TO_WATCH"
echo "Edit this file and add the path to continue.."
echo
exit 1;
fi
if [ $DEBUG -ne 0 ]; then
echo "Debug mode enabled. You can turn it of by editing updateme.sh and set DEBUG to 0"
fi
# Let's keep an eye on those bastards!
inotifywait -m -r -e $EVENTS_TO_LISTEN --format '%w%f %e' --exclude $FILES_TO_EXCLUDE $PATH_TO_WATCH | \
while read FILE
do
_MOD_FILE=$(echo $FILE|awk '{print $1}' )
_EVENTS=$(echo $FILE|awk '{print $2}')
touch $_MOD_FILE
if [ $DEBUG -ne 0 ]; then
echo "touch on file $_MOD_FILE because of event(s) $_EVENTS"
fi
done