Skip to main content
summaryrefslogtreecommitdiffstats
blob: fcdca208ff86c34413950bb75e8b139a5b7a755f (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
#!/usr/bin/env bash
#*******************************************************************************
# Copyright (c) 2016, 2017 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
#     David Williams - initial API and implementation
#       Initial version based on similar file in Sim Release repository
#*******************************************************************************


# Small utility to more automatically do the renames the morning of "making visible",
# after artifacts have mirrored. In theory, could be done by a cron or at job.
#
# Note, copy is used, instead of move, so that the parent directory's "modified time" does not change.
# That way the mirroring script won't falsely report "no mirrors" (for a while).
#
# Plus, we "copy over" any existing files, under the assumption that previous labeled files are left in place,
# for a while, so they'd serve as backup. If that ever changes, should make a --backup of
# the original files ... just in case ... but then modified time of parent directory would be
# changed.
#
# And notice we do "artifacts" first, so by the time "content" can be retrieved, by p2, thre will be
# valid artifacts "pointed to". If anyone has already fetched 'content' and in the middle of getting
# artifacts, their downloads should nearly always continue to work (except we do keep only 3 milestones
# in composite, so in theory, they might have stale 'content' data that pointed to an old artifact that
# was no longer in (the newly copied) 'artifacts' file.

function usage ()
{
  printf "\n\t%s" "This utility, ${0##*/}, is to copy the two metadataXX.jars to their final name of metadata.jar." >&2
  printf "\n\t\t%s\n" "Example: ${0##*/} 'trainName' 'checkpoint'" >&2
  printf "\n\t%s" "Both arguments are required." >&2
  printf "\n\t%s" "'trainName' is the final directory segment of where the composite files reside," >&2
  printf "\n\t\t%s\n" "such as neon, oxygen, photon, etc." >&2
  printf "\n\t%s" "'checkpoint' is the pre-visibility label given to the metadata files," >&2
  printf "\n\t\t%s\n" "such as M4, RC1, etc. or simply R for final release, 1 for Update 1, etc.." >&2
  printf "\n\t\t%s\n" "For example, for Neon.1 the file content1.jar is copied to content.jar " >&2
  printf "\n\t\t\t%s\n" "and content1.xml.xz, if it exists, is copied to content.xml.xz" >&2
  printf "\n\t\t%s\n" "If the contentN.jar or artifactsN.jar do not exist, it is treated as an error." >&2
  printf "\n\t\t%s\n" "But if the corresponding "xz" versions do not exist, it is treated as a warning." >&2
}

function changeNamesByCopy ()
{

  REPO_ROOT=$1

  # be paranoid with sanity checks
  if [[ -z "${REPO_ROOT}"  ]]
  then
    printf "\n\t[ERROR] REPO_ROOT must be passed in to this function ${0##*/}\n"
    exit 1
  elif [[ ! -e "${REPO_ROOT}" ]]
  then
    printf "\n\t[ERROR] REPO_ROOT did not exist!\n\tREPO_ROOT: ${REPO_ROOT}\n"
    exit 1
  elif [[ ! -w "${REPO_ROOT}" ]]
  then
    printf "\n\t\[ERROR] We do not appear to have write access to REPO_ROOT\n"
  else
    printf "\n\t[INFO] REPO_ROOT existed as expected:\n\tREPO_ROOT: ${REPO_ROOT}\n\n"
  fi

  artifactsFileName="artifacts"
  contentFileName="content"
  oldArtifactsJarName="${artifactsFileName}${CHECKPOINT}.jar"
  oldContentJarName="${contentFileName}${CHECKPOINT}.jar"
  newArtifactsJarName="${artifactsFileName}.jar"
  newContentJarName="${contentFileName}.jar"
  oldArtifactsXZName="${artifactsFileName}${CHECKPOINT}.xml.xz"
  oldContentXZName="${contentFileName}${CHECKPOINT}.xml.xz"
  newArtifactsXZName="${artifactsFileName}.xml.xz"
  newContentXZName="${contentFileName}.xml.xz"
  
  # Note: we check for all error conditions first, so if there is any one error, we make no changes.
  if [[ ! -e "${REPO_ROOT}/${oldArtifactsJarName}" ]]
  then
    printf "\n\t[ERROR] ${oldArtifactsJarName} did not exist in REPO_ROOT!\n"
    exit 1
  fi
  if [[ ! -e "${REPO_ROOT}/${oldContentJarName}" ]]
  then
    printf "\n\t[ERROR] ${oldContentJarName} did not exist in REPO_ROOT!\n"
    exit 1
  fi

  # TODO: should these be errors?
  if [[ ! -e "${REPO_ROOT}/${oldArtifactsXZName}" ]]
  then
    printf "\n\t[WARNING] ${oldArtifactsXZName} did not exist in REPO_ROOT!\n"
  fi
  if [[ ! -e "${REPO_ROOT}/${oldContentXZName}" ]]
  then
    printf "\n\t[WARNING] ${oldContentXZName} did not exist in REPO_ROOT!\n"
  fi

  # The copy work begins here, still checking for errors on each
  # verbose doesn't help too much if out-format given
  verboseOutput=
  #verboseOutput="--verbose"
  # out-format gives us the names of files copied
  #outputFormat=
  # using %i gives details of "what" changed about existing item. 
  # In our case it typically says something like: '>f..T......artifacts1.jar'
  # Which means "transferred" "file" and its "Time" changed. 
  # (Does say say new name of file, though ... ll -tr will give "most recent" 
  # files at end of listing). 
  outputFormat="--out-format='%i%n%L'"
  rsync ${outputFormat} --group ${verboseOutput} ${REPO_ROOT}/${oldArtifactsJarName} ${REPO_ROOT}/${newArtifactsJarName}
  RC=$?
  if [[ $RC != 0 ]]
  then
    printf "\n\t[ERROR] copy returned a non zero return code for ${oldArtifactsJarName}. RC: $RC\n"
    exit $RC
  fi
  rsync ${outputFormat} --group ${verboseOutput} ${REPO_ROOT}/${oldContentJarName}   ${REPO_ROOT}/${newContentJarName}
  RC=$?
  if [[ $RC != 0 ]]
  then
    printf "\n\t[ERROR] copy returned a non zero return code for ${oldContentJarName}. RC: $RC\n"
    exit $RC
  fi

  if [[ -e ${REPO_ROOT}/${oldArtifactsXZName} ]]
  then
  rsync ${outputFormat} --group ${verboseOutput} ${REPO_ROOT}/${oldArtifactsXZName} ${REPO_ROOT}/${newArtifactsXZName}
  RC=$?
  if [[ $RC != 0 ]]
  then
    printf "\n\t[ERROR] copy returned a non zero return code for ${oldArtifactsXZName}. RC: $RC\n"
    exit $RC
  fi
  fi
  if [[ -e ${REPO_ROOT}/${oldContentXZName} ]]
  then
  rsync ${outputFormat} --group ${verboseOutput} ${REPO_ROOT}/${oldContentXZName}   ${REPO_ROOT}/${newContentXZName}
  RC=$?
  if [[ $RC != 0 ]]
  then
    printf "\n\t[ERROR] copy returned a non zero return code for ${oldContentXZName}. RC: $RC\n"
    exit $RC
  fi
fi

}

# This is entry point to "main" function
# We require both arguments, since to provide a default could lead to
# very bad errors if wrong value of "trainName" was used.

if [[ ! $# = 2 ]]
then
  printf "\n\t[ERROR] Wrong number of arguments to ${0##*/}\n"
  usage
  exit 1
fi


TRAIN_NAME=$1
CHECKPOINT=$2

printf "\n\tArguments to utility were:"
printf "\n\t\tTRAIN_NAME: ${TRAIN_NAME}"
printf "\n\t\tCHECKPOINT: ${CHECKPOINT}\n"

if [[ -z "${CHECKPOINT}" || -z "${TRAIN_NAME}" ]]
then
  # This would be rare. Equates to something like ./makevisible.sh "" M2
  # But, just in case. Note that something like ./makevisible "   " M2
  # is still not handled well.
  printf "\n\t%s\n" "[ERROR]: one or both required arguments were empty?!\n" >&2
  usage
  exit 1
fi

# Note: we do "Sim Rel repo" first, to avoid a small window of users getting
# EPP metadata for update, but the Sim Rel repo not being ready.
# Note: we allow "override" of the repo roots by env. variable to make testing easier.

EPP_REPO_ROOT=${EPP_REPO_ROOT:-/home/data/httpd/download.eclipse.org/technology/epp/packages/${TRAIN_NAME}}
changeNamesByCopy "${EPP_REPO_ROOT}"
RC=$?
if [[ $RC != 0 ]]
then
  printf "\n\t[ERROR] changeNamesByCopy returned non-zero return code. RC: $RC\n"
  exit $RC
fi
exit 0

Back to the top