| #!/usr/bin/env bash |
| |
| # this function accomplished "from a client" the same function that |
| # could be done like this, on the download server (in .../eclipse/downloads directory): |
| # php createIndex4x.php > index.html |
| # php eclipse3x.php > eclipse3x.html |
| # with the important exception that doing from a client, such as using wget, resolves |
| # such variables as _SERVER, and similar, which are null if ran from command line. |
| |
| source localBuildProperties.shsource 2>/dev/null |
| |
| function internalUpdateIndex () |
| { |
| |
| # this localBuildProperties.shsource file is to ease local builds to override some variables. |
| # It should not be used for production builds. |
| source localBuildProperties.shsource 2>/dev/null |
| SITE_HOST=${SITE_HOST:-download.eclipse.org} |
| #echo "SITE_HOST: $SITE_HOST" |
| |
| if [[ $# != 2 ]] |
| then |
| echo "PROGRAM ERROR: this function requires two arguments, in order, " |
| echo " the php page to use to create the html page, named in second argument)." |
| echo " Returning 1" |
| return 1 |
| fi |
| |
| PHP_PAGE=$1 |
| HTML_PAGE=$2 |
| |
| TEMP_INDEX_TXT=tempIndex.txt |
| # remove previous vesrsions, if exists |
| rm ${TEMP_INDEX_TXT} 2>/dev/null |
| |
| wget --no-verbose -O ${TEMP_INDEX_TXT} http://${SITE_HOST}/eclipse/downloads/${PHP_PAGE} 2>&1 |
| rccode=$? |
| if [[ $rccode = 0 ]] |
| then |
| timestamp=$( date +%Y-%m-%d_%H:%M:%S ) |
| TMP_DIR=${TMP_DIR:-/shared/eclipse/tmp} |
| mkdir -p ${TMP_DIR} |
| TMP_SAVES=${TMP_DIR}/tempSAVEindexhtml/$timestamp |
| mkdir -p $TMP_SAVES |
| rsync /home/data/httpd/download.eclipse.org/eclipse/downloads/${HTML_PAGE} $TMP_SAVES/ |
| # TODO: add error checking to making backup |
| rsync ${TEMP_INDEX_TXT} /home/data/httpd/download.eclipse.org/eclipse/downloads/${HTML_PAGE} |
| rccode=$? |
| if [[ $rccode = 0 ]] |
| then |
| echo "INFO: Updated http://${SITE_HOST}/eclipse/downloads/${HTML_PAGE}" |
| # normal exit. Return out the bottom, to include 'remove' temp file. |
| # return 0 |
| else |
| echo "ERROR: Could not copy ${HTML_PAGE} to downlaods. rccode: $rccode" |
| return $rccode |
| fi |
| else |
| echo "ERROR: Could not create or pull ${TEMP_INDEX_TXT} from downloads file ${PHP_PAGE}. rccode: $rccode" |
| return $rccode |
| fi |
| # cleanup |
| rm ${TEMP_INDEX_TXT} |
| return 0 |
| } |
| |
| function updateIndexMAIN () |
| { |
| internalUpdateIndex ${x4X_PHP_PAGE_MAIN} ${x4X_HTML_PAGE_MAIN} |
| # internalUpdateIndex ${x3X_PHP_PAGE_MAIN} ${x3X_HTML_PAGE_MAIN} |
| } |
| |
| |
| function updateIndex () |
| { |
| |
| x4X_PHP_PAGE_MAIN="createIndex4x.php" |
| x4X_HTML_PAGE_MAIN="index.html" |
| x3X_PHP_PAGE_MAIN="createIndex3x.php" |
| x3X_HTML_PAGE_MAIN="eclipse3x.html" |
| |
| # if no arguments, do all |
| if [[ $# == 0 ]] |
| then |
| # 0 args is normal case (now). Update all main indexpages. |
| updateIndexMAIN |
| elif (( $# > 0 )) |
| then |
| # still do all, but print warning |
| updateIndexMAIN |
| echo "WARNING: arguments to updateIndex (\"$@\") were ignored. We update all pages each call." |
| fi |
| |
| return 0 |
| } |