diff --git a/LICENSE.md b/LICENSE similarity index 100% rename from LICENSE.md rename to LICENSE diff --git a/Makefile b/Makefile index 5412d17..ade7c55 100644 --- a/Makefile +++ b/Makefile @@ -43,11 +43,11 @@ _lint-shell: @echo "# -------------------------------------------------------------------- #" @echo "# Shellcheck" @echo "# -------------------------------------------------------------------- #" - @docker run --rm $$(tty -s && echo "-it" || echo) -v $(PWD):/mnt -w /mnt koalaman/shellcheck:stable watcherd + @docker run --rm $$(tty -s && echo "-it" || echo) -v $(PWD):/mnt -w /mnt koalaman/shellcheck:stable bin/watcherd # ------------------------------------------------------------------------------------------------- # Test Targets # ------------------------------------------------------------------------------------------------- test: - ./test/01.sh + ./tests/01.sh diff --git a/README.md b/README.md index fbd69e7..eba2a56 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ # watcherd ![tag](https://img.shields.io/github/v/tag/devilbox/watcherd.svg?colorB=orange&sort=semver) -[![linting](https://github.com/devilbox/watcherd/workflows/linting/badge.svg)](https://github.com/devilbox/watcherd/actions?query=workflow%3Alinting) -[![test-linux](https://github.com/devilbox/watcherd/workflows/test-linux/badge.svg)](https://github.com/devilbox/watcherd/actions?query=workflow%3Atest-linux) -[![test-macos](https://github.com/devilbox/watcherd/workflows/test-macos/badge.svg)](https://github.com/devilbox/watcherd/actions?query=workflow%3Atest-macos) -[![test-windows](https://github.com/devilbox/watcherd/workflows/test-windows/badge.svg)](https://github.com/devilbox/watcherd/actions?query=workflow%3Atest-windows) +[![linting](https://github.com/devilbox/watcherd/workflows/linting/badge.svg)](https://github.com/devilbox/watcherd/actions/workflows/linting.yml) +[![test-linux](https://github.com/devilbox/watcherd/workflows/test-linux/badge.svg)](https://github.com/devilbox/watcherd/actions/workflows/test-linux.yml) +[![test-macos](https://github.com/devilbox/watcherd/workflows/test-macos/badge.svg)](https://github.com/devilbox/watcherd/actions/workflows/test-macos.yml) +[![test-windows](https://github.com/devilbox/watcherd/workflows/test-windows/badge.svg)](https://github.com/devilbox/watcherd/actions/workflows/test-windows.yml) +[![License](https://img.shields.io/badge/license-MIT-%233DA639.svg)](https://opensource.org/licenses/MIT) -**[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. + +**[watcherd](https://github.com/devilbox/watcherd/blob/master/bin/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. Once all events have happened during one round (`-i`), a trigger command can be executed (`-t`). Note, the trigger command will only be execute when at least one add or delete command has succeeded with exit code 0. @@ -18,7 +20,7 @@ If you need the same functionality to monitor changes of listening ports, check ### Modes -**[watcherd](https://github.com/devilbox/watcherp/blob/master/watcherd)** can either use the native [inotifywait](https://linux.die.net/man/1/inotifywait) implementation or if this is not available on your system use a custom bash implementation. The default is to use bash. +**[watcherd](https://github.com/devilbox/watcherd/blob/master/bin/watcherd)** can either use the native [inotifywait](https://linux.die.net/man/1/inotifywait) implementation or if this is not available on your system use a custom bash implementation. The default is to use bash. ### Placeholders @@ -31,14 +33,14 @@ You can specify the placeholders as many times as you want. See the following ex ### Examples -By using **[vhost_gen.py](https://github.com/devilbox/vhost-gen)** (which is capable of creating Nginx or Apache vhost config files for normal vhosts or reverse proxies), the following will be able to create new nginx vhosts on-the-fly, simply by adding or deleting folders in your main www directory. The trigger command will simply force nginx to reload its configuration after directory changes occured. +By using **[vhost-gen](https://github.com/devilbox/vhost-gen)** (which is capable of creating Nginx or Apache vhost config files for normal vhosts or reverse proxies), the following will be able to create new nginx vhosts on-the-fly, simply by adding or deleting folders in your main www directory. The trigger command will simply force nginx to reload its configuration after directory changes occured. ```shell # %n will be replaced by watcherd with the new directory name # %p will be replaced by watcherd with the new directory path watcherd -v \ -p /shared/httpd \ - -a "vhost_gen.py -p %p -n %n -s" \ + -a "vhost-gen -p %p -n %n -s" \ -d "rm /etc/nginx/conf.d/%n.conf" \ -t "nginx -s reload" ``` @@ -86,3 +88,9 @@ Misc arguments: --help Show this help screen. --version Show version information. ``` + +### License + +**[MIT License](LICENSE)** + +Copyright (c) 2017 [cytopia](https://github.com/cytopia) diff --git a/watcherd b/bin/watcherd similarity index 86% rename from watcherd rename to bin/watcherd index e87804f..6e029e0 100755 --- a/watcherd +++ b/bin/watcherd @@ -29,7 +29,7 @@ MY_DATE="2022-12-17" MY_URL="https://github.com/devilbox/watcherd" MY_AUTHOR="cytopia " MY_GPGKEY="0xA02C56F0" -MY_VERSION="1.0.5" +MY_VERSION="1.0.6" MY_LICENSE="MIT" # Default settings @@ -174,45 +174,65 @@ while [ $# -gt 0 ]; do case "${1}" in -p) shift + if [ -z "${1:-}" ]; then + >&2 echo "${MY_NAME}: -p requires an argument." + exit 1 + fi if [ ! -d "${1}" ]; then - >&2 echo "Specified directory with -p does not exist: '${1}'." + >&2 echo "${MY_NAME}: Specified directory with -p does not exist: '${1}'." exit 1 fi WATCH_DIR="${1}" ;; -a) shift + if [ -z "${1:-}" ]; then + >&2 echo "${MY_NAME}: -a requires an argument." + exit 1 + fi if [ "${1:0:1}" = "-" ]; then - >&2 echo "Specified add command cannot start with '-': '${1}'." + >&2 echo "${MY_NAME}: Specified add command cannot start with '-': '${1}'." exit 1 fi CMD_ADD="${1}" ;; -d) shift + if [ -z "${1:-}" ]; then + >&2 echo "${MY_NAME}: -d requires an argument." + exit 1 + fi if [ "${1:0:1}" = "-" ]; then - >&2 echo "Specified del command cannot start with '-': '${1}'." + >&2 echo "${MY_NAME}: Specified del command cannot start with '-': '${1}'." exit 1 fi CMD_DEL="${1}" ;; -t) shift + if [ -z "${1:-}" ]; then + >&2 echo "${MY_NAME}: -t requires an argument." + exit 1 + fi if [ "${1:0:1}" = "-" ]; then - >&2 echo "Specified trigger command cannot start with '-': '${1}'." + >&2 echo "${MY_NAME}: Specified trigger command cannot start with '-': '${1}'." exit 1 fi CMD_TRIGGER="${1}" ;; -w) shift + if [ -z "${1:-}" ]; then + >&2 echo "${MY_NAME}: -w requires an argument." + exit 1 + fi if [ "${1}" != "bash" ] && [ "${1}" != "inotify" ]; then - >&2 echo "Specified watcher with -w must either be 'bash; or 'inotify': '${1}'." + >&2 echo "${MY_NAME}: Specified watcher with -w must either be 'bash; or 'inotify': '${1}'." exit fi if [ "${1}" = "inotify" ]; then if ! command -v inotifywait >/dev/null 2>&1; then - >&2 echo "Specified watcher 'inotify' requires 'inotifywait' binary. Not found." + >&2 echo "${MY_NAME}: Specified watcher 'inotify' requires 'inotifywait' binary. Not found." exit fi fi @@ -220,8 +240,12 @@ while [ $# -gt 0 ]; do ;; -i) shift + if [ -z "${1:-}" ]; then + >&2 echo "${MY_NAME}: -i requires an argument." + exit 1 + fi if ! echo "${1}" | grep -Eq '^[1-9][0-9]*$'; then - >&2 echo "Specified interval with -i is not a valid integer > 0: '${1}'." + >&2 echo "${MY_NAME}: Specified interval with -i is not a valid integer > 0: '${1}'." exit 1 fi INTERVAL="${1}" @@ -238,8 +262,7 @@ while [ $# -gt 0 ]; do exit 0 ;; *) - echo "Invalid argument: ${1}" - echo "Type '${MY_NAME} --help' for available options." + echo "${MY_NAME}: Invalid argument: ${1}. Type --help for available options." exit 1 ;; esac @@ -248,15 +271,15 @@ done # Make sure required arguments are set if [ -z "${WATCH_DIR}" ]; then - >&2 echo "Error: -p is required. Type --help for more information." + >&2 echo "${MY_NAME}: Error: -p is required. Type --help for more information." exit 1 fi if [ -z "${CMD_ADD}" ]; then - >&2 echo "Error: -a is required. Type --help for more information." + >&2 echo "${MY_NAME}: Error: -a is required. Type --help for more information." exit 1 fi if [ -z "${CMD_DEL}" ]; then - >&2 echo "Error: -d is required. Type --help for more information." + >&2 echo "${MY_NAME}: Error: -d is required. Type --help for more information." exit 1 fi diff --git a/test/01.sh b/tests/01.sh similarity index 97% rename from test/01.sh rename to tests/01.sh index 5405d55..6527330 100755 --- a/test/01.sh +++ b/tests/01.sh @@ -6,7 +6,7 @@ set -o pipefail SCRIPT_PATH="$( cd "$(dirname "$0")" && pwd -P )" -BIN_PATH="${SCRIPT_PATH}/.." +BIN_PATH="${SCRIPT_PATH}/../bin" DIR_PATH="${SCRIPT_PATH}/dirs"