Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

build-test.sh 7.2KB

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