-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy_packages.bash
More file actions
executable file
·319 lines (249 loc) · 7.83 KB
/
deploy_packages.bash
File metadata and controls
executable file
·319 lines (249 loc) · 7.83 KB
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
#!/bin/bash
# Get directory containing scripts
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
SCRIPT_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
SOURCE="$(readlink "$SOURCE")"
[[ ${SOURCE} != /* ]] && SOURCE="$SCRIPT_DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SCRIPT_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
source "${SCRIPT_DIR}/utils.sh"
function usage() {
echo -e "${RESET}${GREEN}${BOLD}Nextoo Deploy Packages Script${RESET} ${BOLD}version <TAG ME>${RESET}"
cat <<-EOU
Usage: $(basename "${0}") [long option(s)] [option(s)] <base manifest path> <delta manifest path> <output manifest path> <top packages uri>
<base manifest path>
Location of existing packages to to merge in with new packages. If this does not exist, the delta manifiest and packages will still be copied to the output.
*NOTE* Packages from this location are not copied to the output location. It is assumed for now that the output and base will be the same.
<delta manifest path>
Location of the /usr/packages/ directory for the newly build packages and manifest file.
<output manifest path>
Location to copy new packages and place merged manifest.
<top packages uri>
Location to place the new manifest with the added URI to the head.
Options:
-a, --arch Architecture to build (defaults to the output of 'uname -m')
-b, --build Configure environment for building binaries (not needed for user systems)
-d, --debug Enable debugging output
-f, --force Use the directory specified by -d even if it exists already
-h, --help Show this message and exit
-m, --mirror Specify the mirror for getting Gentoo sources (default: distfiles.gentoo.org)
-t, --timestamps Enable timestamps in debug and status output
Arch:
Currently we support 'x86' and 'amd64'. If you don't know, don't worry - auto detection
usually works :)
Build path:
An (empty) directory must always be specified as the build path. If not empty, the -f option
must be present and may lead to unpredictable results.
Profile:
Full Nextoo profile names look like "nextoo:default/linux/amd64/server/router".
Because that's a pain to type, you only need to provide the elements which come after the
architecture. For the amd64 router profile, you'd specify "server/router".
EOU
}
# Assign defaults
MIRROR="http://distfiles.gentoo.org"
# Get command-line options
set +e
args=$(getopt --shell=bash --options="abdfhmt" --longoptions="arch:,build,debug,force,help,mirror:,timestamps" --name="$(basename "${0}")" -- "$@")
if [[ "$?" -ne '0' ]]; then
usage
exit 1
fi
set -e
eval set -- "${args}"
state=options
while [[ ! -z "${1}" ]]; do
case "${1}" in
-a | --arch)
shift
ARCH=$1
shift
;;
-b | --build)
NEXTOO_BUILD=true
shift
;;
-d | --debug)
DEBUG=true
shift
;;
-f | --force)
FORCE=true
shift
;;
-h | --help)
usage
exit 0
;;
-m | --mirror)
shift
MIRROR=$1
shift
;;
-t | --timestamps)
PRINT_DATE_TIMESTAMP=true
shift
;;
--)
state=base_dir
shift
;;
*)
case "${state}" in
base_dir)
BASE_DIR="${1}"
debug "BASE_DIR set to '${BASE_DIR}'"
state=delta_dir
;;
delta_dir)
DELTA_DIR="${1}"
debug "DELTA_DIR set to '${DELTA_DIR}'"
state=output_dir
;;
output_dir)
OUTPUT_DIR="${1}"
debug "OUTPUT_DIR set to '${OUTPUT_DIR}'"
state=packages_uri
;;
packages_uri)
PACKAGES_URI="${1}"
state=too_many_params
;;
too_many_params)
# If there is no additional parameter, work is done
#[[ -z "${1}" ]] && break
error "Unrecognized parameter \"${1}\""
usage
exit 1
;;
*)
error "Unknown state \"${state}\" during parameter processing"
exit 1
;;
esac
shift
;;
esac
done
# Enable debug output if requested
[[ "${DEBUG}" == "true" ]] && set -x
# Validate command-line argument
if [[ -z "${BASE_DIR}" ]]; then
usage
error 'Error: Base manifest directory is undefined.'
exit 1
fi
# Validate command-line argument
if [[ -z "${DELTA_DIR}" ]]; then
usage
error 'Error: Delta manifest directory is undefined.'
exit 1
fi
# Verify Delta manifest directory exists
if [[ -d "${DELTA_DIR}" ]]; then
debug 'Delta directory does not exist.'
fi
# Validate command-line argument
if [[ -z "${OUTPUT_DIR}" ]]; then
usage
error 'Error: Outpout manifest directory is undefined.'
exit 1
fi
# Validate command-line argument
if [[ -z "${PACKAGES_URI}" ]]; then
usage
error 'Error: Packages URI was not provided'
exit 1
fi
function validate_packages_source_dir() {
if [[ ! -f "${DELTA_DIR}/packages/Packages" ]]; then
error 'A Packages manifest/index file, that Portage does not care about, is not in the source directory provided. Assuming wrong delta manifest dir and exiting!'
exit 1
fi
}
function copy_packages_to_target() {
status "Coping packages from ${DELTA_DIR} to ${OUTPUT_DIR} ..."
rsync -urv --exclude="/Packages" "${DELTA_DIR}"/* "${OUTPUT_DIR}"
}
function merge_manifest_files() {
# $1 - base manifest
# $2 - built manifest
# $3 - output manifest
"${SCRIPT_DIR}/manifest_merge.rb" "${1}" "${2}" "${3}"
if [[ $? != 0 ]]; then
error 'Failed to merge the manifest files.'
exit 1
fi
debug "Publishing merged manifest to '${remote_manifest}'..."
rsync "${output_manifest}" "${remote_manifest}"
if [[ $? != 0 ]]; then
error "Failed to publish the merged manifest from '${remote_manifest}'"
exit 1
fi
}
function update_top_manifest_uri() {
# $1 - input file
# $2 - output file
# $3 - uri
./update_header.rb "${1}" "${2}" "${3}"
if [[ $? != 0 ]]; then
error 'Failed to merge the manifest files.'
exit 1
fi
}
function merge_manifests() {
# $1 - remote path
# $1 - output package manifest
# $2 - output manifest with URI
# flow:
# - pull remote manifest
# - merge
# - make backup of target's manifests
# - publish new manifests
local remote_manifest="${1}/packages/Packages"
local base_manifest="/tmp/Packages.base.$$" #the remote manifest will be stored here and treated as the base
local built_manifest="${DELTA_DIR}/Packages"
debug "Fetching remote manifest from '${remote_manifest}'..."
#rsync "${remote_manifest}" "${base_manifest}"
wget "${remote_manifest}" -O "${base_manifest}"
if [[ $? != 0 ]]; then
error "Failed to fetch the remote manifest from '${remote_manifest}'"
exit 1
fi
merge_manifest_files "${base_manifest}" "${built_manifest}" "${2}"
update_top_manifest_uri "${2}" "${3}" "${PACKAGES_URI}"
}
function publish_new_manifests() {
# $1 - remote path
# $2 - output package manifest
# $3 - output manifest with URI
local remote_packages_manifest="${1}/packages/Packages"
local remote_manifest_uri="${1}/Packages"
debug "Pushing package manifest to remote: '${remote_packages_manifest}'..."
rsync "${2}" "${remote_packages_manifest}"
if [[ $? != 0 ]]; then
error "Failed to push manifest to remote: '${remote_packages_manifest}'"
exit 1
fi
debug "Pushing package manifest with URI to remote: '${remote_manifest_uri}'..."
rsync "${3}" "${remote_manifest_uri}"
if [[ $? != 0 ]]; then
error "Failed to push manifest to remote: '${remote_manifest_uri}'"
exit 1
fi
}
function work() {
local output_manifest="/tmp/Packages.out.$$"
local output_manifest_with_uri="/tmp/Packages.out.uri.$$"
local output_staging_dir="output/"
debug 'Creating output staging directory...'
mkdir -p "${output_staging_dir}/packages"
validate_packages_source_dir
#copy_packages_to_target
merge_manifests "${BASE_DIR}" "${output_manifest}" "${output_manifest_with_uri}"
publish_new_manifests "${output_staging_dir}" "${output_manifest}" "${output_manifest_with_uri}"
}
# Call main work function
work
status 'Success'