-
Notifications
You must be signed in to change notification settings - Fork 0
/
dxport
executable file
·468 lines (407 loc) · 13.4 KB
/
dxport
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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
#! /bin/sh
# Copyright (c) 2019, 2020, 2021, 2023 Dennis Wölfing
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
dxport_me="$0"
dxportdir="$(cd "$(dirname "$0")" && pwd)"
dxport_builddir="$dxportdir/build"
dxport_allports=$(find -path ./build -prune -false -o -name '*.port.sh' | sed 's|.*/||;s|\.port\.sh$||' | sort)
dxport_all=$(echo "$dxport_allports" | sed '/^grub$/d')
dxport_absolute_path() {
case "$1" in
/*)
echo "$1"
;;
*)
echo "$PWD/$1"
;;
esac
}
dxport_check_sha256() {
if [ -n "$src_sha256" ]; then
printf "%s\t%s\n" "$src_sha256" "$1" | sha256sum -c
fi
}
dxport_default_funcs() {
prepare_source() {
dxport_unused_prepare_source=yes
}
prepare() {
:
}
build() {
cd "$builddir"
if [ "$buildsystem" = configure ]; then
"$srcdir/configure" --host="$host" --prefix= $extra_configure_flags
elif [ "$buildsystem" = make ]; then
extra_make_flags="CC=$host-gcc prefix= $extra_make_flags"
elif [ "$buildsystem" = none ]; then
return
fi
make $dxport_jobs $make_targets $extra_make_flags
}
install_port() {
cd "$builddir"
if [ -n "$install_targets" ]; then
make $install_targets DESTDIR="$SYSROOT" $extra_make_flags
else
make install-strip DESTDIR="$SYSROOT" $extra_make_flags || make install DESTDIR="$SYSROOT" $extra_make_flags
fi
}
install_license() {
if [ -n "$license_files" ]; then
cd "$srcdir"
mkdir -p "$SYSROOT/share/licenses/$portname"
cp $license_files "$SYSROOT/share/licenses/$portname"
fi
}
post_install() {
:
}
}
dxport_download_git() {
srcdir="$dxport_builddir/$port/${src_basename%.git}"
if [ -d "$srcdir/.git" ]; then
cd "$srcdir"
git fetch origin "${src_commit:-HEAD}"
else
git clone "$src_url" "$srcdir"
fi
cd "$srcdir"
git checkout -fq "${src_commit:-origin/HEAD}"
dxport_hash="$(git rev-parse HEAD)"
: "${revnum:=$(git rev-list --count HEAD)}"
}
dxport_download_sources() {
if [ -n "$src_url" ]; then
src_basename="$(basename "$src_url")"
case "$src_type" in
git)
dxport_download_git
;;
tar*)
dxport_download_tar
;;
zip)
dxport_download_zip
;;
*)
dxport_error "Unsupported src_type '$src_type'"
esac
fi
}
dxport_download_tar() {
[ "$dxport_dump" = yes ] && dxport_archive="$portdir/$src_url" || dxport_archive="$src_basename"
if [ ! -f "$dxport_archive" ] || ! dxport_check_sha256 "$dxport_archive"; then
wget "$src_url" -O "$dxport_archive"
dxport_check_sha256 "$dxport_archive"
fi
tar xf "$dxport_archive"
srcdir="$dxport_builddir/$port/${src_basename%.$src_type}"
}
dxport_download_zip() {
[ "$dxport_dump" = yes ] && dxport_archive="$portdir/$src_url" || dxport_archive="$src_basename"
if [ ! -f "$dxport_archive" ] || ! dxport_check_sha256 "$dxport_archive"; then
wget "$src_url" -O "$dxport_archive"
dxport_check_sha256 "$dxport_archive"
fi
srcdir="$dxport_builddir/$port/${src_basename%.$src_type}"
mkdir -p "$srcdir"
bsdtar xf "$dxport_archive" -C "$srcdir"
}
dxport_dump() (
set -e
portname="$1"
cp -R "$dxportdir/$portname/." "$dxport_builddir/dump/$portname"
dxport_default_funcs
dxport_get_port_info "$portname"
[ "$dxport_dump" = yes ] && return 0
mkdir -p "$dxport_builddir/$portname"
cd "$dxport_builddir/$portname"
dxport_download_sources
prepare_source
case "$dxport_unused_prepare_source:$src_type" in
yes:tar*)
cp "$dxport_archive" "$dxport_builddir/dump/$portname"
src_url="$src_basename"
;;
*)
cd "$srcdir/.."
srcdir_base="$(basename "$srcdir")"
tar cJf "$dxport_builddir/dump/$portname/$srcdir_base.tar.xz" --exclude="$srcdir_base/.git" "$srcdir_base"
src_url="$srcdir_base.tar.xz"
src_type=tar.xz
src_sha256="$(sha256sum "$dxport_builddir/dump/$portname/$src_url" | cut -c1-64)"
esac
cat >> "$dxport_builddir/dump/$portname/$portname.port.sh" << EOF
# PORTDUMP
dxport_dump=yes
revnum='${revnum:-0}'
src_url='$src_url'
src_type='$src_type'
src_sha256='$src_sha256'
EOF
)
dxport_error() {
echo "$dxport_me: $1" >&2
exit 1
}
dxport_get_port_info() {
portdir="$dxportdir/$1"
. "$portdir/$1.port.sh"
dxport_hash="${src_sha256:-$src_commit}"
}
dxport_help() {
cat << EOF
Usage: $dxport_me [OPTIONS] install [INSTALLOPTS] [PORT...]
$dxport_me [OPTIONS] dump [DUMPOPTS] [PORT...]
OPTIONS:
--builddir=BUILDDIR places build files into BUILDDIR
--help print this help
--host=HOST set host to HOST
--sysroot=SYSROOT set sysroot to SYSROOT
INSTALLOPTS:
-d, --no-dependencies do not install port dependencies
-f, --force-install reinstall already installed ports
-j, --jobs=JOBS run up to JOBS jobs in parallel during build
-k, --keep-going do not stop when one port fails to install
-u, --update-only do not install any new ports
-D, --no-update-dependencies do not update already installed dependencies
-U, --no-update do not update already installed ports
DUMPOPTS:
-d, --no-dependencies do not dump port dependencies
EOF
}
dxport_install() (
set -e
portname="$1"
if [ "$dxport_install_no_dependencies" = yes ] && ! dxport_is_explicitly_requested_port "$portname"; then
return
fi
if [ -f "$SYSROOT/local/dxport/$portname" ]; then
dxport_installed_version="$(cat "$SYSROOT/local/dxport/$portname")"
elif [ "$dxport_install_update_only" = yes ]; then return
else
dxport_installed_version=0:0:0
fi
dxport_default_funcs
dxport_get_port_info "$portname"
# We might not know the revnum yet without downloading the source
dxport_new_version="${version:-0}:${revnum:--1}:${dxport_hash:-0}"
if [ "$dxport_install_force_install" != yes ] || ! dxport_is_explicitly_requested_port "$portname"; then
if ! dxport_version_outdated "$dxport_installed_version" "$dxport_new_version"; then
echo "$portname is already up-to-date."
return
fi
if [ "$dxport_install_no_update_dependencies" = yes ] &&
! dxport_is_explicitly_requested_port "$portname" ||
[ "$dxport_install_no_update" = yes ] &&
[ -f "$SYSROOT/local/dxport/$portname" ]; then
echo "$portname is already installed and no update was requested."
return
fi
fi
mkdir -p "$dxport_builddir/$portname"
cd "$dxport_builddir/$portname"
dxport_download_sources
# Check again now that we know the final revnum.
dxport_new_version="${version:-0}:${revnum:-0}:${dxport_hash:-0}"
if [ "$dxport_install_force_install" != yes ] || ! dxport_is_explicitly_requested_port "$portname"; then
if ! dxport_version_outdated "$dxport_installed_version" "$dxport_new_version"; then
echo "$portname is already up-to-date."
return
fi
fi
if [ "$buildsystem" = configure ]; then
builddir="$dxport_builddir/$portname/build-$portname"
rm -rf "$builddir"
mkdir -p "$builddir"
else
builddir="$srcdir"
fi
[ "$dxport_dump" = yes ] || prepare_source
cd "$srcdir"
for p in $patches; do
patch -p1 < "$portdir/$p"
done
prepare
build
install_port
install_license
post_install
if [ -n "$purge" ]; then
for file in $purge; do
rm -rf "$SYSROOT/$file"
done
fi
mkdir -p "$SYSROOT/local/dxport"
echo "${version:-0}:${revnum:-0}:${dxport_hash:-0}" > "$SYSROOT/local/dxport/$portname"
)
dxport_is_explicitly_requested_port() {
case " $dxport_requested_ports " in
*" $1 "*) return 0 ;;
*) return 1 ;;
esac
}
dxport_resolve_dependencies() {
result=
for port; do
unset depends
dxport_get_port_info "$port"
for dependency in $depends; do
result="$result $(dxport_resolve_dependencies "$dependency")"
done
result="$result $port"
done
printf "%s" "$result" | awk -v RS=' ' -v ORS=' ' '!seen[$0]++'
}
dxport_version_outdated() {
IFS=: read -r oldversion oldrevision oldhash newversion newrevision newhash << EOF
$1:$2
EOF
if [ -z "$newhash" ]; then
return 0
fi
if [ "$oldversion:$oldrevision:$oldhash" = 0:0:0 ]; then
return 0
elif ! printf "%s\n" "$newversion" "$oldversion" | sort -CV; then
return 0
elif [ "$oldversion" != "$newversion" ]; then
return 1
elif [ "$newrevision" != -1 ] && [ "$oldrevision" -lt "$newrevision" ]; then
return 0
elif [ "$newrevision" != -1 ] && [ "$oldrevision" != "$newrevision" ]; then
return 1
elif [ "$oldhash" != "$newhash" ]; then
return 0
else
return 1
fi
}
while [ "$#" -gt 0 ]; do
case "$1" in
--builddir=*)
dxport_builddir="$(dxport_absolute_path "${1#--builddir=}")"
shift
;;
--help)
dxport_help
exit
;;
--host=*)
host="${1#--host=}"
shift
;;
--sysroot=*)
SYSROOT="$(dxport_absolute_path "${1#--sysroot=}")"
shift
;;
--)
shift
break
;;
-*)
dxport_error "Unexpected option '$1'"
;;
*)
break
esac
done
if [ "$#" -eq 0 ]; then
dxport_error "No command given"
fi
export dxport_sysroot="$SYSROOT"
export PKG_CONFIG="$dxportdir/dxport-pkg-config"
dxport_jobs=
case "$1" in
install)
[ -n "$host" ] || dxport_error "No host given"
[ -n "${SYSROOT+x}" ] || dxport_error "No sysroot given"
shift
while getopts dfj:kuDU-: dxport_arg; do
case "$dxport_arg" in
d) dxport_install_no_dependencies=yes ;;
f) dxport_install_force_install=yes ;;
j) dxport_jobs="-j$OPTARG" ;;
k) dxport_install_keep_going=yes ;;
u) dxport_install_update_only=yes ;;
D) dxport_install_no_update_dependencies=yes ;;
U) dxport_install_no_update=yes ;;
-)
case "$OPTARG" in
force-install) dxport_install_force_install=yes ;;
jobs=*) dxport_jobs="-j${OPTARG#*=}" ;;
keep-going) dxport_install_keep_going=yes ;;
no-dependencies) dxport_install_no_dependencies=yes ;;
no-update) dxport_install_no_update=yes ;;
no-update-dependencies) dxport_install_no_update_dependencies=yes ;;
update-only) dxport_install_update_only=yes ;;
*) dxport_error "Invalid option '--$OPTARG'"
esac ;;
*) exit 1
esac
done
shift $((OPTIND - 1))
dxport_requested_ports="$(echo "$*" | sed "s/\\ball\\b/$(echo $dxport_all)/g")"
dxport_ports="$(dxport_resolve_dependencies $dxport_requested_ports)" ||
dxport_error "Could not resolve dependencies"
echo "Resolved dependencies:$dxport_ports"
for port in $dxport_ports; do
dxport_install "$port"
if [ $? != 0 ]; then
if [ "$dxport_install_keep_going" = yes ]; then
dxport_install_failed="$dxport_install_failed $port"
else
dxport_error "Failed to install $port"
fi
fi
done
if [ -n "$dxport_install_failed" ]; then
dxport_error "Failed to install the following ports:$dxport_install_failed"
fi
;;
dump)
shift
while getopts d-: dxport_arg; do
case "$dxport_arg" in
d) dxport_no_dependencies=yes ;;
-)
case "$OPTARG" in
no-dependencies) dxport_no_dependencies=yes ;;
*) dxport_error "Invalid option '--$OPTARG'"
esac ;;
*) exit 1
esac
done
shift $((OPTIND - 1))
if [ "$#" = 0 ]; then
dxport_ports=$(echo $dxport_allports)
else
dxport_requested_ports=$(echo "$*" | sed "s/\\ball\\b/$(echo $dxport_allports)/g")
if [ "$dxport_no_dependencies" = yes ]; then
dxport_ports=$dxport_requested_ports
else
dxport_ports=$(dxport_resolve_dependencies $dxport_requested_ports) ||
dxport_error "Could not resolve dependencies"
fi
fi
echo "Dumping ports: $dxport_ports"
mkdir -p "$dxport_builddir/dump"
cp "$dxportdir/dxport" "$dxportdir/dxport-pkg-config" "$dxport_builddir/dump"
for port in $dxport_ports; do
dxport_dump "$port" || dxport_error "Failed to dump port: $port"
done
;;
*)
dxport_error "Unknown command '$1'"
esac