diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1f92e51 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.*~ + diff --git a/PressZilla.meta.js~ b/PressZilla.meta.js~ deleted file mode 100644 index 76df6fc..0000000 --- a/PressZilla.meta.js~ +++ /dev/null @@ -1,16 +0,0 @@ -// ==UserScript== -// @name PressZilla -// @namespace https://www.jboss.org/pressgang -// @description PressGang BugZilla customization -// @author Matthew Casperson -// @include https://bugzilla.redhat.com/* -// @include http://docbuilder.usersys.redhat.com/* -// @include http://docbuilder.ecs.eng.bne.redhat.com/* -// @require http://code.jquery.com/jquery-2.0.3.min.js -// @version 1.6 -// @grant GM_xmlhttpRequest -// @grant unsafeWindow -// @downloadURL http://docbuilder.usersys.redhat.com/PressZilla.user.js -// @updateURL http://docbuilder.usersys.redhat.com/PressZilla.meta.js -// @homepageURL http://docbuilder.usersys.redhat.com -// ==/UserScript== \ No newline at end of file diff --git a/PressZilla.user.js~ b/PressZilla.user.js~ deleted file mode 100644 index 7ad2c0c..0000000 --- a/PressZilla.user.js~ +++ /dev/null @@ -1,530 +0,0 @@ -// ==UserScript== -// @name PressZilla -// @namespace https://www.jboss.org/pressgang -// @description PressGang BugZilla customization -// @author Matthew Casperson -// @include https://bugzilla.redhat.com/* -// @include http://docbuilder.usersys.redhat.com/* -// @include http://docbuilder.ecs.eng.bne.redhat.com/* -// @require http://code.jquery.com/jquery-2.0.3.min.js -// @version 1.7 -// @grant GM_xmlhttpRequest -// @grant unsafeWindow -// @downloadURL http://docbuilder.usersys.redhat.com/PressZilla.user.js -// @updateURL http://docbuilder.usersys.redhat.com/PressZilla.meta.js -// @homepageURL http://docbuilder.usersys.redhat.com -// ==/UserScript== - -var NEW_WINDOW_NAME = "PressZilla"; -var run = false; -var solutionsCache = {}; - -function logToConsole(message) { - console.log(message); -} - -if (window.location.host == "docbuilder.usersys.redhat.com" || window.location.host == "docbuilder.ecs.eng.bne.redhat.com") { - - logToConsole("Detected DocBuilder Window"); - - /* - Here we add listeners for the opening of the various popovers that will be populated with - data otherwise unavailable to the browser due to same origin rules. - */ - - function addClickFunction(buttonId, topicId, popoverId) { - jQuery('#' + buttonId).click(function() { - jQuery('#' + buttonId).attr('disabled', 'true'); - jQuery('#' + buttonId).text('Getting Solutions'); - jQuery('#' + buttonId).removeClass('btn-primary'); - jQuery('#' + buttonId).removeClass('btn-danger'); - jQuery('#' + buttonId).addClass('btn-primary'); - fetchKeywords(topicId, popoverId); - }); - } - - function getSolutions(topic, position, topicId, popoverId) { - logToConsole("Getting solutions"); - - var keywords = ""; - for (var keywordIndex = 0, keywordCount = topic.keywords.length; keywordIndex < keywordCount; ++keywordIndex){ - if (keywords.length != 0) { - if (keywordIndex / keywordCount * 100 < position) { - keywords += " AND "; - } else { - keywords += " OR "; - } - } - keywords += topic.keywords[keywordIndex]; - } - - logToConsole("querying solutions: " + keywords); - - var kcsUrl = "https://api.access.redhat.com/rs/solutions?limit=10&keyword=" + encodeURIComponent(keywords); - - var handleError = function(buttonId) { - jQuery('#' + buttonId).attr('disabled', 'true'); - jQuery('#' + buttonId).text('Connection Failed'); - jQuery('#' + buttonId).removeClass('btn-primary'); - jQuery('#' + buttonId).addClass('btn-danger'); - } - - GM_xmlhttpRequest({ - method: 'GET', - url: kcsUrl, - headers: {Accept: 'application/json'}, - onabort: function() {logToConsole("onabort"); handleError();}, - onerror: function() {logToConsole("onerror"); handleError();}, - onprogress: function() {logToConsole("onprogress");}, - onreadystatechange: function() {logToConsole("onreadystatechange");}, - ontimeout: function() {logToConsole("ontimeout"); handleError();}, - onload: function(topicId, popoverId) { - return function(solutionsResponse) { - logToConsole(solutionsResponse); - - var content = jQuery('#' + popoverId + "content"); - content.empty(); - - if (solutionsResponse.status == 401) { - - solutionsCache[unsafeWindow.eventDetails.topicId].fetching = false; - - var buttonId = popoverId + 'contentbutton'; - - content.append(jQuery('

If you are running Chrome, you will need to log into the Red Hat Customer Portal.

\ -

If you are running Firefox, then the credentials you entered were incorrect. Please confirm that the username and password you entered are valid for the Red Hat Customer Portal.

\ -
\ - \ -
')); - - addClickFunction(buttonId, topicId, popoverId); - } else if (solutionsResponse.status == 200) { - var solutions = JSON.parse(solutionsResponse.responseText); - - if (!solutions.solution) { - if (position > 0) { - getSolutions(topic, position - 25, topicId, popoverId); - } - } else { - var solutionsTable = ""; - - // keep a copy of the results - solutionsCache[topicId].text = solutionsTable; - - content.append(jQuery(solutionsTable)); - } - } - } - }(topicId, popoverId) - }); - } - - function fetchKeywords(topicId, popoverId) { - if (!solutionsCache[unsafeWindow.eventDetails.topicId].fetching) { - - logToConsole("Getting topic keywords"); - - // make a note that we have started processing this topic - solutionsCache[unsafeWindow.eventDetails.topicId].fetching = true; - - var handleError = function() { - var buttonId = popoverId + 'contentbutton'; - jQuery('#' + buttonId).attr('disabled', 'true'); - jQuery('#' + buttonId).text('Connection Failed'); - jQuery('#' + buttonId).removeClass('btn-primary'); - jQuery('#' + buttonId).addClass('btn-danger'); - } - - var specId = unsafeWindow.getSpecIdFromURL(); - var specProductUrl = "http://topika.ecs.eng.bne.redhat.com:8080/pressgang-ccms/rest/1/contentspecnodes/get/json/query;csNodeType=7;contentSpecIds=" + specId + "?expand=" + encodeURIComponent("{\"branches\":[{\"trunk\":{\"name\": \"nodes\"}}]}"); - - setTimeout(function(){ - GM_xmlhttpRequest({ - method: 'GET', - url: specProductUrl, - onabort: function() {logToConsole("onabort"); handleError(); }, - onerror: function() {logToConsole("onerror"); handleError();}, - //onprogress: function() {logToConsole("onprogress");}, - //onreadystatechange: function() {logToConsole("onreadystatechange");}, - ontimeout: function() {logToConsole("ontimeout"); handleError();}, - onload: function(topicId, popoverId) { - return function(specNodesResponse) { - var nodes = JSON.parse(specNodesResponse.responseText); - var product = ""; - for (var nodeIndex = 0, nodeCount = nodes.items.length; nodeIndex < nodeCount; ++nodeIndex) { - var node = nodes.items[nodeIndex].item; - if (node.title == "Product") { - var product = node.additionalText; - break; - } - } - - var additionalKeywords = product.split(" "); - - GM_xmlhttpRequest({ - method: 'GET', - url: topicKeywordUrl, - onabort: function() {logToConsole("onabort"); handleError();}, - onerror: function() {logToConsole("onerror"); handleError();}, - //onprogress: function() {logToConsole("onprogress");}, - //onreadystatechange: function() {logToConsole("onreadystatechange");}, - ontimeout: function() {logToConsole("ontimeout"); handleError();}, - onload: function(topicResponse) { - var topic = JSON.parse(topicResponse.responseText); - topic.keywords = additionalKeywords.concat(topic.keywords); - getSolutions(topic, 100, topicId, popoverId, product); - } - }); - } - }(unsafeWindow.eventDetails.topicId, unsafeWindow.eventDetails.popoverId) - }); - }, 0); - - var topicKeywordUrl = "http://topika.ecs.eng.bne.redhat.com:8080/pressgang-ccms/rest/1/topic/get/json/" + unsafeWindow.eventDetails.topicId + "?expand=%7B%22branches%22%3A%5B%7B%22trunk%22%3A%7B%22name%22%3A+%22keywords%22%7D%7D%5D%7D" - - // see http://stackoverflow.com/questions/11007605/gm-xmlhttprequest-why-is-it-never-firing-the-onload-in-firefox - // and http://wiki.greasespot.net/0.7.20080121.0_compatibility - setTimeout(function(){ - - }, 0); - } - } - - // listen for the kcs popover - jQuery(window).bind("solutions_opened", function(event){ - if (!solutionsCache[unsafeWindow.eventDetails.topicId]) { - - solutionsCache[unsafeWindow.eventDetails.topicId] = {contentFixed: true}; - - var content = jQuery('#' + unsafeWindow.eventDetails.popoverId + "content"); - content.empty(); - - var buttonId = unsafeWindow.eventDetails.popoverId + 'contentbutton'; - - content.append(jQuery('

This popover displays KCS solutions that match the keywords in the topic.

\ -

If you are running Chrome, you first need to log into into the Red Hat Customer Portal.

\ -

If you are running Firefox, you may be prompted for a username and password. These credentials are the ones that you use to log into the Red Hat Customer Portal

\ -
\ - \ -
')); - - addClickFunction(buttonId, unsafeWindow.eventDetails.topicId, unsafeWindow.eventDetails.popoverId); - } - }); - - /* - Build the callout that displays the bug submission link. - */ - var height = 250; - var width = 200; - var smallHeight = 150; - - var callout = null; - - function getSpecIdFromURL() { - var urlComponents = window.location.href.split("/"); - for (var index = urlComponents.length - 1; index >= 0; --index) { - var integer = parseInt(urlComponents[index]); - if (!isNaN(integer)) { - return integer; - } - } - - return null; - } - - function buildBugCallout(top, left, text, parent) { - - var iframeSrc = null; - - var parentSection = parent.parentNode; - while (parentSection && (parentSection.nodeName != "DIV" || parentSection.className != "section")) { - parentSection = parentSection.parentNode; - } - - - if (parentSection && parentSection.nodeName == "DIV" && parentSection.className == "section") { - var elements = parentSection.childNodes; - for (var i = elements.length - 1; i >= 0; --i) { - var element = elements[i]; - if (element.className.match(".*RoleCreateBugPara.*")) { - if (element.innerHTML.match(".*Report a bug.*")) { - iframeSrc = element.children[0].getAttribute("href"); - break; - } - } - } - } - - if (iframeSrc) { - - var bzURLRegex = /.*?(&|\?)comment=(.*?)(&|$)/; - var match = bzURLRegex.exec(iframeSrc); - iframeSrc = iframeSrc.replace("comment=" + match[2], "comment=" + encodeURIComponent("Selected Text: \"" + text + "\"\n\nBug Details: ") + "&short_desc==" + encodeURIComponent("PressZilla Bug")); - - logToConsole(iframeSrc); - - callout = jQuery('
\ -
\ -
\ -
\ -
\ -
\ - \ -
\ -
'); - jQuery(document.body).append(callout); - - jQuery('#PressZillaCalloutButton').click(function(event) { - - var newwindow = window.open(iframeSrc, NEW_WINDOW_NAME, 'directories=0,titlebar=0,toolbar=0,location=0,status=0,menubar=0,scrollbars=no,resizable=no,height=480,width=640'); - newwindow.focus(); - removeCallout(); - }); - } else { - callout = jQuery('
\ -
\ -
\ -
\ -
\ -
\ -
\ - The content selected does not have any bug information. This may be because you selected text in a boilerplate section of the document which was not supplied by PressGang, or because the content specification has not enabled bug links.\ -
\ -
\ -
'); - jQuery(document.body).append(callout); - } - - - } - - function removeCallout() { - if (callout) { - callout.remove(); - callout = null; - } - } - - // http://stackoverflow.com/questions/1335252/how-can-i-get-the-dom-element-which-contains-the-current-selection - function getSelectionBoundaryElement(isStart) { - var range, sel, container; - if (document.selection) { - range = document.selection.createRange(); - range.collapse(isStart); - return {parent: range.parentElement(), selection: range}; - } else { - sel = window.getSelection(); - if (sel.getRangeAt) { - if (sel.rangeCount > 0) { - range = sel.getRangeAt(0); - } - } else { - // Old WebKit - range = document.createRange(); - range.setStart(sel.anchorNode, sel.anchorOffset); - range.setEnd(sel.focusNode, sel.focusOffset); - - // Handle the case when the selection was selected backwards (from the end to the start in the document) - if (range.collapsed !== sel.isCollapsed) { - range.setStart(sel.focusNode, sel.focusOffset); - range.setEnd(sel.anchorNode, sel.anchorOffset); - } - } - - if (range) { - container = range[isStart ? "startContainer" : "endContainer"]; - - // Check if the container is a text node and return its parent if so - return {parent: container.nodeType === 3 ? container.parentNode : container, selection: sel}; - } - } - } - - jQuery(document).mouseup(function(e) { - - if (callout) { - var x = e.pageX; - var y = e.pageY; - var offset = callout.offset(); - - if (x >= offset.left && x <= offset.left + callout.width() && - y >= offset.top && y <= offset.top + callout.height()) { - // click was over callout, so don't do anything - logToConsole("Clicked over callout"); - return; - } - } - - removeCallout(); - var selectionDetails = getSelectionBoundaryElement(true); - if (selectionDetails && selectionDetails.selection && jQuery.trim(selectionDetails.selection.toString()).length != 0) { - - var selectedText = jQuery.trim(selectionDetails.selection.toString()); - var top = jQuery(selectionDetails.parent).offset().top; - var left = jQuery(document.body).offset().left + jQuery(document.body).width() + 20; - - logToConsole(selectedText); - - buildBugCallout(top, left, selectedText, selectionDetails.parent); - } - - return; - }); - -} else if (NEW_WINDOW_NAME == window.name) { - - logToConsole("Detected Bugzilla Window"); - - //jQuery(document.body).css("display", "none"); - - //jQuery(document).ready(function() { - - //jQuery(document.body).css("display", ""); - - if (jQuery("#Bugzilla_login").length != 0) { - // logging in - - var hiddenElements = jQuery("form>input[type=hidden]"); - - var newForm = jQuery('
'); - var newFormInputs = jQuery('\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
\ - \ - \ - \ -
\ - \ - \ - \ -
\ - '); - - newFormInputs.append(hiddenElements); - newForm.append(newFormInputs); - - jQuery("body").empty(); - jQuery("body").css("background-image", "none"); - jQuery("body").append(newForm); - } else if (jQuery("#Create").length != 0) { - // creating a bug - var componentSelect = jQuery('#component'); - componentSelect.css("display", "none"); - var versionSelect = jQuery('#version'); - versionSelect.css("display", "none"); - var shortDesc = jQuery('#short_desc'); - shortDesc.css("display", "none"); - - var comment = jQuery('#comment'); - var commit = jQuery('#commit'); - - var hidden = jQuery('#Create>input[type=hidden]'); - - var assignedTo = jQuery('#assigned_to'); - assignedTo.css("display", "none"); - - var cfBuildId = jQuery('#cf_build_id'); - cfBuildId.css("display", "none"); - - var cfEnvironment = jQuery('#cf_environment'); - cfEnvironment.css("display", "none"); - - - var createForm = jQuery('\ - \ - \ - \ - \ - \ - \ - \ - \ -
\ -
\ -
\ -
' - ); - - createForm.append(componentSelect); - createForm.append(versionSelect); - createForm.append(shortDesc); - createForm.append(assignedTo); - createForm.append(cfBuildId); - createForm.append(cfEnvironment); - createForm.append(hidden); - createForm.find('#CommentCell').append(comment); - createForm.find('#SubmittCell').append(commit); - - jQuery("body").empty(); - jQuery("body").css("background-image", "none"); - comment.attr("rows", 25); - jQuery("body").append(createForm); - - } else if (window.location.pathname == "/show_bug.cgi") { - // Viewing the submitted bug - var regex = /.*?id=(\d+)/; - var match = regex.exec(window.location.href); - if (match) { - var id = match[1]; - var link = jQuery('Bug ' + id + ' Created'); - var close = jQuery(''); - - var createForm = jQuery('\ -
\ - \ - \ - \ - \ - \ - \ - \ -
\ -
\ -
\ -
' - ); - - jQuery("body").empty(); - jQuery("body").css("background-image", "none"); - - jQuery("#LinkCell", createForm).append(link); - jQuery("#CloseCell", createForm).append(close); - jQuery("body").append(createForm); - - } - } else if (jQuery("#bugzilla-body").length != 0) { - // something else (maybe product selection) - var bugzillaBody = jQuery("#bugzilla-body"); - jQuery("body").empty(); - jQuery("body").css("background-image", "none"); - jQuery("body").append(bugzillaBody); - } - //} -} \ No newline at end of file diff --git a/build_books.sh b/build_books.sh index fbe676b..5cc1b8e 100755 --- a/build_books.sh +++ b/build_books.sh @@ -2,30 +2,30 @@ function cleanHTMLDir() { - CLEAN_DIR=$1 + CLEAN_DIR=$1 - if [ -d /var/www/html/${CLEAN_DIR} ] || [ -e /var/www/html/${CLEAN_DIR} ] - then - rm -rf /var/www/html/${CLEAN_DIR} - fi + if [ -d /var/www/html/${CLEAN_DIR} ] || [ -e /var/www/html/${CLEAN_DIR} ] + then + rm -rf /var/www/html/${CLEAN_DIR} + fi } function backupAndCleanHTMLDir() { - CLEAN_DIR=$1 + CLEAN_DIR=$1 - if [ -d /var/www/html/${CLEAN_DIR} ] || [ -e /var/www/html/${CLEAN_DIR} ] - then - if [ -d /var/www/html/backup/${CLEAN_DIR} ] || [ -e /var/www/html/backup/${CLEAN_DIR} ] - then - rm -rf /var/www/html/backup/${CLEAN_DIR} - fi + if [ -d /var/www/html/${CLEAN_DIR} ] || [ -e /var/www/html/${CLEAN_DIR} ] + then + if [ -d /var/www/html/backup/${CLEAN_DIR} ] || [ -e /var/www/html/backup/${CLEAN_DIR} ] + then + rm -rf /var/www/html/backup/${CLEAN_DIR} + fi - mkdir -p /var/www/html/backup/${CLEAN_DIR} - cp -r /var/www/html/${CLEAN_DIR} /var/www/html/backup/${CLEAN_DIR} - rm -rf /var/www/html/${CLEAN_DIR} - fi + mkdir -p /var/www/html/backup/${CLEAN_DIR} + cp -r /var/www/html/${CLEAN_DIR} /var/www/html/backup/${CLEAN_DIR} + rm -rf /var/www/html/${CLEAN_DIR} + fi } @@ -41,8 +41,8 @@ PUBLICAN_BOOK_ZIPS_COMPLETE=${APACHE_HTML_DIR}${PUBLICAN_BOOK_ZIPS} if [ "$#" -lt ${EXPECTED_ARGS} ] then - echo ERROR! Expected more arguments. - exit 1 + echo ERROR! Expected more arguments. + exit 1 fi # Get the suffix on the directory @@ -51,145 +51,121 @@ shift while (( "$#" )) do - IFS='=' read -ra ADDR <<< "$1" - - # Extract the language, Common Content language and CSP id - # from the command line argument - BUILD_LANG=${ADDR[0]} - PUBLICAN_LANG=${ADDR[1]} - CSPID=${ADDR[2]} + IFS='=' read -ra ADDR <<< "$1" - # Shift the arguments down - shift + # Extract the language, Common Content language and CSP id + # from the command line argument + BUILD_LANG=${ADDR[0]} + PUBLICAN_LANG=${ADDR[1]} + CSPID=${ADDR[2]} - # Start with a clean temp dir for every build - if [ -d ${TMP_DIR}${DIR_SUFFIX} ] - then - rm -rf ${TMP_DIR}${DIR_SUFFIX} - fi - - mkdir ${TMP_DIR}${DIR_SUFFIX} + # Shift the arguments down + shift - # Enter the temp directory - pushd ${TMP_DIR}${DIR_SUFFIX} + # Start with a clean temp dir for every build + if [ -d ${TMP_DIR}${DIR_SUFFIX} ] + then + rm -rf ${TMP_DIR}${DIR_SUFFIX} + fi - # Build the book as HTML-SINGLE with no overrides - date > build.log + mkdir ${TMP_DIR}${DIR_SUFFIX} - echo "csprocessor build --lang ${BUILD_LANG} --flatten --editor-links --show-report --target-lang ${PUBLICAN_LANG} --output ${BOOKNAME}.zip ${CSPID} >> build.log" - csprocessor build --lang ${BUILD_LANG} --flatten --editor-links --show-report --target-lang ${PUBLICAN_LANG} --output ${BOOKNAME}.zip ${CSPID} >> build.log + # Enter the temp directory + pushd ${TMP_DIR}${DIR_SUFFIX} - CSP_STATUS=$? - - # If the csp build failed then continue to the next item - if [ $CSP_STATUS != 0 ] - then - cleanHTMLDir ${BUILD_LANG}/${CSPID} + # Build the book as HTML-SINGLE with no overrides + date > build.log - mkdir -p /var/www/html/${BUILD_LANG}/${CSPID} - cp build.log /var/www/html/${BUILD_LANG}/${CSPID} + echo "csprocessor build --lang ${BUILD_LANG} --flatten --editor-links --show-report --target-lang ${PUBLICAN_LANG} --output ${BOOKNAME}.zip ${CSPID} >> build.log" + csprocessor build --lang ${BUILD_LANG} --flatten --editor-links --show-report --target-lang ${PUBLICAN_LANG} --output ${BOOKNAME}.zip ${CSPID} >> build.log - continue - fi + CSP_STATUS=$? - unzip ${BOOKNAME}.zip + backupAndCleanHTMLDir ${BUILD_LANG}/${CSPID} + mkdir -p /var/www/html/${BUILD_LANG}/${CSPID} + cp build.log /var/www/html/${BUILD_LANG}/${CSPID} - # The zip file will be extracted to a directory name that - # refelcts the name of the book. We don't know this name, - # but we can loop over the subdirectories and then break - # once we have processed the first directory. - for dir in ./*/ - do + # If the csp build failed then continue to the next item + if [ $CSP_STATUS != 0 ] + then + continue + fi - # Enter the extracted book directory - pushd ${dir} + unzip ${BOOKNAME}.zip - # Clone the publican.cfg for the html and remark builds - cp publican.cfg publican-html.cfg - cp publican.cfg publican-remarks.cfg + # The zip file will be extracted to a directory name that + # refelcts the name of the book. We don't know this name, + # but we can loop over the subdirectories and then break + # once we have processed the first directory. + for dir in ./*/ + do - # Add the extra options for the html and remark builds - echo -e "\nchunk_first: 1" >> publican-html.cfg - echo -e "\nshow_remarks: 1" >> publican-remarks.cfg + # Enter the extracted book directory + pushd ${dir} - # Do the original publican build - echo "publican build --formats=html-single,pdf --langs=${PUBLICAN_LANG} &> publican.log" - publican build --formats=html-single,pdf --langs=${PUBLICAN_LANG} &> publican.log - - PUBLICAN_STATUS=$? + # Clone the publican.cfg for the remark builds + cp publican.cfg publican-remarks.cfg - mkdir -p /var/www/html/${BUILD_LANG}/${CSPID} - cp publican.log /var/www/html/${BUILD_LANG}/${CSPID} + # Add the extra options for the html and remark builds + echo -e "\nchunk_first: 1" >> publican.cfg + echo -e "\nshow_remarks: 1" >> publican-remarks.cfg - backupAndCleanHTMLDir ${BUILD_LANG}/${CSPID} - mkdir -p /var/www/html/${BUILD_LANG}/${CSPID} - - cp -R tmp/${PUBLICAN_LANG}/html-single/* /var/www/html/${BUILD_LANG}/${CSPID} - cp -R tmp/${PUBLICAN_LANG}/pdf/* /var/www/html/${BUILD_LANG}/${CSPID} + # Do the original publican build + echo "publican build --formats=html-single,pdf,html --langs=${PUBLICAN_LANG} &> publican.log" + publican build --formats=html-single,pdf,html --langs=${PUBLICAN_LANG} &> publican.log - # don't bother with the html or remark if the html-single failed - if [ $PUBLICAN_STATUS == 0 ] - then - - # Clean up - rm -rf tmp - rm publican.log + PUBLICAN_STATUS=$? - # Do the html publican build - echo "publican build --langs=${PUBLICAN_LANG} --formats=html --config=publican-html.cfg &> publican.log" + cp -R tmp/${PUBLICAN_LANG}/html-single/* /var/www/html/${BUILD_LANG}/${CSPID} + cp -R tmp/${PUBLICAN_LANG}/pdf/* /var/www/html/${BUILD_LANG}/${CSPID} + cp publican.log /var/www/html/${BUILD_LANG}/${CSPID} - publican build --langs=${PUBLICAN_LANG} --formats=html --config=publican-html.cfg &> publican.log + # Copy the html to its own directory + cleanHTMLDir ${BUILD_LANG}/${CSPID}/html + mkdir /var/www/html/${BUILD_LANG}/${CSPID}/html - if [ -d /var/www/html/${BUILD_LANG}/${CSPID}/html ] || [ -e /var/www/html/${BUILD_LANG}/${CSPID}/html ] - then - rm -rf /var/www/html/${BUILD_LANG}/${CSPID}/html - fi + cp -R tmp/${PUBLICAN_LANG}/html/* /var/www/html/${BUILD_LANG}/${CSPID}/html + cp publican.log /var/www/html/${BUILD_LANG}/${CSPID}/html - mkdir /var/www/html/${BUILD_LANG}/${CSPID}/html - cp -R tmp/${PUBLICAN_LANG}/html/. /var/www/html/${BUILD_LANG}/${CSPID}/html + # don't bother with the remark if the html-single failed + if [ $PUBLICAN_STATUS == 0 ] + then - cp publican.log /var/www/html/${BUILD_LANG}/${CSPID}/html + # Clean up + rm -rf tmp + rm publican.log - # Clean up - rm -rf tmp - rm publican.log + # Do the remarks build + echo "publican build --langs=${PUBLICAN_LANG} --formats=html-single --config=publican-remarks.cfg &> publican.log" + publican build --langs=${PUBLICAN_LANG} --formats=html-single --config=publican-remarks.cfg &> publican.log - # Do the remarks build - echo "publican build --langs=${PUBLICAN_LANG} --formats=html-single --config=publican-remarks.cfg &> publican.log" + cleanHTMLDir ${BUILD_LANG}/${CSPID}/remarks + mkdir -p /var/www/html/${BUILD_LANG}/${CSPID}/remarks - publican build --langs=${PUBLICAN_LANG} --formats=html-single --config=publican-remarks.cfg &> publican.log + cp -R tmp/${PUBLICAN_LANG}/html-single/* /var/www/html/${BUILD_LANG}/${CSPID}/remarks + cp publican.log /var/www/html/${BUILD_LANG}/${CSPID}/remarks - if [ -d /var/www/html/${BUILD_LANG}/${CSPID}/remarks ] || [ -e /var/www/html/${BUILD_LANG}/${CSPID}/remarks ] - then - rm -rf /var/www/html/${BUILD_LANG}/${CSPID}/remarks - fi - - mkdir -p /var/www/html/${BUILD_LANG}/${CSPID}/remarks - cp -R tmp/${PUBLICAN_LANG}/html-single/. /var/www/html/${BUILD_LANG}/${CSPID}/remarks - - cp publican.log /var/www/html/${BUILD_LANG}/${CSPID}/remarks - -# # Build the publican zip file without editor links -# DATE_MARKER=$(date '+%Y-%m-%dT%k:%M:%S.000%z') -# BOOK_FILE_NAME="${PUBLICAN_BOOK_ZIPS_COMPLETE}/${BUILD_LANG}/${CSPID} ${DATE_MARKER}.zip" +# # Build the publican zip file without editor links +# DATE_MARKER=$(date '+%Y-%m-%dT%k:%M:%S.000%z') +# BOOK_FILE_NAME="${PUBLICAN_BOOK_ZIPS_COMPLETE}/${BUILD_LANG}/${CSPID} ${DATE_MARKER}.zip" # -# if [ -f "${BOOK_FILE_NAME}" ] -# then -# rm -rf "${BOOK_FILE_NAME}" -# fi +# if [ -f "${BOOK_FILE_NAME}" ] +# then +# rm -rf "${BOOK_FILE_NAME}" +# fi # -# echo "csprocessor build --lang ${BUILD_LANG} --output "${BOOK_FILE_NAME}" ${CSPID} >> build.log" -# csprocessor build --lang ${BUILD_LANG} --output "${BOOK_FILE_NAME}" ${CSPID} >> build.log +# echo "csprocessor build --lang ${BUILD_LANG} --target-lang ${PUBLICAN_LANG} --hide-errors --output "${BOOK_FILE_NAME}" ${CSPID} >> build.log" +# csprocessor build --lang ${BUILD_LANG} --target-lang ${PUBLICAN_LANG} --hide-errors --output "${BOOK_FILE_NAME}" ${CSPID} >> build.log + + fi - fi + popd - popd - - # we only want to process one directory - break + # we only want to process one directory + break - done + done - cp build.log /var/www/html/${BUILD_LANG}/${CSPID} - popd + cp build.log /var/www/html/${BUILD_LANG}/${CSPID} + popd done diff --git a/build_original_books.sh b/build_original_books.sh index d6aa6fe..bbd1b2d 100755 --- a/build_original_books.sh +++ b/build_original_books.sh @@ -1,5 +1,15 @@ #!/bin/bash +function cleanHTMLDir() +{ + CLEAN_DIR=$1 + + if [ -d /var/www/html/${CLEAN_DIR} ] || [ -e /var/www/html/${CLEAN_DIR} ] + then + rm -rf /var/www/html/${CLEAN_DIR} + fi +} + TMP_DIR=/tmp/buildbooks BOOKNAME=Book EXPECTED_ARGS=2 @@ -36,146 +46,115 @@ fi while (( "$#" )) do - # Extract the language and CSP id from the - # command line argument - CSPID=$1 - - # Shift the arguments down - shift - - # Start with a clean temp dir for every build - if [ -d ${TMP_DIR}${DIR_SUFFIX} ] - then - rm -rf ${TMP_DIR}${DIR_SUFFIX} - fi - - mkdir ${TMP_DIR}${DIR_SUFFIX} - - # Enter the temp directory - pushd ${TMP_DIR}${DIR_SUFFIX} - - # Build the book as HTML-SINGLE with no overrides - date > build.log - - echo "csprocessor build --flatten --show-report --editor-links --skip-bug-link-validation --output ${BOOKNAME}.zip ${CSPID} >> build.log" - csprocessor build --flatten --editor-links --skip-bug-link-validation --output ${BOOKNAME}.zip ${CSPID} >> build.log - - CSP_STATUS=$? - - # If the csp build failed then continue to the next item - if [ $CSP_STATUS != 0 ] - then - if [ -d /var/www/html/${CSPID} ] - then - rm -rf /var/www/html/${CSPID} - fi - - mkdir /var/www/html/${CSPID} - cp build.log /var/www/html/${CSPID} - - else - unzip ${BOOKNAME}.zip - - # The zip file will be extracted to a directory name that - # refelcts the name of the book. We don't know this name, - # but we can loop over the subdirectories and then break - # once we have processed the first directory. - for dir in ./*/ - do - - # Enter the extracted book directory - pushd ${dir} - - # Clone the publican.cfg for the html and remark builds - cp publican.cfg publican-html.cfg - cp publican.cfg publican-remarks.cfg - - # Add the extra options for the html and remark builds - echo -e "\nchunk_first: 1" >> publican-html.cfg - echo -e "\nshow_remarks: 1" >> publican-remarks.cfg - - # Do the original publican build - echo 'publican build --formats=html-single --langs=en-US &> publican.log' - - publican build --formats=html-single --langs=en-US &> publican.log - - PUBLICAN_STATUS=$? - - if [ -d /var/www/html/${CSPID} ] || [ -e /var/www/html/${CSPID} ] - then - rm -rf /var/www/html/${CSPID} - fi - - mkdir /var/www/html/${CSPID} - cp -R tmp/en-US/html-single/. /var/www/html/${CSPID} - - cp publican.log /var/www/html/${CSPID} - - # don't bother with the html or remark if the html-single failed - if [ $PUBLICAN_STATUS == 0 ] && [ $CSP_STATUS == 0 ] - then - # Clean up - rm -rf tmp - rm publican.log - - # Do the html publican build - echo 'publican build --formats=html --langs=en-US &> publican.log' - - publican build --formats=html --langs=en-US --config=publican-html.cfg &> publican.log - - if [ -d /var/www/html/${CSPID}/html ] || [ -e /var/www/html/${CSPID}/html ] - then - rm -rf /var/www/html/${CSPID}/html - fi - - mkdir /var/www/html/${CSPID}/html - cp -R tmp/en-US/html/. /var/www/html/${CSPID}/html - - cp publican.log /var/www/html/${CSPID}/html - - # Clean up - rm -rf tmp - rm publican.log - - # Do the remarks build - echo 'publican build --formats=html-single --langs=en-US &> publican.log' - - publican build --formats=html-single --langs=en-US --config=publican-remarks.cfg &> publican.log - - if [ -d /var/www/html/${CSPID}/remarks ] || [ -e /var/www/html/${CSPID}/remarks ] - then - rm -rf /var/www/html/${CSPID}/remarks - fi - - mkdir -p /var/www/html/${CSPID}/remarks - cp -R tmp/en-US/html-single/. /var/www/html/${CSPID}/remarks - - cp publican.log /var/www/html/${CSPID}/remarks - - # Build the publican zip file without editor links - DATE_MARKER=$(date '+%Y-%m-%dT%k:%M:%S.000%z') - BOOK_FILE_NAME="${PUBLICAN_BOOK_ZIPS_COMPLETE}/${CSPID} ${DATE_MARKER}.zip" - - if [ -f "${BOOK_FILE_NAME}" ] - then - rm -rf "${BOOK_FILE_NAME}" - fi - - echo "csprocessor build --output "${BOOK_FILE_NAME}" ${CSPID} >> build.log" - csprocessor build --output "${BOOK_FILE_NAME}" ${CSPID} >> build.log - - fi - popd - - # we only want to process one directory - break - - done - - cp build.log /var/www/html/${CSPID} - fi - - popd + # Extract the language and CSP id from the + # command line argument + CSPID=$1 + + # Shift the arguments down + shift + + # Start with a clean temp dir for every build + if [ -d ${TMP_DIR}${DIR_SUFFIX} ] + then + rm -rf ${TMP_DIR}${DIR_SUFFIX} + fi + + mkdir ${TMP_DIR}${DIR_SUFFIX} + + # Enter the temp directory + pushd ${TMP_DIR}${DIR_SUFFIX} + + # Build the book as HTML-SINGLE with no overrides + date > build.log + + echo "csprocessor build --flatten --editor-links --skip-bug-link-validation --output ${BOOKNAME}.zip ${CSPID} >> build.log" + csprocessor build --flatten --editor-links --skip-bug-link-validation --output ${BOOKNAME}.zip ${CSPID} >> build.log + + CSP_STATUS=$? + + cleanHTMLDir ${CSPID} + mkdir /var/www/html/${CSPID} + cp build.log /var/www/html/${CSPID} + + # If the csp build failed then continue to the next item + if [ $CSP_STATUS == 0 ] + then + unzip ${BOOKNAME}.zip + + # The zip file will be extracted to a directory name that + # refelcts the name of the book. We don't know this name, + # but we can loop over the subdirectories and then break + # once we have processed the first directory. + for dir in ./*/ + do + + # Enter the extracted book directory + pushd ${dir} + + # Clone the publican.cfg for the remark builds + cp publican.cfg publican-remarks.cfg + + # Add the extra options for the html and remark builds + echo -e "\nchunk_first: 1" >> publican.cfg + echo -e "\nshow_remarks: 1" >> publican-remarks.cfg + + # Do the original publican build + echo 'publican build --formats=html-single,html --langs=en-US &> publican.log' + publican build --formats=html-single,html --langs=en-US &> publican.log + + PUBLICAN_STATUS=$? + + cp -R tmp/en-US/html-single/* /var/www/html/${CSPID} + cp publican.log /var/www/html/${CSPID} + + # Copy the html to its own directory + cleanHTMLDir ${CSPID}/html + mkdir /var/www/html/${CSPID}/html + + cp -R tmp/en-US/html/* /var/www/html/${CSPID}/html + cp publican.log /var/www/html/${CSPID}/html + + # don't bother with the remark if the html-single failed + if [ $PUBLICAN_STATUS == 0 ] && [ $CSP_STATUS == 0 ] + then + + # Clean up + rm -rf tmp + rm publican.log + + # Do the remarks build + echo 'publican build --formats=html-single --langs=en-US --config=publican-remarks.cfg &> publican.log' + publican build --formats=html-single --langs=en-US --config=publican-remarks.cfg &> publican.log + + cleanHTMLDir ${CSPID}/remarks + mkdir -p /var/www/html/${CSPID}/remarks + + cp -R tmp/en-US/html-single/* /var/www/html/${CSPID}/remarks + cp publican.log /var/www/html/${CSPID}/remarks + + # Build the publican zip file without editor links + DATE_MARKER=$(date '+%Y-%m-%dT%k:%M:%S.000%z') + BOOK_FILE_NAME="${PUBLICAN_BOOK_ZIPS_COMPLETE}/${CSPID} ${DATE_MARKER}.zip" + + if [ -f "${BOOK_FILE_NAME}" ] + then + rm -rf "${BOOK_FILE_NAME}" + fi + + echo "csprocessor build --output "${BOOK_FILE_NAME}" ${CSPID} >> build.log" + csprocessor build --output "${BOOK_FILE_NAME}" ${CSPID} >> build.log + + fi + popd + + # we only want to process one directory + break + + done + + fi + + popd done diff --git a/build_original_books.sh~ b/build_original_books.sh~ deleted file mode 100644 index 9489173..0000000 --- a/build_original_books.sh~ +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash - -TMP_DIR=/tmp/buildbooks -BOOKNAME=Book -EXPECTED_ARGS=2 -# The Apache root html directory -APACHE_HTML_DIR=/var/www/html -# The directory that holds the Publican ZIP files -PUBLICAN_BOOK_ZIPS=/books -# The complete directory that holds the Publican ZIP files -PUBLICAN_BOOK_ZIPS_COMPLETE=${APACHE_HTML_DIR}${PUBLICAN_BOOK_ZIPS} - -if [ "$#" -lt ${EXPECTED_ARGS} ] -then - echo ERROR! Expected more arguments. - exit 1 -fi - -# Get the suffix on the directory -DIR_SUFFIX=$1 -LOCK_FILE=${TMP_DIR}${DIR_SUFFIX}.lock - -# echo ${LOCK_FILE} - -shift - -# Check and create a lock file to make sure builds don't overlap -if [ -f ${LOCK_FILE} ] -then - date >> build_original_books_error.log - echo "ERROR! ${LOCK_FILE} exists, consider increasing the time between builds." >> build_original_books_error.log - exit 1 -else - touch ${LOCK_FILE} -fi - -while (( "$#" )) -do - # Extract the language and CSP id from the - # command line argument - CSPID=$1 - - # Shift the arguments down - shift - - # Start with a clean temp dir for every build - if [ -d ${TMP_DIR}${DIR_SUFFIX} ] - then - rm -rf ${TMP_DIR}${DIR_SUFFIX} - fi - - mkdir ${TMP_DIR}${DIR_SUFFIX} - - # Enter the temp directory - pushd ${TMP_DIR}${DIR_SUFFIX} - - # Build the book as HTML-SINGLE with no overrides - date > build.log - - echo "csprocessor build --flatten --show-report --editor-links --output ${BOOKNAME}.zip ${CSPID} >> build.log" - csprocessor build --flatten --editor-links --output ${BOOKNAME}.zip ${CSPID} >> build.log - - CSP_STATUS=$? - - # If the csp build failed then continue to the next item - if [ $CSP_STATUS != 0 ] - then - if [ -d /var/www/html/${CSPID} ] - then - rm -rf /var/www/html/${CSPID} - fi - - mkdir /var/www/html/${CSPID} - cp build.log /var/www/html/${CSPID} - - else - unzip ${BOOKNAME}.zip - - # The zip file will be extracted to a directory name that - # refelcts the name of the book. We don't know this name, - # but we can loop over the subdirectories and then break - # once we have processed the first directory. - for dir in ./*/ - do - - # Enter the extracted book directory - pushd ${dir} - - # Clone the publican.cfg for the html and remark builds - cp publican.cfg publican-html.cfg - cp publican.cfg publican-remarks.cfg - - # Add the extra options for the html and remark builds - echo -e "\nchunk_first: 1" >> publican-html.cfg - echo -e "\nshow_remarks: 1" >> publican-remarks.cfg - - # Do the original publican build - echo 'publican build --formats=html-single --langs=en-US &> publican.log' - - publican build --formats=html-single --langs=en-US &> publican.log - - PUBLICAN_STATUS=$? - - if [ -d /var/www/html/${CSPID} ] || [ -e /var/www/html/${CSPID} ] - then - rm -rf /var/www/html/${CSPID} - fi - - mkdir /var/www/html/${CSPID} - cp -R tmp/en-US/html-single/. /var/www/html/${CSPID} - - cp publican.log /var/www/html/${CSPID} - - # don't bother with the html or remark if the html-single failed - if [ $PUBLICAN_STATUS == 0 ] && [ $CSP_STATUS == 0 ] - then - # Clean up - rm -rf tmp - rm publican.log - - # Do the html publican build - echo 'publican build --formats=html --langs=en-US &> publican.log' - - publican build --formats=html --langs=en-US --config=publican-html.cfg &> publican.log - - if [ -d /var/www/html/${CSPID}/html ] || [ -e /var/www/html/${CSPID}/html ] - then - rm -rf /var/www/html/${CSPID}/html - fi - - mkdir /var/www/html/${CSPID}/html - cp -R tmp/en-US/html/. /var/www/html/${CSPID}/html - - cp publican.log /var/www/html/${CSPID}/html - - # Clean up - rm -rf tmp - rm publican.log - - # Do the remarks build - echo 'publican build --formats=html-single --langs=en-US &> publican.log' - - publican build --formats=html-single --langs=en-US --config=publican-remarks.cfg &> publican.log - - if [ -d /var/www/html/${CSPID}/remarks ] || [ -e /var/www/html/${CSPID}/remarks ] - then - rm -rf /var/www/html/${CSPID}/remarks - fi - - mkdir -p /var/www/html/${CSPID}/remarks - cp -R tmp/en-US/html-single/. /var/www/html/${CSPID}/remarks - - cp publican.log /var/www/html/${CSPID}/remarks - - # Build the publican zip file without editor links - DATE_MARKER=$(date '+%Y-%m-%dT%k:%M:%S.000%z') - BOOK_FILE_NAME="${PUBLICAN_BOOK_ZIPS_COMPLETE}/${CSPID} ${DATE_MARKER}.zip" - - if [ -f "${BOOK_FILE_NAME}" ] - then - rm -rf "${BOOK_FILE_NAME}" - fi - - echo "csprocessor build --output "${BOOK_FILE_NAME}" ${CSPID} >> build.log" - csprocessor build --output "${BOOK_FILE_NAME}" ${CSPID} >> build.log - - fi - popd - - # we only want to process one directory - break - - done - - cp build.log /var/www/html/${CSPID} - fi - - popd - -done - -# remove the lock file -rm -f ${LOCK_FILE} diff --git a/copy_js_files.sh~ b/copy_js_files.sh~ deleted file mode 100644 index 3b0686e..0000000 --- a/copy_js_files.sh~ +++ /dev/null @@ -1,2 +0,0 @@ -cp -f javascript/overlay.js /var/www/html/javascript -cp -f functions-1.1.js /var/www/html \ No newline at end of file