openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

update.sh (3186B)


      1 #!/bin/bash
      2 
      3 cd "$(dirname "$0")"
      4 
      5 # Calling the template compiler if a template or a component was modified.
      6 #
      7 # Need for:
      8 # - inotify-tools
      9 # - curl
     10 # - getopt
     11 #
     12 # On Ubuntu/Debian install them with 'apt-get install inotify-tools curl'.
     13 #
     14 
     15 
     16 usage() {
     17   echo "Usage: $0 [-t <theme>] [-w] [-x <type>] [-u <host/path>]" 1>&2;
     18   exit 1;
     19 }
     20 
     21 url="http://localhost/"
     22 watch=
     23 type=
     24 theme="default"
     25 
     26 while getopts "wt:x:hu:" o; do
     27     case "${o}" in
     28         t)
     29             theme=${OPTARG}
     30             ;;
     31         w)
     32             watch=true
     33             ;;
     34         h)
     35             usage; exit 1;
     36             ;;
     37         u)
     38             url=${OPTARG}
     39             ;;
     40         x)
     41             type=${OPTARG}
     42             ;;
     43         *)
     44             usage
     45             ;;
     46     esac
     47 done
     48 shift $((OPTIND-1))
     49 
     50 if [ -z "${type}" ]; then
     51   echo "Select a type"
     52   select type in "tpl" "xsd" "css" "js" "lang" "all"; do
     53     break;
     54   done
     55 fi
     56 
     57 if [ "${type}" == "all" ]; then
     58   types=(tpl xsd css js lang)
     59 else
     60   types=($type)
     61 fi
     62 
     63 function update {
     64   url=$1
     65   type=$2
     66   echo "update started at $(date)"
     67   curl --fail -X POST -d "type=$type" $url/dev-helper/update.php
     68   retVal=$?
     69   if [ $retVal -ne 0 ]; then
     70     echo "An error occured! Returncode was $retVal"
     71     exit 4;
     72   else
     73     echo "Sucessful update."
     74   fi
     75   echo "update ended   at $(date)"
     76 }
     77 
     78 function make_writable {
     79   type=$1
     80   theme=$2
     81   case $type in
     82         lang ) chmod -v a+w ../modules/language ../modules/language/Language_*.php ../modules/language/Messages*;;
     83         xsd  ) chmod -v a+w ../modules/template_engine/components/template.xsd ../modules/template_engine/components/components.ini;;
     84         css  ) chmod -v a+w ../modules/cms/ui/themes/$theme/style/openrat*.css;;
     85         js   ) find ../modules/cms/ui/themes/$theme/script/ -type f -name "*.min.js" -exec chmod -v a+w {} \; ; find ../modules/template_engine/components/html/ -type f -name "*.min.js" -exec chmod -v a+w {} \; ;;
     86         tpl  ) find ../modules/cms/ui/themes/$theme/html/views/ -type f -name "*.php" -exec chmod -v a+w {} \; ;;
     87         * ) echo "unknown type";exit;;
     88   esac
     89 }
     90 
     91 
     92 function get_file_to_watch {
     93   type=$1
     94   theme=$2
     95   case $type in
     96         lang )
     97           watchfiles+=' ../modules/language/';;
     98         xsd  )
     99           watchfiles+=' ../modules/template_engine/components/html';;
    100         css  )
    101           watchfiles+=" ../modules/cms/ui/themes/$theme/style";;
    102         js   )
    103           watchfiles+=" ../modules/cms/ui/themes/$theme/script";;
    104         tpl  )
    105           watchfiles+=" ../modules/template_engine/components/html ../modules/cms/ui/themes/$theme/html/views";;
    106 
    107         * ) echo "unknown type";exit;;
    108   esac
    109 }
    110 
    111 
    112 for type in ${types[*]}; do
    113   make_writable $type $theme
    114 done
    115 
    116 while true; do
    117 
    118   # Calling update first
    119   for type in ${types[*]}; do
    120     update $url $type
    121   done
    122 
    123 
    124   if [ -z "${watch}" ]; then
    125     echo "not watching, exiting."
    126     exit 0; # Exit, because watching is not enabled
    127   fi;
    128 
    129   watchfiles=
    130   for type in ${types[*]}; do
    131     get_file_to_watch $type $theme
    132   done
    133 
    134   echo "Watching for files in $watchfiles"
    135   inotifywait --event modify -r $watchfiles &
    136 
    137   echo "Watching ..."
    138   wait
    139   echo "File change detected, updating ..."
    140 done
    141 
    142