Skip to content

Commit 56b21a3

Browse files
authored
Merge pull request #8 from devilbox/release-1.0.0
Release 1.0.0
2 parents 015ebbe + 7832ae2 commit 56b21a3

File tree

6 files changed

+162
-72
lines changed

6 files changed

+162
-72
lines changed

.editorconfig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
# Default for all files
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
# Custom files
12+
[*.py]
13+
indent_style = space
14+
indent_size = 4
15+
16+
[.sh}]
17+
indent_style = tab
18+
indent_size = 4
19+
20+
[Makefile]
21+
indent_style = tab
22+
indent_size = 4
23+
24+
[*.{yml,yaml}]
25+
indent_style = space
26+
indent_size = 2
27+
28+
[*.md]
29+
indent_style = space
30+
trim_trailing_whitespace = false
31+
indent_size = 2

.github/workflows/linting.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
3+
###
4+
### Lints all generic and json files in the whole git repository
5+
###
6+
7+
name: linting
8+
on:
9+
pull_request:
10+
push:
11+
branches:
12+
- master
13+
tags:
14+
15+
jobs:
16+
lint:
17+
runs-on: ubuntu-latest
18+
strategy:
19+
fail-fast: False
20+
matrix:
21+
target:
22+
- Linting
23+
name: "[ ${{ matrix.target }} ]"
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@master
27+
28+
- name: Lint files
29+
run: |
30+
make _lint-files
31+
32+
- name: Shellcheck
33+
run: |
34+
make _lint-shell

.travis.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
ifneq (,)
2+
.error This Makefile requires GNU Make.
3+
endif
4+
5+
# -------------------------------------------------------------------------------------------------
6+
# Default configuration
7+
# -------------------------------------------------------------------------------------------------
8+
.PHONY: help lint
9+
10+
FL_VERSION = 0.3
11+
FL_IGNORES = .git/,.github/
12+
13+
14+
# -------------------------------------------------------------------------------------------------
15+
# Default Target
16+
# -------------------------------------------------------------------------------------------------
17+
help:
18+
@echo "lint Lint repository"
19+
20+
21+
# -------------------------------------------------------------------------------------------------
22+
# Lint Targets
23+
# -------------------------------------------------------------------------------------------------
24+
lint: _lint-files
25+
lint: _lint-shell
26+
27+
28+
.PHONY: _lint-files
29+
_lint-files:
30+
@echo "# -------------------------------------------------------------------- #"
31+
@echo "# Lint files"
32+
@echo "# -------------------------------------------------------------------- #"
33+
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(PWD):/data cytopia/file-lint:$(FL_VERSION) file-cr --text --ignore '$(FL_IGNORES)' --path .
34+
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(PWD):/data cytopia/file-lint:$(FL_VERSION) file-crlf --text --ignore '$(FL_IGNORES)' --path .
35+
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(PWD):/data cytopia/file-lint:$(FL_VERSION) file-trailing-single-newline --text --ignore '$(FL_IGNORES)' --path .
36+
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(PWD):/data cytopia/file-lint:$(FL_VERSION) file-trailing-space --text --ignore '$(FL_IGNORES)' --path .
37+
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(PWD):/data cytopia/file-lint:$(FL_VERSION) file-utf8 --text --ignore '$(FL_IGNORES)' --path .
38+
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(PWD):/data cytopia/file-lint:$(FL_VERSION) file-utf8-bom --text --ignore '$(FL_IGNORES)' --path .
39+
40+
.PHONY: _lint-shell
41+
_lint-shell:
42+
@echo "# -------------------------------------------------------------------- #"
43+
@echo "# Shellcheck"
44+
@echo "# -------------------------------------------------------------------- #"
45+
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(PWD):/mnt -w /mnt koalaman/shellcheck:stable watcherd

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# watcherd
22

3-
[![Build Status](https://travis-ci.org/devilbox/watcherd.svg?branch=master)](https://travis-ci.org/devilbox/watcherd)
3+
[![linting](https://github.com/devilbox/watcherd/workflows/linting/badge.svg)](https://github.com/devilbox/watcherd/actions?query=workflow%3Alinting)
44

55
**[watcherd](https://github.com/devilbox/watcherp/blob/master/watcherd)** will look for directory changes (added and deleted directories) under the specified path (`-p`) and will execute specified commands or shell scripts (`-a`, `-d`) depending on the event.
66
Once all events have happened during one round (`-i`), a trigger command can be executed (`-t`).

watcherd

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -53,53 +53,58 @@ WITHOUT_SUBSHELL=1
5353
############################################################
5454

5555
function print_help() {
56-
printf "Usage: %s %s\n" "${MY_NAME}" "-p <path> -a <cmd> -d <cmd> [-t <cmd> -w <str> -i <int> -v]"
57-
printf " %s %s\n" "${MY_NAME}" "--help"
58-
printf " %s %s\n" "${MY_NAME}" "--version"
59-
printf "\n"
60-
printf "%s\n" "${MY_NAME} will look for directory changes (added and deleted directories) under the specified"
61-
printf "path (-p) and will execute specified commands or shell scripts (-a, -d) depending on the event.\n"
62-
printf "Once all events have happened during one round (-i), a trigger command can be executed (-t).\n"
56+
printf "Usage: %s %s\\n" "${MY_NAME}" "-p <path> -a <cmd> -d <cmd> [-t <cmd> -w <str> -i <int> -v]"
57+
printf " %s %s\\n" "${MY_NAME}" "--help"
58+
printf " %s %s\\n" "${MY_NAME}" "--version"
59+
printf "\\n"
60+
printf "%s\\n" "${MY_NAME} will look for directory changes (added and deleted directories) under the specified"
61+
printf "path (-p) and will execute specified commands or shell scripts (-a, -d) depending on the event.\\n"
62+
printf "Once all events have happened during one round (-i), a trigger command can be executed (-t).\\n"
6363
printf "Note, the trigger command will only be execute when at least one add or delete command has succeeded with exit code 0."
64-
printf "\n"
65-
printf "\nRequired arguments:\n"
66-
printf " -p <path> %s\n" "Path to directoy to watch for changes."
67-
printf " -a <cmd> %s\n" "Command to execute when a directory was added."
68-
printf " %s\n" "You can also append the following placeholders to your command string:"
69-
printf " %s\n" "%p The full path of the directory that changed (added, deleted)."
70-
printf " %s\n" "%n The name of the directory that changed (added, deleted)."
71-
printf " %s\n" "Example: -a \"script.sh -f %p -c %n -a %p\""
72-
printf " -d <cmd> %s\n" "Command to execute when a directory was deletd."
73-
printf " %s\n" "You can also append the following placeholders to your command string:"
74-
printf " %s\n" "%p The full path of the directory that changed (added, deleted)."
75-
printf " %s\n" "%n The name of the directory that changed (added, deleted)."
76-
printf " %s\n" "Example: -b \"script.sh -f %p -c %n -a %p\""
77-
printf "\nOptional arguments:\n"
78-
printf " -t <cmd> %s\n" "Command to execute after all directories have been added or deleted during one round."
79-
printf " %s\n" "No argument will be appended."
80-
printf " -w <str> %s\n" "The directory watcher to use. Valid values are:"
81-
printf " %s\n" "'inotify': Uses inotifywait to watch for directory changes."
82-
printf " %s\n" "'bash': Uses a bash loop to watch for directory changes."
83-
printf " %s\n" "The default is to use 'bash' as the watcher."
84-
printf " -i <int> %s\n" "When using the bash watcher, specify the interval in seconds for how often"
85-
printf " %s\n" "to look for directory changes."
86-
printf " -v %s\n" "Verbose output."
87-
printf "\nMisc arguments:\n"
88-
printf " --help %s\n" "Show this help screen."
89-
printf " --version %s\n" "Show version information."
64+
printf "\\n"
65+
printf "\\nRequired arguments:\\n"
66+
printf " -p <path> %s\\n" "Path to directoy to watch for changes."
67+
printf " -a <cmd> %s\\n" "Command to execute when a directory was added."
68+
printf " %s\\n" "You can also append the following placeholders to your command string:"
69+
printf " %s\\n" "%p The full path of the directory that changed (added, deleted)."
70+
printf " %s\\n" "%n The name of the directory that changed (added, deleted)."
71+
printf " %s\\n" "Example: -a \"script.sh -f %p -c %n -a %p\""
72+
printf " -d <cmd> %s\\n" "Command to execute when a directory was deletd."
73+
printf " %s\\n" "You can also append the following placeholders to your command string:"
74+
printf " %s\\n" "%p The full path of the directory that changed (added, deleted)."
75+
printf " %s\\n" "%n The name of the directory that changed (added, deleted)."
76+
printf " %s\\n" "Example: -b \"script.sh -f %p -c %n -a %p\""
77+
printf "\\nOptional arguments:\\n"
78+
printf " -t <cmd> %s\\n" "Command to execute after all directories have been added or deleted during one round."
79+
printf " %s\\n" "No argument will be appended."
80+
printf " -w <str> %s\\n" "The directory watcher to use. Valid values are:"
81+
printf " %s\\n" "'inotify': Uses inotifywait to watch for directory changes."
82+
printf " %s\\n" "'bash': Uses a bash loop to watch for directory changes."
83+
printf " %s\\n" "The default is to use 'bash' as the watcher."
84+
printf " -i <int> %s\\n" "When using the bash watcher, specify the interval in seconds for how often"
85+
printf " %s\\n" "to look for directory changes."
86+
printf " -v %s\\n" "Verbose output."
87+
printf "\\nMisc arguments:\\n"
88+
printf " --help %s\\n" "Show this help screen."
89+
printf " --version %s\\n" "Show version information."
9090
}
9191

9292
function print_version() {
93-
printf "Name: %s\n" "${MY_NAME}"
94-
printf "Version: %s (%s)\n" "${MY_VERSION}" "${MY_DATE}"
95-
printf "Author: %s (%s)\n" "${MY_AUTHOR}" "${MY_GPGKEY}"
96-
printf "License: %s\n" "${MY_LICENSE}"
97-
printf "URL: %s\n" "${MY_URL}"
93+
printf "Name: %s\\n" "${MY_NAME}"
94+
printf "Version: %s (%s)\\n" "${MY_VERSION}" "${MY_DATE}"
95+
printf "Author: %s (%s)\\n" "${MY_AUTHOR}" "${MY_GPGKEY}"
96+
printf "License: %s\\n" "${MY_LICENSE}"
97+
printf "URL: %s\\n" "${MY_URL}"
9898
}
9999

100100
function get_subdirs() {
101101
local path="${1}"
102-
find "${path}" -type d \! -name "$( basename "${path}" )" -prune | sort
102+
# shellcheck disable=SC2016
103+
find "${path}" \
104+
| grep -Ev "^${path}\$" \
105+
| grep -Ev "^${path}/.+/" \
106+
| xargs -n1 sh -c 'if [ -d "${1}" ]; then echo "${1}"; fi' -- \
107+
| sort
103108
}
104109

105110
function action() {
@@ -116,12 +121,12 @@ function action() {
116121

117122
if eval "${action}"; then
118123
if [ "${verbose}" -gt "0" ]; then
119-
printf "%s: [%s] [OK] %s succeeded: %s\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "${info}" "${directory}"
124+
printf "%s: [%s] [OK] %s succeeded: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "${info}" "${directory}"
120125
fi
121126
return 0
122127
else
123128
if [ "${verbose}" -gt "0" ]; then
124-
printf "%s: [%s] [ERR] %s failed: %s\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "${info}" "${directory}"
129+
printf "%s: [%s] [ERR] %s failed: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "${info}" "${directory}"
125130
fi
126131
return 1
127132
fi
@@ -137,12 +142,12 @@ function trigger() {
137142
if [ "${changes}" -eq "1" ]; then
138143
if eval "${action}"; then
139144
if [ "${verbose}" -gt "0" ]; then
140-
printf "%s: [%s] [OK] %s succeeded: %s\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "TRIGGER" "${action}"
145+
printf "%s: [%s] [OK] %s succeeded: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "TRIGGER" "${action}"
141146
fi
142147
return 0
143148
else
144149
if [ "${verbose}" -gt "0" ]; then
145-
printf "%s: [%s] [ERR] %s failed: %s\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "TRIGGER" "${action}"
150+
printf "%s: [%s] [ERR] %s failed: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "TRIGGER" "${action}"
146151
fi
147152
# Also return 0 here in order to not abort the loop
148153
return 0
@@ -255,7 +260,7 @@ fi
255260

256261
# Log startup
257262
if [ "${VERBOSE}" -gt "0" ]; then
258-
printf "%s: [%s] Starting daemon.\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )"
263+
printf "%s: [%s] Starting daemon.\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )"
259264
fi
260265

261266

@@ -285,7 +290,7 @@ CHANGES=0
285290
# Use native inotify
286291
if [ "${WATCHER}" = "inotify" ]; then
287292
if [ "${VERBOSE}" -gt "0" ]; then
288-
printf "%s: [%s] Using native inotify to watch for changes.\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )"
293+
printf "%s: [%s] Using native inotify to watch for changes.\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )"
289294
fi
290295
inotifywait \
291296
--quiet \
@@ -310,7 +315,7 @@ if [ "${WATCHER}" = "inotify" ]; then
310315
# Use custom inotify
311316
else
312317
if [ "${VERBOSE}" -gt "0" ]; then
313-
printf "%s: [%s] Using bash loop to watch for changes.\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )"
318+
printf "%s: [%s] Using bash loop to watch for changes.\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )"
314319
fi
315320
while true; do
316321
# Get all directories

0 commit comments

Comments
 (0)