Browse Source

enable normal build of multiple files at once (still not folders); improve and formalise output messages with colours

mxmehl 3 years ago
parent
commit
598362d103
1 changed files with 99 additions and 67 deletions
  1. 99
    67
      fsfe-preview.sh

+ 99
- 67
fsfe-preview.sh View File

@@ -25,6 +25,20 @@
25 25
 #  
26 26
 #######################################################################
27 27
 
28
+# Coloured and tagged output
29
+function echo_ERR {
30
+  echo -e '\033[0;31m'"[ERROR] $1"'\033[0m'
31
+}
32
+function echo_SUC {
33
+  echo -e '\033[0;32m'"[SUCCESS] $1"'\033[0m'
34
+}
35
+function echo_WARN {
36
+  echo -e '\033[0;33m'"[WARNING] $1"'\033[0m'
37
+}
38
+function echo_INFO {
39
+  echo -e '\033[0;37m'"[INFO] $1"'\033[0m'
40
+}
41
+
28 42
 # Check dependencies (stolen from build_main.sh)
29 43
 deperrors=''
30 44
 for depend in realpath rsync xsltproc xmllint sed find egrep grep wc make tee date iconv; do
@@ -50,7 +64,7 @@ source "$ROOT"/config.cfg
50 64
 # Help listing
51 65
 if [ "$1" = "" ]; then
52 66
   self=$(basename $0) 
53
-  echo "No parameters or variables given!"
67
+  echo_WARN "No parameters or variables given!"
54 68
   echo
55 69
   echo "Usage: "
56 70
   echo
@@ -75,11 +89,11 @@ LOC_trunk_dev=$(echo $LOC_trunk_dev | sed 's|/$||')
75 89
 # Pure copy
76 90
 if [ "$1" = "--copy" ]; then
77 91
   numargs=$(($# - 1))
78
-  echo "[INFO] Starting a plain mass copy with $numargs files..."
92
+  echo_INFO "Starting a plain mass copy with $numargs file(s)..."
79 93
   for ((i=1; i <= $numargs; i++)); do
80 94
     SRC_full=$(realpath $2)
81 95
     DST_full=$(echo $SRC_full | sed -E "s|$LOC_trunk|$LOC_out|")
82
-    echo "[INFO] Copying $SRC_full to $DST_full..."
96
+    echo_INFO "Copying $SRC_full to $DST_full..."
83 97
     if [ -d "$SRC_full" ] && [ -e "$DST_full" ]; then
84 98
       rm -rf "$DST_full"
85 99
       cp -R $SRC_full $DST_full
@@ -89,83 +103,101 @@ if [ "$1" = "--copy" ]; then
89 103
     
90 104
     shift
91 105
   done
92
-  echo "[SUCCESS] Copying finished. Files should be visible via the local webserver now."
106
+  echo_SUC "Copying finished. Files should be visible via the local webserver now."
93 107
   exit 0
94 108
 fi
95 109
 
96
-SRC_rel=$1  # e.g. index.en.xhtml
97
-SRC_full=$(realpath $SRC_rel) # Full path to source file
98
-
99
-# CHECK whether the source file is located in LOC_trunk
100
-if [ ! $(echo $SRC_full | grep "$LOC_trunk") ]; then
101
-  echo "[ERROR] Given source file is not part of \$LOC_trunk (currently set to \"$LOC_trunk\"). Please only build files which reside in or below this directory. Aborting now."
102
-  exit 1
110
+# Run through number of files given as arguments
111
+numargs=$#
112
+echo_INFO "Building $numargs file(s)"
113
+if [ $numargs -gt 1 ]; then
114
+  echo 
103 115
 fi
116
+for ((i=1; i <= $numargs; i++)); do
117
+  SRC_rel=$1  # e.g. index.en.xhtml
118
+  SRC_full=$(realpath $SRC_rel) # Full path to source file
119
+
120
+  # CHECK whether the source file is located in LOC_trunk
121
+  if [ ! $(echo $SRC_full | grep "$LOC_trunk") ]; then
122
+    echo_ERR "Given source file is not part of \$LOC_trunk (currently set to \"$LOC_trunk\"). Please only build files which reside in or below this directory. Aborting now."
123
+    exit 1
124
+  fi
104 125
 
105
-# CHECK whether the source file is a directory (only --copy allowed)
106
-if [ -d "$SRC_full" ]; then
107
-  echo "[ERROR] The given file \"$SRC_full\" is a directory. Those can only be copied by using --copy as a parameter."
108
-  echo "NOTE: Using --copy won't build potential .xhtml files inside a directory. If you have this case, please first copy an empty directory and then build the .xhtml files inside them."
109
-  exit 1
110
-fi
126
+  # CHECK whether the source file is a directory (only --copy allowed)
127
+  if [ -d "$SRC_full" ]; then
128
+    echo_ERR "The given file \"$SRC_full\" is a directory. Those can only be copied by using --copy as a parameter."
129
+    echo_ERR "NOTE: Using --copy won't build potential .xhtml files inside a directory. If you have this case, please first copy an empty directory and then build the .xhtml files inside them."
130
+    exit 1
131
+  fi
111 132
 
112
-# TEST if a DEV SVN directory is used. If yes, copy clean file to this Dir
113
-if [ "$LOC_trunk_dev" != "" ]; then
114
-  SRC_full_dev=$(echo $SRC_full | sed -E "s|$LOC_trunk|$LOC_trunk_dev|")
115
-  echo "[INFO] A \"dirty\" Development SVN directory ($LOC_trunk_dev) is being used. Copy file from clean SVN directory ($LOC_trunk) to Development directory..."
116
-  cp $SRC_full $SRC_full_dev  # copy file from clean SVN to dev/dirty SVN
117
-  SRC_full=$SRC_full_dev
118
-  LOC_trunk=$LOC_trunk_dev
119
-fi
133
+  # TEST if a DEV SVN directory is used. If yes, copy clean file to this Dir
134
+  if [ "$LOC_trunk_dev" != "" ]; then
135
+    SRC_full_dev=$(echo $SRC_full | sed -E "s|$LOC_trunk|$LOC_trunk_dev|")
136
+    echo_INFO "A \"dirty\" Development SVN directory ($LOC_trunk_dev) is being used. Copy file from clean SVN directory ($LOC_trunk) to Development directory..."
137
+    cp $SRC_full $SRC_full_dev  # copy file from clean SVN to dev/dirty SVN
138
+    SRC_full=$SRC_full_dev
139
+    LOC_trunk=$LOC_trunk_dev
140
+  fi
120 141
 
121
-echo "[INFO] Using file $SRC_full as source..."
142
+  echo_INFO "Using file $SRC_full as source..."
122 143
 
123
-### TRANSFORM XHTML file path
124
-DST_full=$(echo $SRC_full | sed -E "s|$LOC_trunk|$LOC_out|")  # replace SVN directory by build/HTTP destination
144
+  ### TRANSFORM XHTML file path
145
+  DST_full=$(echo $SRC_full | sed -E "s|$LOC_trunk|$LOC_out|")  # replace SVN directory by build/HTTP destination
125 146
 
126
-### BUILD/COPY FILE depending on file extension
127
-ftype=${SRC_full##*.} # get extension of file
128
-ftype=$(echo "$ftype" | tr '[:upper:]' '[:lower:]')
129
-ftype_build="xhtml" # file types which have to be built
147
+  ### BUILD/COPY FILE depending on file extension
148
+  ftype=${SRC_full##*.} # get extension of file
149
+  ftype=$(echo "$ftype" | tr '[:upper:]' '[:lower:]')
150
+  ftype_build="xhtml" # file types which have to be built
130 151
 
131
-if [[ "$ftype" == @($ftype_build) ]]; then  # XHTML file
132
-  DST_full=$(echo $DST_full | sed -E "s/$ftype_build/html/")  # Replace xhtml by html
133
-  echo "[INFO] XHTML file detected. Going to build into $DST_full ..."
134
-  
135
-  xmllint --noout "$SRC_full" || (echo; echo "[ERROR] Syntax error in $SRC_full. Error message above. Please fix!"; exit 1)
136
-  if [[ "$?" != "0" ]]; then exit 1; fi
137
-  
138
-  $LOC_trunk/build/build_main.sh process_file $SRC_full > $DST_full
152
+  if [[ "$ftype" == @($ftype_build) ]]; then  # XHTML file
153
+    DST_full=$(echo $DST_full | sed -E "s/$ftype_build/html/")  # Replace xhtml by html
154
+    echo_INFO "XHTML file detected. Going to build into $DST_full ..."
155
+    
156
+    xmllint --noout "$SRC_full" || (echo; echo "Syntax error in $SRC_full. Error message above. Please fix!"; exit 1)
157
+    if [[ "$?" != "0" ]]; then exit 1; fi
158
+    
159
+    $LOC_trunk/build/build_main.sh process_file $SRC_full > $DST_full
139 160
 
140
-else # just copy file
141
-  echo "[INFO] File type ($ftype) is detected as not to be built. Just copying it to $DST_full ..."
142
-  cp $SRC_full $DST_full
143
-fi
161
+  else # just copy file
162
+    echo_INFO "File type ($ftype) is detected as not to be built. Just copying it to $DST_full ..."
163
+    cp $SRC_full $DST_full
164
+  fi
144 165
 
145 166
 
146
-### START WEBSERVER if necessary
147
-if [ "$HTTPD" == "python" ]; then   # python
148
-  if [ ! $(pgrep -f "pywebserver-fsfe.py $LOC_out") ]; then
149
-    echo "[INFO] Starting $HTTPD webserver"
150
-    nohup "$ROOT/pywebserver-fsfe.py" "$LOC_out" "$HTTPD_port" > "$ROOT"/pywebserver-fsfe.log 2>&1 &
151
-  else
152
-    echo "[INFO] $HTTPD webserver already seems to be running."
167
+  ### START WEBSERVER if necessary
168
+  if [ "$HTTPD" == "python" ]; then   # python
169
+    if [ ! $(pgrep -f "pywebserver-fsfe.py $LOC_out") ]; then
170
+      echo_INFO "Starting $HTTPD webserver"
171
+      nohup "$ROOT/pywebserver-fsfe.py" "$LOC_out" "$HTTPD_port" > "$ROOT"/pywebserver-fsfe.log 2>&1 &
172
+    else
173
+      echo_INFO "$HTTPD webserver already seems to be running."
174
+    fi
175
+  elif [ "$HTTPD" == "lighttpd" ]; then
176
+    if [ ! $(pgrep lighttpd) ]; then   # lighttpd
177
+      echo_INFO "Starting $HTTPD webserver"
178
+      /usr/sbin/lighttpd -f "$HTTPD_conf"
179
+    else
180
+      echo_INFO "$HTTPD webserver already seems to be running."
181
+    fi
182
+  elif [ "$HTTPD" == "" ]; then   # empty variable
183
+    echo_ERR "No webserver specified. Please define variable HTTPD in config.cfg. Aborting now."
184
+    exit 1
185
+  else    # something custom
186
+    echo_WARN "Unknown webserver defined. Probably you won't be able to see the file in your browser. Building it anyway. Please check variable \"HTTPD\" in config.cfg." 
153 187
   fi
154
-elif [ "$HTTPD" == "lighttpd" ]; then
155
-  if [ ! $(pgrep lighttpd) ]; then   # lighttpd
156
-    echo "[INFO] Starting $HTTPD webserver"
157
-    /usr/sbin/lighttpd -f "$HTTPD_conf"
158
-  else
159
-    echo "[INFO] $HTTPD webserver already seems to be running."
188
+
189
+  ### SHOW RESULTS
190
+  DST_rel=$(echo $DST_full | sed "s|$LOC_out||") # relative path
191
+  echo_SUC "Finished. File can be viewed at http://localhost:5080$DST_rel"
192
+  
193
+  if [ $numargs -gt 1 ]; then
194
+  echo "++++++++++++++++++++++++++++++++++"
160 195
   fi
161
-elif [ "$HTTPD" == "" ]; then   # empty variable
162
-  echo "[ERROR] No webserver specified. Please define variable HTTPD in config.cfg. Aborting now."
163
-  exit 1
164
-else    # something custom
165
-  echo "[WARNING] Unknown webserver defined. Please check variable HTTPD in config.cfg." 
166
-fi
196
+  
197
+  shift
198
+done
167 199
 
168
-### SHOW RESULTS
169
-echo
170
-DST_rel=$(echo $DST_full | sed "s|$LOC_out||") # relative path
171
-echo "[SUCCESS] Finished. File can be viewed at http://localhost:5080$DST_rel"
200
+if [ $numargs -gt 1 ]; then
201
+  echo 
202
+  echo_SUC "$numargs files have been processed. Preview links to each file can be found individually above."
203
+fi

Loading…
Cancel
Save