Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d54aad863fc88694092da8d4331c334d6e92af11 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/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
}

Back to the top