Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: de2892cbcaf59bae58b1c556ea56d98b97d9abbe (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#!/usr/bin/env bash

# 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
export BUILD_HOME=${BUILD_HOME:-/shared/eclipse/builds}

# To allow this cron job to work from hudson, or traditional crontab
if [[ -z "${WORKSPACE}" ]]
then
  export UTILITIES_HOME=/shared/eclipse
else
  export UTILITIES_HOME=${WORKSPACE}/utilities/production
fi


# These variable are not correctly defined centrally, 
# and are also defined in various Ant scripts.
# For production, use value for shared instance
HUDSON_PROTOCOL=${HUDSON_PROTOCOL:-"https"}
HUDSON_HOST=${HUDSON_HOST:-"ci.eclipse.org"}
# is standard port for "eclipse", but can not leave blank, since we use ':' in some URLs
HUDSON_PORT=${HUDSON_PORT:-"443"}
HUDSON_ROOT_URI=${HUDSON_ROOT_URI:-"releng"}
# For production, use the special performance machine at eclipse
HUDSON_PERF_HOST=${HUDSON_PERF_HOST:-"ci.eclipse.org"}
HUDSON_PERF_PORT=${HUDSON_PERF_PORT:-"443"}
HUDSON_PERF_PROTOCOL=${HUDSON_PERF_PROTOCOL:-"https"}
LINUX_PERF_SEGMENT=${LINUX_PERF_SEGMENT:-"perftests"}

function convertToZeroPaddedMillisecs ()
{
  inNumber=$1
  printf -v outNumber "%.3f" "${inNumber}" 
  RC=$?
  if [[ $RC != 0 ]]  
  then 
    printf "%s" "InvalidInput"
  else
    printf "%s" "${outNumber}"
  fi  
}

function dropOnDLServer()
{
  eclipseStream=$1
  if [[ -z "${eclipseStream}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide eclipseStream as first argument, for this function $(basename $0)" >&2
    return 1;
  fi


  buildId=$2
  if [[ -z "${buildId}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide buildType as second argument, for this function $(basename $0)" >&2
    return 1;
  fi

  pathToDL=$( dlToPath "$eclipseStream" "$buildId")

  if [[ "$pathToDL" == 1 ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: pathToDL could not be computed." >&2
    return 1
  fi
  toDir="/home/data/httpd/download.eclipse.org/${pathToDL}"
  echo $toDir
}
function updateSiteOnDL()
{
  eclipseStream=$1
  if [[ -z "${eclipseStream}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide eclipseStream as first argument, for this function $(basename $0)" >&2
    return 1;
  fi


  buildId=$2
  if [[ -z "${buildId}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide buildType as second argument, for this function $(basename $0)" >&2
    return 1;
  fi


  # contrary to intuition (and previous behavior, bash 3.1) do NOT use quotes around right side of expression.
  if [[ "${eclipseStream}" =~ ([[:digit:]]*)\.([[:digit:]]*)\.([[:digit:]]*) ]]
  then
    eclipseStreamMajor=${BASH_REMATCH[1]}
    eclipseStreamMinor=${BASH_REMATCH[2]}
    eclipseStreamService=${BASH_REMATCH[3]}
  else
    echo "ERROR: eclipseStream, $eclipseStream, must contain major, minor, and service versions, such as 4.2.0" >&2
    exit 1
  fi
  buildType=${buildId:0:1}

  toSiteDir="/home/data/httpd/download.eclipse.org/eclipse/updates"


  updatesSuffix="builds"

  toMainUpdateDir=$toSiteDir/${eclipseStreamMajor}.${eclipseStreamMinor}-${buildType}-${updatesSuffix}/
  # We'll check for existence, and create if doesn't exist ... as long as it is "under" our
  # toSiteDir, it is likely an intentional new one, rather than an error.
  if [[ ! -d "${toMainUpdateDir}" ]]
  then
    if [[ -d "${toSiteDir}" ]]
    then
      # create
      mkdir -p "${toMainUpdateDir}"
      RC=$?
      if [[ $RC != 0 ]]
      then
        echo "ERROR: could not create main update site: ${toMainUpdateDir}" >&2
        # "return" empty string, as indication of error"
        toMainUpdateDir=""
      fi
    else
      echo "PROGRAM ERROR: main update site root did not exist: ${toSiteDir}" >&2
      # "return" empty string, as indication of error"
      toMainUpdateDir=""
    fi
  fi
  echo $toMainUpdateDir
}
# compute update site on build server
function updateSiteOnBuildDir()
{
  eclipseStream=$1
  if [[ -z "${eclipseStream}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide eclipseStream as first argument, for this function $(basename $0)" >&2
    return 1;
  fi


  buildId=$2
  if [[ -z "${buildId}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide buildType as second argument, for this function $(basename $0)" >&2
    return 1;
  fi

  # contrary to intuition (and previous behavior, bash 3.1) do NOT use quotes around right side of expression.
  if [[ "${eclipseStream}" =~ ([[:digit:]]*)\.([[:digit:]]*)\.([[:digit:]]*) ]]
  then
    eclipseStreamMajor=${BASH_REMATCH[1]}
    eclipseStreamMinor=${BASH_REMATCH[2]}
    eclipseStreamService=${BASH_REMATCH[3]}
  else
    echo "eclipseStream, $eclipseStream, must contain major, minor, and service versions, such as 4.2.0" >&2
    return 1
  fi
  buildType=${buildId:0:1}


  buildRoot=${BUILD_HOME}/${eclipseStreamMajor}${buildType}

  siteDir=${buildRoot}/siteDir
  updatesSuffix="builds"
  fromDir=$siteDir/updates/${eclipseStreamMajor}.${eclipseStreamMinor}-${buildType}-${updatesSuffix}/${buildId}

  echo $fromDir
}

# compute main part of download server drop directory
function dropFromBuildDir ()
{

  eclipseStream=$1
  buildId=$2
  pathFromDL=$( dlFromPath "$eclipseStream" "$buildId" )


  if [[ "$pathFromDL" == 1 ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: pathToDL could not be computed." >&2
    return 1
  fi

  eclipseStreamMajor=${eclipseStream:0:1}
  buildType=${buildId:0:1}

  buildRoot=${BUILD_HOME}/${eclipseStreamMajor}${buildType}

  siteDir=${buildRoot}/siteDir

  fromDir=${siteDir}/${pathFromDL}/${buildId}

  echo "$fromDir"

}

# compute main (middle part) of download site
function dlToPath()
{
  eclipseStream=$1
  if [[ -z "${eclipseStream}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide eclipseStream as first argument, for this function $(basename $0)" >&2
    return 1;
  fi


  buildId=$2
  if [[ -z "${buildId}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide buildId as second argument, for this function $(basename $0)" >&2
    return 1;
  fi

  eclipseStreamMajor=${eclipseStream:0:1}
  buildType=${buildId:0:1}

  pathToDL=eclipse/downloads/drops
  if (( $eclipseStreamMajor > 3 ))
  then
    pathToDL=$pathToDL$eclipseStreamMajor
  fi

  echo $pathToDL
}

function dlFromPath()
{
  eclipseStream=$1
  if [[ -z "${eclipseStream}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide eclipseStream as first argument, for this function $(basename $0)" >&2
    return 1;
  fi


  buildId=$2
  if [[ -z "${buildId}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide buildId as second argument, for this function $(basename $0)" >&2
    return 1;
  fi

  eclipseStreamMajor=${eclipseStream:0:1}
  buildType=${buildId:0:1}

  pathFromDL=eclipse/downloads/drops
  if (( $eclipseStreamMajor > 3 ))
  then
    pathFromDL=$pathFromDL$eclipseStreamMajor
  fi

  echo $pathFromDL
}


function syncDropLocation ()
{
  echo "start syncDropLocation"
  eclipseStream=$1
  if [[ -z "${eclipseStream}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide eclipseStream as first argument, for this function $(basename $0)" >&2
    return 1;
  fi
  echo "eclipseStream: $eclipseStream"

  buildId=$2
  if [[ -z "${buildId}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide buildId as second argument, for this function $(basename $0)" >&2
    return 1;
  fi
  echo "buildId: $buildId"


  EBUILDER_HASH=$3
  if [[ -z "${EBUILDER_HASH}" ]]
  then
    printf "\n\n\t%s\n\n" "ERROR: Must provide builder (or aggregator) hash as fourth argument, for this function $(basename $0)" >&2
    return 1;
  fi
  echo "EBUILDER_HASH: $EBUILDER_HASH"

  eclipseStreamMajor=${eclipseStream:0:1}
  buildType=${buildId:0:1}

  fromDir=$( dropFromBuildDir $eclipseStream $buildId  )
  if [[ ! -d "${fromDir}" ]]
  then
    echo "ERROR: fromDir is not a directory? fromDir: ${fromDir}"
    return 1
  fi


  toDir=$( dropOnDLServer $eclipseStream $buildId )
  if [[ ! -d "${toDir}" ]]
  then
    echo "ERROR: toDir is not a directory? toDir: ${toDir}"
    return 1
  fi

  echo "   fromDir: ${fromDir}" >&1
  echo "     toDir: ${toDir}" >&1

  # here, for dl site, best not to preserve times, since (if mirrored)
  # would be more accurate for mirroring system to have
  # actual times (and we are copying only one specific
  # sub-directory) (But, we do for now, for easier testing)
  if [[ -n "${fromDir}" && -d "${fromDir}" && -n "${toDir}" && -d "${toDir}" ]]
  then
    # Note the slash at end of aggregator ... we do not want to exclude eclipse.platform.releng.aggregator-(builder hash).zip
    # TODO: remove --verbose, once confident it works as expected.
    rsync --times --omit-dir-times --recursive --prune-empty-dirs --exclude="*apitoolingreference/*" --exclude="*org.eclipse.releng.basebuilder/*" --exclude="*eclipse.platform.releng.aggregator/*" --exclude="*/repository/*" --exclude="*workspace-*/*" "${fromDir}" "${toDir}"
    rccode=$?
  else
    rccode=9
  fi
  if [[ $rccode != 0 ]]
  then
    echo "ERROR: rsync did not complete normally.rccode: $rccode"
    return $rccode
  else
    # Now update main DL page index pages, to show available
    source ${UTILITIES_HOME}/sdk/updateIndexFilesFunction.shsource
    updateIndex
  fi

  echo "ending syncDropLocation"
}
function linkURL ()
{
  url="${1}"
  if [[ -z "${url}" ]]
  then 
    echo "Programming error. URL must not be null as argument to 'linkURL'"
    exit 1
  fi
  link="<a href=\"${url}\">${url}</a>"
  echo ${link}
}

function sendEclipseMail ()
{
  TO="$1"
  FROM="$2"
  SUBJECT="$3"
  message1="$4"
  (
  echo "To: ${TO}"
  echo "From: ${FROM}"
  if [[ -n "${InReplyTo}" ]]
  then
    echo "In-Reply-To: ${InReplyTo}"
  fi
  if [[ -n "${Reference}" ]]
  then
    echo "Reference: ${Reference}"
  fi
  echo "MIME-Version: 1.0"
  echo "Content-Type: text/html; charset=utf-8"
  echo "Subject: ${SUBJECT}"
  echo "<html><body>"
  echo -e "${message1}"
  echo "</body></html>"
  ) | /usr/lib/sendmail -t

}

function setToAndFromAddresses ()
{
# This bit of data is used in a few other scripts, such as
# syncDropLocation.sh and updateDropLoction.sh
# It primarily sets the TO and FROM fields for email. 
# It also supplements the SUBJECT.


# override 'TO' in localBuildProperties.shsource if doing local tests
# for initial testing, only to me -- change as desired after initial testing.
if [[ "${buildType}" =~ [PYXU] ]]
then
  case "${buildType}" in
    "P" )
      export TO=${TO:-"sravankumarl@in.ibm.com,jdt-core-dev@eclipse.org"}
      export SUBJECT="Patch Build: ${SUBJECT}" ;;
    "U" )
      export TO=${TO:-"sravankumarl@in.ibm.com,noopur_gupta@in.ibm.com,jdt-ui-dev@eclipse.org"}
      export SUBJECT="Branch SDK Build: ${SUBJECT}" ;;
    "Y" )
      export TO=${TO:-"sravankumarl@in.ibm.com,jdt-core-dev@eclipse.org"}
      export SUBJECT="Branch SDK Build: ${SUBJECT}" ;;
    "X" )
      export TO=${TO:-"sravankumarl@in.ibm.com"}
      export SUBJECT="Experimental Build: ${SUBJECT}" ;;
    *)
      export TO=${TO:-"sravankumarl@in.ibm.com"}
      export SUBJECT="Unknown buildType ${buildType}: ${SUBJECT}"
      echo -e "\n\tWARNING: Unreachable code. Programming error. case statement did not match any pattern!\n"
  esac
else
  if [[ "${invisibleBuild}" == "true" ]]
  then
    export TO=${TO:-"sravankumarl@in.ibm.com, akurtako@redhat.com"}
  else
    export TO=${TO:-"platform-releng-dev@eclipse.org"}
  fi
fi

export FROM=${FROM:-"genie.releng@eclipse.org"}

}

Back to the top