/
ros.sh
executable file
·52 lines (42 loc) · 1.15 KB
/
ros.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
#!/usr/bin/env bash
#
# set -e;
WATCH_DIRECTORY=$1;
shift;
EVENT_TASK=$1;
shift;
IGNORE_PATHS="$@";
function listVariables() {
echo -e "Variables ::
WATCH_DIRECTORY = ${WATCH_DIRECTORY};
EVENT_TASK = ${EVENT_TASK};
";
}
function doIt() {
sleep 1;
${EVENT_TASK};
};
echo -e "\nros.sh -- Run On Save : Executes the indicated command when any file is changed in the indicated directory.
Usage: ./ros.sh . \"ls -la\";\n\n";
declare PKG="inotify-tools";
if ! dpkg-query -l ${PKG} &>/dev/null; then
echo "Attempting to install '${PKG}'"
if sudo apt-get -y install ${PKG} &>/dev/null; then
echo -e "Hmmm.";
else
echo -e "Required repositories are not available. Running 'apt-get update'";
sudo apt-get update;
echo "\n\nAgain attempting to install '${PKG}'\n"
sudo apt-get -y install ${PKG};
echo "\nInstalled '${PKG}'\n"
fi;
fi;
declare PKG="tree";
dpkg-query -l ${PKG} &>/dev/null || sudo apt-get -y install ${PKG};
echo "Run-On-Save will execute : '${EVENT_TASK}'";
listVariables;
doIt;
while true #run indefinitely
do
inotifywait -qqr -e close_write,move,create,delete ${IGNORE_PATHS} ${WATCH_DIRECTORY} && doIt;
done