-
Notifications
You must be signed in to change notification settings - Fork 62
/
debug.sh
executable file
·58 lines (53 loc) · 1.77 KB
/
debug.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
#!/usr/bin/env bash
set -e
## Settings
debug_file=.debugfile
target_dir=/var/www/html
watch_dir=/app/.debug
## Create watch_dir
if [[ ! -d ${watch_dir} ]]; then
mkdir ${watch_dir}
chmod 777 ${watch_dir}
fi
## Create debug_file
if [[ ! -f ${watch_dir}/${debug_file} ]]; then
touch ${watch_dir}/${debug_file}
chmod 777 ${watch_dir}/${debug_file}
fi
process_debug_file () {
while IFS= read file || [[ -n "${file}" ]]; do
[[ -z "${file}" ]] && continue
[[ "${file::1}" == "#" ]] && continue
[[ -f ${watch_dir}/${file} ]] && continue
echo "+ ${file}"
if [[ ! -f ${target_dir}/${file} ]]; then
mkdir -p $(dirname ${target_dir}/${file}) && true
touch ${target_dir}/${file}
chmod 777 -R $(dirname ${target_dir}/${file})
fi
mkdir -p $(dirname ${watch_dir}/${file}) && true
cp ${target_dir}/${file} ${watch_dir}/${file}
chmod 777 -R ${watch_dir}
done < ${watch_dir}/${debug_file}
}
## Files watcher
echo "Add your file names on '.debug/.debugfile'"
echo "Watching for debug... (Stop with [Ctrl+C])"
process_debug_file
inotifywait -q -r -e moved_to,create -m ${watch_dir} |
while read -r directory events current_file; do
#echo "${events} ${directory} ${current_file}"
if [[ "${current_file}" = "${debug_file}" ]]; then
process_debug_file
else
while IFS= read file || [[ -n "${file}" ]]; do
[[ -z "${file}" ]] && continue
[[ "${file::1}" == "#" ]] && continue
if [[ "${directory}${current_file}" = "${watch_dir}/${file}" ]]; then
echo "> ${file}"
cp ${watch_dir}/${file} ${target_dir}/${file}
fi
done < ${watch_dir}/${debug_file}
fi
#echo ">>> ${filename}"
done