openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

commit 0117ac2688a310b3378c01c4f8757d9cd2285eeb
parent 8914e0ae7871414622086c53480a0caf05dbf683
Author: Jan Dankert <develop@jandankert.de>
Date:   Sat, 22 Aug 2020 02:27:48 +0200

Recatoring: New script 'update.sh' for a more comfortable way to update the internal ui elements.

Diffstat:
dev-helper/create-output-files.sh | 109-------------------------------------------------------------------------------
dev-helper/tag-version.sh | 4++--
dev-helper/template-watcher.sh | 36------------------------------------
dev-helper/update.php | 1+
dev-helper/update.sh | 106+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 109 insertions(+), 147 deletions(-)

diff --git a/dev-helper/create-output-files.sh b/dev-helper/create-output-files.sh @@ -1,109 +0,0 @@ -#!/bin/bash -# -# -- Only for OpenRat-Developers! -- -# -# Creates files for minified/compiled version of CSS/LESS, JS and XML-Template files. -# Sets file permission bits to World-Readable that the CMS is able to write to these files! -# -# Do NOT use this in production environments! -# -# -echo "Preparing for developer mode" -echo "----------------------------" -echo -echo "Start ("as `whoami` ")" - - -function language -{ - for iso in de en es fr it ru cn; do - - touch ../modules/language/lang-$iso.php - chmod -v a+w ../modules/language/lang-$iso.php - done -} - - - -function check -{ - for jsfile in `find ../modules/cms/ui/themes -name "*.js" -not -name "*.min.js"`; do - jsfile="${jsfile%.*}" - createfile $jsfile.min.js $jsfile.js - done - for jsfile in `find ../modules/template_engine/components -name "*.js" -not -name "*.min.js"`; do - jsfile="${jsfile%.*}" - createfile $jsfile.min.js $jsfile.js - done - - for jsfile in `find ../modules/editor/codemirror -name "*.js" -not -name "*.min.js"`; do - jsfile="${jsfile%.*}" - createfile $jsfile.min.js $jsfile.js - done - - - for tplfile in `find ../modules/cms/ui/themes/ -name "*.tpl.src.xml"`; do - - tplfile="${tplfile%.*}" - tplfile="${tplfile%.*}" - tplfile="${tplfile%.*}" - createfile $tplfile.php; - done - - # CSS-Files - for lessfile in `find ../modules/cms/ui/themes -name "*.less"`; do - lessfile="${lessfile%.*}" - createfile $lessfile.css - createfile $lessfile.min.css; - done - - # CSS-Files - for lessfile in `find ../modules/template_engine/components -name "*.less"`; do - lessfile="${lessfile%.*}" - createfile $lessfile.css - createfile $lessfile.min.css; - done - - createfile ../modules/cms/ui/themes/default/production/combined.min.css - createfile ../modules/cms/ui/themes/default/production/combined.min.js - -} - - -function createfile -{ - file=$1 - copy=$2 - if [ ! -f $file ]; then - if [ ! -z $copy ]; then - cp -v $copy $file - else - touch -d '2000-01-01' $file; - fi - echo "OK: Created $file" - fi - - - if [ -e /etc/apache2/mods-enabled/php7.2.load ] && [ `stat -c %a $file` -ne "666" ]; then - chmod 666 -v $file - fi -} - -function xsdfile -{ - - xsd="../modules/template_engine/components/template.xsd" - if [ -f $xsd ]; then - chmod 666 -v $xsd - fi - - components="../modules/template_engine/components/components.ini" - if [ -f $components ]; then - chmod 666 -v $components - fi - -} - -language -check -xsdfile diff --git a/dev-helper/tag-version.sh b/dev-helper/tag-version.sh @@ -4,8 +4,8 @@ VERSION=$1 if [ -z "$VERSION" ]; then - echo need version number - exit 4; + echo "Usage: $0 <version>" 1>&2; + exit 1; fi DATE=`date -R` diff --git a/dev-helper/template-watcher.sh b/dev-helper/template-watcher.sh @@ -1,36 +0,0 @@ -#!/bin/bash - -# Calling the template compiler if a template or a component was modified. -# -# Need for: -# - inotify-tools -# - curl -# -# On Ubuntu/Debian install them with 'apt-get install inotify-tools curl'. -# - -CMS_URL=$1 - -function update { - echo "update started at $(date)" - curl -X POST -d "type=all" $1/dev-helper/update.php - retVal=$? - if [ $retVal -ne 0 ]; then - echo "An error occured! Returncode was $retVal" - else - echo "Sucessful update." - fi -exit $retVal - echo "update ended at $(date)" -} - -while true; do - # Calling compiler first - update - - echo "waiting for changes ..." - inotifywait --event modify -r ../modules/template_engine/ ../modules/cms/ui/themes/default/html/views/ - echo "a file was changed. updating ..." -done - - diff --git a/dev-helper/update.php b/dev-helper/update.php @@ -48,6 +48,7 @@ if ( @$type ) default: echo "Unknown type"; + http_response_code(400); // "Bad Request" } } diff --git a/dev-helper/update.sh b/dev-helper/update.sh @@ -0,0 +1,106 @@ +#!/bin/bash + +# Calling the template compiler if a template or a component was modified. +# +# Need for: +# - inotify-tools +# - curl +# - getopt +# +# On Ubuntu/Debian install them with 'apt-get install inotify-tools curl'. +# + + +usage() { + echo "Usage: $0 [-t <theme>] [-w] [-x <type>] [-u <host/path>]" 1>&2; + exit 1; +} + +url="http://localhost/" +watch= +type= +theme="default" + +while getopts "wt:x:hu:" o; do + case "${o}" in + t) + theme=${OPTARG} + ;; + w) + watch=true + ;; + h) + usage; exit 1; + ;; + u) + url=${OPTARG} + ;; + x) + type=${OPTARG} + ;; + *) + usage + ;; + esac +done +shift $((OPTIND-1)) + +if [ -z "${type}" ]; then + echo "Select a type" + select type in "tpl" "xsd" "css" "js" "lang"; do + break; + done +fi + +function update { + url=$1 + type=$2 + echo "update started at $(date)" + curl --fail -X POST -d "type=$type" $url/dev-helper/update.php + retVal=$? + if [ $retVal -ne 0 ]; then + echo "An error occured! Returncode was $retVal" + exit 4; + else + echo "Sucessful update." + fi + echo "update ended at $(date)" +} + +function make_writable { + type=$1 + theme=$2 + case $type in + lang ) chmod -v a+w ../modules/language/lang-*.php;; + xsd ) chmod -v a+w ../modules/template_engine/components/template.xsd ../modules/template_engine/components/components.ini;; + css ) chmod -v a+w ../modules/cms/ui/themes/$theme/style/openrat*.css;; + js ) chmod -v a+w ../modules/cms/ui/themes/$theme/script/openrat*.js;; + tpl ) find ../modules/cms/ui/themes/$theme/html/views/ -type f -name "*.php" -exec chmod -v a+w {} \; ;; + * ) echo "unknown type";exit;; + esac +} + +while true; do + # Calling compiler first + make_writable $type $theme + update $url $type + + if [ -z "${watch}" ]; then + echo "not watching, exiting." + exit 0; # Exit, because watching is not enabled + fi; + + echo "waiting for changes ..." + case $type in + lang ) watchfiles="../modules/language/language.yml";; + 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/cms/ui/themes/$theme/html/views/";; + * ) echo "unknown type";exit;; + esac + inotifywait --event modify -r $watchfiles + echo "a file was changed. updating ..." +done + +