Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/ https://fsfe.org
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.
 
 
 
 
 
 

179 lines
6.6 KiB

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