fr: reword a sentence; remove spurious full stop; comment out Albanian transl. (not...
[enc.git] / fr / kitchen / assemble-all-pages
index 0b1dc43aa20dfb5523d2238f903c0fc89905b4df..75e459c5ba6d55c37b4510f7c1996866de755d8c 100755 (executable)
@@ -1,6 +1,11 @@
 #!/bin/bash
 
-# assemble-all-pages: generates a set of HTML pages with variable parts.
+## assemble-all-pages -- generate a set of HTML pages with variable parts
+#                        for emailselfdefense.fsf.org
+
+## Synopsis:             assemble-all-pages
+
+## Description
 
 # Each page is built from a template and one or several includes, as usual;
 # in addition, several versions of a page can be built from a single
 # inserted, and deletion markers to identify the borders of each deletion
 # and indicate which page(s) the text between those borders belongs to.
 
-# The script processes all the templates in the working directory. The
+# The script processes all the templates in the working directory and the
 # pages are created in the parent directory.
 
 # Ideally, any modifications should be done to the templates or includes,
 # not to the final pages.
 
-
-# All the ingredients are in [...]/enc/[lang]/kitchen/.
-
-# Script:     assemble-all-pages
-
 # Templates:  confirmation.t.html
 #             index.t.html  (contains variable parts for mac and windows)
 #             infographic.t.html
 #             javascript.html
 #             translist.html
 
-# To generate the pages in [...]/enc/[lang]/:
-# - in the terminal, cd to [...]/enc/[lang]/kitchen/ and enter
-#                     $ ./assemble-all-pages
-# - alternatively, display the kitchen/ directory in the file browser
-#   (not the parent directory) and double-click on the script.
+## Graphic-user-interface howto
+
+# - Place the script in the same directory as the templates.
+# - Display this directory in the file browser (do not just unfold the parent
+#   directory) and double-click on the script.
 
 # And if anything goes wrong, you can do a git reset, right?    ;-)
 
-# ==========================================================================
+# ===========================================================================
 
 set -e
+set -o pipefail
+
+function close_term () {
+  printf '\n%s' '*** Close the terminal window or press Return.'; read OK
+  test -z "$OK" && exit $1
+}
 
 # Create temporary files.
-names=$(mktemp -t aap.XXXXXX) || exit 1
-list=$(mktemp -t aap.XXXXXX) || exit 1
-before=$(mktemp -t aap.XXXXXX) || exit 1
-after=$(mktemp -t aap.XXXXXX) || exit 1
+names=$(mktemp -t aap.XXXXXX)  || close_term 1
+list=$(mktemp -t aap.XXXXXX)   || close_term 1
+before=$(mktemp -t aap.XXXXXX) || close_term 1
+after=$(mktemp -t aap.XXXXXX)  || close_term 1
 trap 'rm -f "$names" "$list" "$before" "$after"' EXIT
 
 # List all the templates in the working directory.
 if ls *.t.html > $names  2>/dev/null; then
   sed -i 's,\.t\.html$,,' $names
 else
-  echo "There is no template in this directory." && exit 1
+  echo "*** There is no template in this directory." && close_term 1
 fi
 
 ## Add the includes to the templates.
@@ -75,7 +81,7 @@ while read name; do
     if [ -f "$include" ]; then
       cat $before $include $after > ../$name.html
     else
-      echo "$include is missing." && exit 1
+      echo "$include is missing." && close_term 1
     fi
     sed -i "/^<!-- include virtual=\"$include\"/d" ../$name.html
   done < $list
@@ -93,18 +99,17 @@ echo 'windows' >> $names
 
 while read name ; do
   # Find out which deletions apply.
-  grep '^<!-- START DELETION' ../$name.html \
-  | grep -v "$name" \
-  | sed 's%^<!-- START DELETION \([0-9][0-9]\),.*$%\1%' > $list
-  echo $name
-  # Make the deletions.
+  grep '^<!-- START DELETION' ../$name.html |
+  grep -v "$name" > $list || true
+  sed -i 's%^<!-- START DELETION \([0-9][0-9]\),.*$%\1%' $list
+  # Delete.
   while read deletion; do
     sed -i "/^<!-- START DELETION $deletion/, \
     /^<!-- END DELETION $deletion/d" ../$name.html
   done < $list
-  # Delete the markers and any extra blank lines at the end of the page.
+  # Remove the markers and any extra blank lines at the end of the page.
   sed -i '/^<!-- [A-Z]* DELETION/d' ../$name.html
   sed -i ':a /^\n*$/ {$d; N; ba}' ../$name.html
 done < $names
 
-exit 0
+close_term 0