Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build2.sh 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #!/bin/bash
  2. # -----------------------------------------------------------------------------
  3. # Web page build script
  4. # -----------------------------------------------------------------------------
  5. # This script is called every 5 minutes on www.fsfe.org to rebuild the
  6. # HTML pages from the .xhtml, .xml and .xsl source files. Most of the work,
  7. # however, is done by the Perl script build2.pl.
  8. # -----------------------------------------------------------------------------
  9. SOURCE=.
  10. DEST=../fsfe-web-out/home/www/html
  11. TMP=../fsfe-web-out/home/www/tmp.$$
  12. STATUS=../fsfe-web-out/var/www/web
  13. MAKEFILE_PL=${SOURCE}/Makefile.PL
  14. SVNUPOUTFILE=../fsfe-web-out/tmp/fsfe-svnup-out
  15. SVNUPERRFILE=../fsfe-web-out/tmp/fsfe-svnup-err
  16. # Since we must grep for svn output messages,
  17. # let's ensure we get English messages
  18. export LANG=C
  19. # If there is a build2.pl script started more than 10 minutes ago, kill it and mail alarm
  20. BUILD_STARTED=$(ps --no-headers -C build2.pl -o etime | cut -c 7-8 | sort -r | head -n 1)
  21. if [[ -n "$BUILD_STARTED" && "10#${BUILD_STARTED}" -gt 10 ]] ; then
  22. echo -e "
  23. A build2.pl script has been running for more than 10 minutes,
  24. and was automatically killed.
  25. Please check the build script log at http://status.fsfe.org/web-test/
  26. and fix the cause of the problem.
  27. In case of doubt, please write to system-hackers@fsfeurope.org
  28. " | mail -s "www.fsfe.org: build2.pl warning" web@fsfeurope.org system-hackers@fsfeurope.org
  29. fi
  30. # Redirect output
  31. #exec 1> ${STATUS}/status.txt 2>&1
  32. # If some build script is already running, don't run it.
  33. if ps -C "build-df.sh,build-test.sh,build.sh" -o pid= | grep -q -v "$$"; then
  34. echo "Another build script is currently running. Build postponed."
  35. exit
  36. fi
  37. cd ${SOURCE}
  38. # -----------------------------------------------------------------------------
  39. echo "$(date) Cleaning old build directories."
  40. # -----------------------------------------------------------------------------
  41. rm -rf ${TMP%.*}.*
  42. # -----------------------------------------------------------------------------
  43. echo "$(date) Updating source files from SVN."
  44. # -----------------------------------------------------------------------------
  45. # Update the svn working copy and check if any files were updated.
  46. # Since the "svn update" exit status cannot be trusted, and "svn update -q" is
  47. # always quiet, we have to test the output of "svn update" (ignoring the final
  48. # "At revision" line) and check for any output lines
  49. svn --non-interactive update 2>${SVNUPERRFILE} | grep -v 'At revision' >${SVNUPOUTFILE}
  50. cat ${SVNUPOUTFILE}
  51. # If "svn update" wrote anything to standard error, exit
  52. if test -s ${SVNUPERRFILE} ; then
  53. echo "$(date) svn update produced the following error message. Build aborted"
  54. cat ${SVNUPERRFILE}
  55. cat ${STATUS}/status.txt >> ${STATUS}/status-log.txt
  56. exit
  57. fi
  58. # If there are conflicts in the working copy, exit
  59. if test -n "$(grep '^C' ${SVNUPOUTFILE})" ; then
  60. echo "$(date) There are conflicts in the local svn working copy. Build aborted"
  61. cat ${STATUS}/status.txt >> ${STATUS}/status-log.txt
  62. exit
  63. fi
  64. # Rebuild only if changes were made to the SVN or it hasn't run yet today
  65. # (unless "-f" option is used)
  66. #
  67. # We must run it once every day at least to move events from future to current
  68. # and from current to past.
  69. if test ! -s ${SVNUPOUTFILE} \
  70. -a "$(date -r ${STATUS}/last-run +%F)" == "$(date +%F)" \
  71. -a "$1" != "-f" ; then
  72. echo "$(date) No changes to SVN."
  73. echo "$(date) $(svn info 2>/dev/null | grep '^Revision')"
  74. # In this case we only append to the cumulative status-log.txt file, we don't touch status-finished.txt
  75. cat ${STATUS}/status.txt >> ${STATUS}/status-log.txt
  76. exit
  77. fi
  78. # -----------------------------------------------------------------------------
  79. echo "$(date) Checking Perl modules."
  80. # -----------------------------------------------------------------------------
  81. perl ${MAKEFILE_PL}
  82. # Make sure build.sh and build2.pl are executable
  83. # TODO: this can be removed once we set the "executable" svn property
  84. # to these files
  85. chmod +x tools/build.sh tools/build2.pl
  86. chmod +x cgi-bin/weborder.pl cgi-bin/stacs-register-capacity.pl
  87. chmod +x cgi-bin/stacs-register-workshop.pl
  88. if test "$1" == "-f" ; then
  89. echo "Forced rebuild"
  90. fi
  91. # -----------------------------------------------------------------------------
  92. echo "$(date) Running Makefiles."
  93. # -----------------------------------------------------------------------------
  94. make --silent
  95. # -----------------------------------------------------------------------------
  96. echo "$(date) Building HTML pages."
  97. # -----------------------------------------------------------------------------
  98. touch ${STATUS}/last-run
  99. if test "x`hostname`" = "xekeberg"; then
  100. tools/build2.pl -t 4 -q -o ${TMP} -i .
  101. else
  102. tools/build2.pl -q -o ${TMP} -i .
  103. fi
  104. if test $? -ne 0; then
  105. echo "$(date) Build not complete. Aborting."
  106. cp ${STATUS}/status.txt ${STATUS}/status-finished.txt
  107. cat ${STATUS}/status-finished.txt >> ${STATUS}/status-log.txt
  108. exit 1
  109. fi
  110. # -----------------------------------------------------------------------------
  111. echo "$(date) Linking source files."
  112. # -----------------------------------------------------------------------------
  113. for target in ${TMP}/*; do
  114. test -d ${target} && ln -s ${SOURCE} ${target}/source
  115. done
  116. cd ${SOURCE}
  117. # -----------------------------------------------------------------------------
  118. echo "$(date) Obfuscating email addresses."
  119. # -----------------------------------------------------------------------------
  120. # This replaces all '@' in all html files with '@'. We use '-type f'
  121. # because we want to exclude symlinks (TODO: is -type f still useful now that
  122. # we don't have .symlinks anymore?). Because 'sed -i' is a very expensive
  123. # operation, even if there is no replacement done anyway, we first limit the
  124. # files to operate on to those files that actually contain an '@'.
  125. find ${TMP} -type f -name "*.html" | xargs grep -l '@' | xargs sed -i 's/@/\@/g'
  126. # -----------------------------------------------------------------------------
  127. echo "$(date) Activating new output."
  128. # -----------------------------------------------------------------------------
  129. mv ${DEST} ${DEST}.old
  130. mv ${TMP} ${DEST}
  131. rm -rf ${DEST}.old
  132. # -----------------------------------------------------------------------------
  133. echo "$(date) Generating translation logs."
  134. # -----------------------------------------------------------------------------
  135. tools/translation-log.sh ${DEST}/translations.log ${STATUS}
  136. # -----------------------------------------------------------------------------
  137. echo "$(date) Build complete."
  138. # -----------------------------------------------------------------------------
  139. cp ${STATUS}/status.txt ${STATUS}/status-finished.txt
  140. cat ${STATUS}/status-finished.txt >> ${STATUS}/status-log.txt
  141. cp tools/status.php ${STATUS}/index.php