commit d6c113194f0a1ea0ac1ff7c18d0c95e0f6f51ed4
parent 4ac4838bad2131cdc9a033d059598ee2f1d4c7ce
Author: Jan Dankert <develop@jandankert.de>
Date: Tue, 20 Oct 2020 00:34:04 +0200
New: update.sh is now able to accept the type 'all'. The script watch-all.sh is not necessary any more.
Diffstat:
2 files changed, 46 insertions(+), 76 deletions(-)
diff --git a/dev-helper/update.sh b/dev-helper/update.sh
@@ -49,11 +49,17 @@ shift $((OPTIND-1))
if [ -z "${type}" ]; then
echo "Select a type"
- select type in "tpl" "xsd" "css" "js" "lang"; do
+ select type in "tpl" "xsd" "css" "js" "lang" "all"; do
break;
done
fi
+if [ "${type}" == "all" ]; then
+ types=(tpl xsd css js lang)
+else
+ types=($type)
+fi
+
function update {
url=$1
type=$2
@@ -82,37 +88,55 @@ function make_writable {
esac
}
-# Kill child processes on CTRL+C
-trap 'echo "Terminating child processes"; pkill -P $$; exit' SIGINT SIGTERM
-while true; do
- # Calling compiler first
+function get_file_to_watch {
+ type=$1
+ theme=$2
+ case $type in
+ lang )
+ watchfiles+=' ../modules/language/';;
+ xsd )
+ watchfiles+=' ../modules/template_engine/components/html';;
+ css )
+ watchfiles+=" ../modules/cms/ui/themes/$theme/style";;
+ js )
+ watchfiles+=" ../modules/cms/ui/themes/$theme/script";;
+ tpl )
+ watchfiles+=" ../modules/template_engine/components/html ../modules/cms/ui/themes/$theme/html/views";;
+
+ * ) echo "unknown type";exit;;
+ esac
+}
+
+
+for type in ${types[*]}; do
make_writable $type $theme
- update $url $type
+done
+
+while true; do
+
+ # Calling update first
+ for type in ${types[*]}; do
+ update $url $type
+ done
+
if [ -z "${watch}" ]; then
echo "not watching, exiting."
exit 0; # Exit, because watching is not enabled
fi;
- echo "Enabling the watcher ..."
- language="../modules/language/language.yml"
- components="../modules/template_engine/components/html"
- style="../modules/cms/ui/themes/$theme/style"
- script="../modules/cms/ui/themes/$theme/script"
- templates="../modules/cms/ui/themes/$theme/html/views"
- case $type in
- lang ) watchfiles="$language";;
- xsd ) watchfiles="$components";;
- css ) watchfiles="$style";;
- js ) watchfiles="$script";;
- tpl ) watchfiles="$templates";;
- * ) echo "unknown type";exit;;
- esac
+ watchfiles=
+ for type in ${types[*]}; do
+ get_file_to_watch $type $theme
+ done
+
+ echo "Watching for files in $watchfiles"
inotifywait --event modify -r $watchfiles &
- echo "Waiting for watcher ..."
+
+ echo "Watching ..."
wait
- echo "a file was changed. updating ..."
+ echo "File change detected, updating ..."
done
diff --git a/dev-helper/watch-all.sh b/dev-helper/watch-all.sh
@@ -1,54 +0,0 @@
-#!/bin/bash
-
-cd "$(dirname "$0")"
-
-# Calling the update script for all types.
-#
-# Need for:
-# - inotify-tools
-# - curl
-# - getopt
-#
-# On Ubuntu/Debian install them with 'apt-get install inotify-tools curl'.
-#
-
-
-usage() {
- echo "Usage: $0 [-u <host/path>]" 1>&2;
- exit 1;
-}
-
-url="http://localhost/"
-type=
-
-while getopts "hu:" o; do
- case "${o}" in
- h)
- usage; exit 1;
- ;;
- u)
- url=${OPTARG}
- ;;
- *)
- usage
- ;;
- esac
-done
-shift $((OPTIND-1))
-
-# Kill child processes on CTRL+C
-trap 'echo "Terminating child processes... ";pkill -P $$' SIGINT SIGTERM
-
-for type in "tpl" "xsd" "css" "js" "lang"; do
- ./update.sh -u $url -x $type -w 2>&1 &
- echo "Started watcher for $type in background with PID $!"
-done
-
-echo "."
-echo "All Watches are started."
-
-echo "Waiting for child processes - Press CTRL + C to exit."
-
-wait # wait for child processes (forever, so the script must be canceled with SIGINT (ctrl+c) or SIGTERM)
-
-echo "All child processes are terminated. Exiting ..."