-
Notifications
You must be signed in to change notification settings - Fork 8
/
xbps-src.sh.in
525 lines (467 loc) · 13.6 KB
/
xbps-src.sh.in
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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
#!/bin/sh
#
# Copyright (c) 2008-2011 Juan Romero Pardines.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#-
readonly XBPS_SRC_VERSION=@@XBPS_SRC_VERSION@@
if [ -n "$IN_CHROOT" ]; then
export XBPS_ETCDIR=/usr/local/etc/xbps
export XBPS_SHAREDIR=/usr/local/share/xbps-src
export XBPS_LIBEXECDIR=/usr/local/libexec/xbps-src
else
export XBPS_PREFIX=${DESTDIR}@@XBPS_INSTALL_PREFIX@@
export XBPS_ETCDIR=${DESTDIR}@@XBPS_INSTALL_ETCDIR@@
export XBPS_SBINDIR=${DESTDIR}@@XBPS_INSTALL_SBINDIR@@
export XBPS_SHAREDIR=${DESTDIR}@@XBPS_INSTALL_SHAREDIR@@
export XBPS_LIBEXECDIR=${DESTDIR}@@XBPS_INSTALL_LIBEXECDIR@@
fi
XBPS_CONFIG_FILE=${XBPS_ETCDIR}/xbps-src.conf
PROGNAME=$(basename $0)
FAKEROOT_CMD=/usr/bin/fakeroot
FAKEROOT_CMD_ARGS="--"
SUDO_CMD=sudo
CHROOT_CMD=chroot
XBPS_MACHINE=$(uname -m)
# Required utilities in host system.
REQHOST_UTILS="awk bash bison sed gcc msgfmt patch makeinfo \
perl fakeroot tar xz gzip bzip2 xbps-bin.static \
xbps-repo.static xbps-uhelper.static"
check_reqhost_utils()
{
local broken
[ -n "$IN_CHROOT" ] && return 0
for f in ${REQHOST_UTILS}; do
if ! command -v ${f} 2>&1 >/dev/null; then
echo "${f} is missing in your system, can't continue!"
broken=1
fi
done
[ -n "$broken" ] && exit 1
}
usage()
{
cat << _EOF
$PROGNAME: [-BCDhKS] [-c file] [-m dir] [-p dir] [-s dir] [target] [pkgname]
Targets:
bootstrap
Build and install from source the bootstrap packages into <masterdir>.
bootstrap-update
Updates bootstrap packages with latest versions available from registered
repositories in the XBPS configuration file, by default set to
<masterdir>/usr/local/etc/xbps/repositories.plist.
build [pkgname]
Build package source (fetch + extract + configure + build).
build-pkg [pkgname|all]
Build a binary package from <pkgname> or all packages with the <all>
keyword. The package(s) must be installed into <destdir> for this to work.
checkvers
Checks installed package versions in <masterdir> against the srcpkgs tree
for new available versions.
chroot
Enter to the chroot in <masterdir>.
clean [pkgname]
Remove <pkgname> build directory.
clean-autodeps
Removes all package dependencies installed automatically.
configure [pkgname]
Configure a package (fetch + extract + configure).
extract [pkgname]
Extract package source distribution file(s) into the build directory.
By default set to <masterdir>/builddir.
fetch [pkgname]
Download package source distribution file(s).
install [pkgname]
Installs a package into destination directory and \`stows' its files into
<masterdir>. If a package is not from bootstrap group, its files will be
symlinked rather than being fully copied.
list
List installed packages in <masterdir>.
make-repoidx
Build a package index for the local repository associated with the
master directory <masterdir>. By default set to <masterdir/host/binpkgs.
To specify another repo, use -p <dir>.
remove [pkgname]
Remove package completely from <destdir> and <masterdir>.
show [pkgname]
Show information for the specified package.
show-deps <pkgname> <build|run>
Show required dependencies for <pkgname>. If <build> is set, only build time
dependencies are shown, if <run> is set only run time dependencies are shown.
show-files <pkgname>
Show package files from <pkgname>. Package must be fully installed
into <masterdir> for this to work (stowed).
show-revdeps <pkgname>
Show reverse dependencies for <pkgname>, i.e packages that are currently
depending on <pkgname>.
stow [pkgname]
Stow <pkgname> files from <destdir> into <masterdir> and register package
in database. When a package is \`stowed', its files will be available in
<masterdir>, and other packages will be able to found it.
unstow [pkgname]
Remove <pkgname> files from <masterdir> and unregister package
from database.
On targets that accept [pkgname], a package name can be specified and xbps-src
will execute the task on any CWD (Current Working Directory). If the argument
is omitted xbps-src assumes that CWD is in the target package. Example:
$ cd srcpkgs/libX11 && xbps-src install
$ xbps-src install libX11
Both ways are equivalent.
Options:
-B Used in the install target, a binary package is built for any
required dependency as well as for <pkgname>. The local repository
pkg-index is created or updated after a successful package installation.
-C Do not remove build directory after successful installation.
-c Path to global configuration file:
if not specified ${XBPS_ETCDIR}/xbps-src.conf is used.
-D Only install <pkgname> to package's destdir (set to
<masterdir>/destdir/<pkgname>-<version> by default).
-h Usage output.
-K Do not remove automatic package dependencies while building
or installing a package with XBPS_PREFER_BINPKG_DEPS enabled.
-m Master directory, overwritting the value set in the configuration
file xbps-src.conf.
-p Local packages repository, overwritting default path at
<masterdir>/host/binpkgs or if XBPS_HOSTDIR is set <hostdir>/binpkgs.
-S Overrides and disables XBPS_PREFER_BINPKG_DEPS even if it was
set in the configuration file xbps-src.conf.
-s Source distribution files directory, overwritting default path at
<masterdir>/host/sources or if XBPS_HOSTDIR is set <hostdir>/sources.
_EOF
}
basename_cwd()
{
echo $(basename $(pwd))
}
check_path()
{
eval local orig="$1"
case "$orig" in
/) ;;
/*) orig="${orig%/}" ;;
*) orig="$(pwd)/${orig%/}" ;;
esac
path_fixed="$orig"
}
run_file()
{
local file="$1"
check_path "$file"
. $path_fixed
}
check_config_vars()
{
local val cffound f cfpaths cf="xbps-src.conf"
if [ -z "$XBPS_CONFIG_FILE" ]; then
cfpaths="@@XBPS_INSTALL_PREFIX@@/etc/${cf} ./etc/${cf}"
for f in $cfpaths; do
if [ -f ${f} ]; then
XBPS_CONFIG_FILE=${f}
cffound=yes
break
fi
done
if [ -z "$cffound" ]; then
echo "cannot find a config file"
exit 1
fi
fi
run_file ${XBPS_CONFIG_FILE}
export XBPS_CONFIG_FILE=$path_fixed
if [ ! -f "$XBPS_CONFIG_FILE" ]; then
echo "cannot find configuration file: $XBPS_CONFIG_FILE"
exit 1
fi
for f in XBPS_DISTRIBUTIONDIR XBPS_MASTERDIR; do
eval val="\$${f}"
if [ -z "$val" ]; then
echo "${f} not set in configuration file!"
exit 1
fi
done
if [ ! -w "$XBPS_MASTERDIR" ]; then
echo "ERROR: not enough perms for masterdir $XBPS_MASTERDIR."
exit 1
fi
}
#
# main()
#
while getopts "CBc:DhKm:p:Ss:V" opt; do
case $opt in
B) export BUILD_BINPKG=1;;
C) export KEEP_WRKSRC=1;;
c) XBPS_CONFIG_FILE="$OPTARG";;
D) export DESTDIR_ONLY_INSTALL=1;;
h) usage && exit 0;;
K) export KEEP_AUTODEPS=1;;
m)
_MASTERDIR_FLAG=1
_MASTERDIR="$OPTARG"
if [ ! -d ${_MASTERDIR} ]; then
mkdir -p ${_MASTERDIR}
fi
;;
p)
_PACKAGEDIR="$OPTARG"
if [ ! -d ${_PACKAGEDIR} ]; then
mkdir -p ${_PACKAGEDIR}/${XBPS_MACHINE}
mkdir -p ${_PACKAGEDIR}/noarch
fi
;;
S) UNSET_PREFER_BINPKG_DEPS=1;;
s) export XBPS_SRCDISTDIR="$OPTARG";;
V) echo $XBPS_SRC_VERSION && exit 0;;
--) shift; break;;
esac
done
shift $(($OPTIND - 1))
[ $# -eq 0 -o $# -gt 3 ] && usage && exit 1
target="$1"
_pkgname="$2"
_optarget="$3"
if [ -z "$target" ]; then
echo "=> ERROR: missing target."
usage && exit 1
fi
#
# Check configuration vars before anyting else, and set defaults vars.
#
check_config_vars
if [ -n "${_MASTERDIR}" ]; then
export XBPS_MASTERDIR=${_MASTERDIR}
fi
. ${XBPS_SHAREDIR}/shutils/init_funcs.sh
set_defvars
for f in $XBPS_SHUTILSDIR/*.sh; do
[ -r "$f" ] && . $f
done
# Disable XBPS_PREFER_BINPKG_DEPS if requested.
[ -n "$UNSET_PREFER_BINPKG_DEPS" ] && unset XBPS_PREFER_BINPKG_DEPS
#
# Check for required utilities in host system.
#
check_reqhost_utils
#
# Fix up some vars when XBPS_USE_CAPABILITIES is set.
#
if [ -z "$IN_CHROOT" -a -n "$XBPS_USE_CAPABILITIES" ]; then
CHROOT_CMD="@@XBPS_INSTALL_LIBEXECDIR@@/capchroot"
unset SUDO_CMD
fi
if [ "$(id -u)" -eq 0 ]; then
# disable sudo and fakeroot if uid==0
CHROOT_CMD="chroot"
unset SUDO_CMD
if [ -n "$IN_CHROOT" ]; then
unset FAKEROOT_CMD
unset FAKEROOT_CMD_ARGS
fi
fi
#
# Sanitize PATH.
#
if [ -z "$IN_CHROOT" ]; then
# In non chroot case always prefer host tools.
MYPATH="$PATH:$XBPS_MASTERDIR/bin:$XBPS_MASTERDIR/usr/bin"
MYPATH="$MYPATH:$XBPS_MASTERDIR/usr/local/bin"
MYPATH="$MYPATH:$XBPS_MASTERDIR/usr/local/sbin"
export PATH="$MYPATH"
else
MYPATH="/tools/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin"
MYPATH="$MYPATH:/usr/local/bin:/usr/lib/perl5/core_perl/bin"
export PATH="$MYPATH"
if [ -n "$XBPS_CCACHE" ]; then
CCACHEPATH="/usr/lib/ccache/bin"
if [ -n "$XBPS_HOSTDIR" ]; then
[ ! -d "$XBPS_HOSTDIR/ccache" ] && \
mkdir -p $XBPS_HOSTDIR/ccache
export CCACHE_DIR="$XBPS_HOSTDIR/ccache"
else
[ ! -d "$XBPS_MASTERDIR/host/ccache" ] && \
mkdir -p $XBPS_MASTERDIR/host/ccache
export CCACHE_DIR="$XBPS_MASTERDIR/host/ccache"
fi
export PATH="$CCACHEPATH:$PATH"
fi
fi
#
# If masterdir is ready (base-chroot installed and chroot set up) and
# XBPS_PREFER_BINPKG_DEPS enabled, force ignoring rules to handle
# bootstrap packages.
#
if [ -n "$DESTDIR_ONLY_INSTALL" -a -n "$XBPS_PREFER_BINPKG_DEPS" \
-a -f "$XBPS_MASTERDIR/.xbps_perms_done" ]; then
export BOOTSTRAP_PKG_REBUILD=1
fi
#
# Main switch.
#
case "$target" in
bootstrap)
[ ! -d $XBPS_SRCPKGDIR/base-chroot ] && \
msg_error "Cannot find $XBPS_SRCPKGDIR/base-chroot directory!\n"
cd $XBPS_SRCPKGDIR/base-chroot && _ORIGINPKG="$(basename_cwd)"
setup_tmpl ${_ORIGINPKG} && install_pkg $pkgname
;;
bootstrap-update)
if [ -z "$IN_CHROOT" ]; then
xbps_chroot_handler ${target} dummy
else
${FAKEROOT_CMD} ${FAKEROOT_CMD_ARGS} ${XBPS_BIN_CMD} -y autoupdate
fi
;;
build-pkg)
if [ -n "${_PACKAGEDIR}" ]; then
export XBPS_PACKAGESDIR=${_PACKAGEDIR}
fi
if [ "$2" = "all" ]; then
for f in $($XBPS_BIN_CMD list|awk '{print $1}'); do
pkg=$(${XBPS_PKGDB_CMD} getpkgname $f)
setup_tmpl $pkg
if [ "${pkg}" = "${sourcepkg}" ]; then
xbps_make_binpkg
fi
done
else
if [ -z "${_pkgname}" ]; then
[ ! -r ./template ] && msg_error "missing build template in $(pwd).\n"
_pkgname=$(basename_cwd)
fi
setup_tmpl ${_pkgname}
xbps_make_binpkg
fi
;;
checkvers)
check_installed_packages
;;
chroot)
xbps_chroot_handler chroot dummy
;;
clean)
if [ -z "${_pkgname}" ]; then
[ ! -r ./template ] && msg_error "missing build template in $(pwd).\n"
_pkgname=$(basename_cwd)
fi
setup_tmpl ${_pkgname}
remove_tmpl_wrksrc $wrksrc
;;
clean-autodeps)
if [ -z "$IN_CHROOT" ]; then
xbps_chroot_handler clean-autodeps dummy
else
pkgver=xbps-src
autoremove_pkg_dependencies
fi
;;
extract|fetch)
if [ -z "${_pkgname}" ]; then
[ ! -r ./template ] && msg_error "missing build template in $(pwd).\n"
_pkgname=$(basename_cwd)
fi
setup_tmpl ${_pkgname}
if [ "$target" = "info" ]; then
info_tmpl
exit $?
fi
fetch_distfiles $update_checksum
[ "$target" = "extract" ] && extract_distfiles
;;
build|configure|install)
if [ -z "${_pkgname}" ]; then
[ ! -r ./template ] && msg_error "missing build template in $(pwd).\n"
_pkgname=$(basename_cwd)
fi
setup_tmpl ${_pkgname}
_ORIGINPKG="${_pkgname}"
if [ -z "$IN_CHROOT" -a -z "$bootstrap" ]; then
xbps_chroot_handler $target ${_ORIGINPKG} || exit $?
else
INSTALL_TARGET=$target install_pkg $pkgname || exit $?
fi
;;
list)
$XBPS_BIN_CMD list
;;
make-repoidx)
if [ -n "${_PACKAGEDIR}" ]; then
export XBPS_PACKAGESDIR=${_PACKAGEDIR}
fi
make_repoidx
;;
remove)
if [ -z "${_pkgname}" ]; then
[ ! -r ./template ] && msg_error "missing build template in $(pwd).\n"
_pkgname=$(basename_cwd)
fi
setup_tmpl ${_pkgname}
if [ -z "$IN_CHROOT" -a -z "$bootstrap" ]; then
xbps_chroot_handler $target ${_pkgname}
else
remove_pkg
fi
;;
show)
if [ -z "${_pkgname}" ]; then
[ ! -r ./template ] && msg_error "missing build template in $(pwd).\n"
_pkgname=$(basename_cwd)
fi
setup_tmpl ${_pkgname}
show_tmpl
;;
show-deps)
setup_subpkg_tmpl ${_pkgname}
if [ -z "${_optarget}" ]; then
msg_error "missing dependency type: build or run.\n"
fi
show_tmpl_deps ${_optarget}
;;
show-files)
list_pkg_files ${_pkgname}
;;
show-revdeps)
show_pkg_revdeps ${_pkgname}
;;
stow)
stow_flag=yes
if [ -z "${_pkgname}" ]; then
[ ! -r ./template ] && msg_error "missing build template in $(pwd).\n"
_pkgname=$(basename_cwd)
fi
setup_tmpl ${_pkgname}
stow_pkg_handler stow
;;
unstow)
if [ -z "${_pkgname}" ]; then
[ ! -r ./template ] && msg_error "missing build template in $(pwd).\n"
_pkgname=$(basename_cwd)
else
pkgname=${_pkgname}
fi
stow_pkg_handler unstow
;;
*)
msg_red "xbps-src: invalid target $target.\n"
usage && exit 1
esac
# Agur
exit $?