2014-03-05 11:02:37 +01:00
|
|
|
# This hook extracts $distfiles into $XBPS_BUILDDIR if $distfiles and $checksum
|
|
|
|
# variables are set.
|
|
|
|
|
|
|
|
hook() {
|
|
|
|
local srcdir="$XBPS_SRCDISTDIR/$pkgname-$version"
|
2022-11-08 22:36:31 -05:00
|
|
|
local f j curfile found extractdir innerdir innerfile num_dirs
|
2020-01-05 08:20:26 +01:00
|
|
|
local TAR_CMD
|
2014-03-05 11:02:37 +01:00
|
|
|
|
|
|
|
if [ -z "$distfiles" -a -z "$checksum" ]; then
|
2020-09-02 19:04:41 +02:00
|
|
|
mkdir -p "$wrksrc"
|
2014-03-12 10:32:50 +01:00
|
|
|
return 0
|
2014-03-05 11:02:37 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check that distfiles are there before anything else.
|
|
|
|
for f in ${distfiles}; do
|
2019-04-13 13:43:07 +02:00
|
|
|
curfile="${f#*>}"
|
|
|
|
curfile="${curfile##*/}"
|
2014-03-05 11:02:37 +01:00
|
|
|
if [ ! -f $srcdir/$curfile ]; then
|
|
|
|
msg_error "$pkgver: cannot find ${curfile}, use 'xbps-src fetch' first.\n"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-01-05 08:24:52 +01:00
|
|
|
# Disable trap on ERR; the code is smart enough to report errors and abort.
|
|
|
|
trap - ERR
|
|
|
|
|
2020-01-05 08:20:26 +01:00
|
|
|
TAR_CMD="$(command -v bsdtar)"
|
|
|
|
[ -z "$TAR_CMD" ] && TAR_CMD="$(command -v tar)"
|
|
|
|
[ -z "$TAR_CMD" ] && msg_error "xbps-src: no suitable tar cmd (bsdtar, tar)\n"
|
|
|
|
|
hooks: do-extract: extract to temp dir then rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
2021-09-18 21:35:34 +07:00
|
|
|
extractdir=$(mktemp -d "$XBPS_BUILDDIR/.extractdir-XXXXXXX") ||
|
|
|
|
msg_error "Cannot create temporary dir for do-extract\n"
|
|
|
|
|
2014-03-05 11:02:37 +01:00
|
|
|
msg_normal "$pkgver: extracting distfile(s), please wait...\n"
|
|
|
|
|
|
|
|
for f in ${distfiles}; do
|
2019-04-13 13:43:07 +02:00
|
|
|
curfile="${f#*>}"
|
|
|
|
curfile="${curfile##*/}"
|
2014-03-05 11:02:37 +01:00
|
|
|
for j in ${skip_extraction}; do
|
|
|
|
if [ "$curfile" = "$j" ]; then
|
|
|
|
found=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ -n "$found" ]; then
|
|
|
|
unset found
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2014-03-12 16:43:37 +01:00
|
|
|
case $curfile in
|
|
|
|
*.tar.lzma) cursufx="txz";;
|
2014-03-14 11:04:51 +01:00
|
|
|
*.tar.lz) cursufx="tlz";;
|
|
|
|
*.tlz) cursufx="tlz";;
|
2014-03-12 16:43:37 +01:00
|
|
|
*.tar.xz) cursufx="txz";;
|
|
|
|
*.txz) cursufx="txz";;
|
|
|
|
*.tar.bz2) cursufx="tbz";;
|
|
|
|
*.tbz) cursufx="tbz";;
|
|
|
|
*.tar.gz) cursufx="tgz";;
|
|
|
|
*.tgz) cursufx="tgz";;
|
2023-03-03 14:25:01 -05:00
|
|
|
*.tar.zst) cursufx="tzst";;
|
|
|
|
*.tzst) cursufx="tzst";;
|
2014-03-12 16:43:37 +01:00
|
|
|
*.gz) cursufx="gz";;
|
2020-02-11 21:29:57 +00:00
|
|
|
*.xz) cursufx="xz";;
|
2014-03-12 16:43:37 +01:00
|
|
|
*.bz2) cursufx="bz2";;
|
2023-03-03 14:25:01 -05:00
|
|
|
*.zst) cursufx="zst";;
|
2014-03-12 16:43:37 +01:00
|
|
|
*.tar) cursufx="tar";;
|
|
|
|
*.zip) cursufx="zip";;
|
2014-05-08 18:44:54 +02:00
|
|
|
*.rpm) cursufx="rpm";;
|
2022-11-08 22:36:31 -05:00
|
|
|
*.deb) cursufx="deb";;
|
2015-10-23 19:43:43 +02:00
|
|
|
*.patch) cursufx="txt";;
|
|
|
|
*.diff) cursufx="txt";;
|
|
|
|
*.txt) cursufx="txt";;
|
2020-02-11 22:52:33 +01:00
|
|
|
*.sh) cursufx="txt";;
|
2016-01-11 11:02:44 +01:00
|
|
|
*.7z) cursufx="7z";;
|
2018-10-26 16:39:18 -03:00
|
|
|
*.gem) cursufx="gem";;
|
2018-10-31 22:11:01 +01:00
|
|
|
*.crate) cursufx="crate";;
|
2014-03-12 16:43:37 +01:00
|
|
|
*) msg_error "$pkgver: unknown distfile suffix for $curfile.\n";;
|
|
|
|
esac
|
2014-03-05 11:02:37 +01:00
|
|
|
|
|
|
|
case ${cursufx} in
|
2023-03-03 14:25:01 -05:00
|
|
|
tar|txz|tbz|tlz|tgz|tzst|crate)
|
2020-09-02 19:04:41 +02:00
|
|
|
$TAR_CMD -x --no-same-permissions --no-same-owner -f $srcdir/$curfile -C "$extractdir"
|
2014-03-05 11:02:37 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
|
|
|
|
fi
|
|
|
|
;;
|
2023-03-03 14:25:01 -05:00
|
|
|
gz|bz2|xz|zst)
|
2020-09-02 19:04:41 +02:00
|
|
|
cp -f $srcdir/$curfile "$extractdir"
|
|
|
|
cd "$extractdir"
|
2020-02-11 21:29:57 +00:00
|
|
|
case ${cursufx} in
|
|
|
|
gz)
|
2022-11-08 22:36:31 -05:00
|
|
|
gunzip -f $curfile
|
2020-02-11 21:29:57 +00:00
|
|
|
;;
|
|
|
|
bz2)
|
|
|
|
bunzip2 -f $curfile
|
|
|
|
;;
|
2023-03-03 14:25:01 -05:00
|
|
|
xz)
|
2020-02-11 21:29:57 +00:00
|
|
|
unxz -f $curfile
|
|
|
|
;;
|
2023-03-03 14:25:01 -05:00
|
|
|
zst)
|
|
|
|
unzstd $curfile
|
|
|
|
;;
|
2020-02-11 21:29:57 +00:00
|
|
|
esac
|
2014-03-05 11:02:37 +01:00
|
|
|
;;
|
|
|
|
zip)
|
2014-05-08 18:44:54 +02:00
|
|
|
if command -v unzip &>/dev/null; then
|
2020-09-02 19:04:41 +02:00
|
|
|
unzip -o -q $srcdir/$curfile -d "$extractdir"
|
2014-03-05 11:02:37 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
|
|
|
|
fi
|
2020-01-19 21:06:55 +02:00
|
|
|
elif command -v bsdtar &>/dev/null; then
|
2020-09-02 19:04:41 +02:00
|
|
|
bsdtar -xf $srcdir/$curfile -C "$extractdir"
|
2020-01-19 21:06:55 +02:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
|
|
|
|
fi
|
2014-03-05 11:02:37 +01:00
|
|
|
else
|
2020-01-19 21:06:55 +02:00
|
|
|
msg_error "$pkgver: cannot find unzip or bsdtar bin for extraction.\n"
|
2014-03-05 11:02:37 +01:00
|
|
|
fi
|
|
|
|
;;
|
2014-05-08 18:44:54 +02:00
|
|
|
rpm)
|
2022-11-09 19:36:30 +07:00
|
|
|
if ! command -v bsdtar &>/dev/null; then
|
|
|
|
msg_error "$pkgver: cannot find bsdtar for extraction.\n"
|
|
|
|
fi
|
|
|
|
bsdtar -x --no-same-permissions --no-same-owner -f $srcdir/$curfile -C "$extractdir"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
|
2014-05-08 18:44:54 +02:00
|
|
|
fi
|
|
|
|
;;
|
2022-11-08 22:36:31 -05:00
|
|
|
deb)
|
|
|
|
if command -v bsdtar &>/dev/null; then
|
|
|
|
bsdtar -x -O -f "$srcdir/$curfile" "data.tar.*" |
|
|
|
|
bsdtar -C "$extractdir" -x --no-same-permissions --no-same-owner
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
msg_error "$pkgver: cannot find bsdtar for extraction.\n"
|
|
|
|
fi
|
|
|
|
;;
|
2015-10-23 19:43:43 +02:00
|
|
|
txt)
|
hooks: do-extract: extract to temp dir then rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
2021-09-18 21:35:34 +07:00
|
|
|
cp -f $srcdir/$curfile "$extractdir"
|
2015-10-23 19:43:43 +02:00
|
|
|
;;
|
2016-01-11 11:02:44 +01:00
|
|
|
7z)
|
|
|
|
if command -v 7z &>/dev/null; then
|
2020-09-02 19:04:41 +02:00
|
|
|
7z x $srcdir/$curfile -o"$extractdir"
|
2016-01-11 11:02:44 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
|
|
|
|
fi
|
2020-01-19 21:06:55 +02:00
|
|
|
elif command -v bsdtar &>/dev/null; then
|
2020-09-02 19:04:41 +02:00
|
|
|
bsdtar -xf $srcdir/$curfile -C "$extractdir"
|
2020-01-19 21:06:55 +02:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
|
|
|
|
fi
|
2016-01-11 11:02:44 +01:00
|
|
|
else
|
2020-01-19 21:06:55 +02:00
|
|
|
msg_error "$pkgver: cannot find 7z or bsdtar bin for extraction.\n"
|
2016-01-11 11:02:44 +01:00
|
|
|
fi
|
|
|
|
;;
|
2018-10-26 16:39:18 -03:00
|
|
|
gem)
|
2021-09-18 21:02:51 +07:00
|
|
|
innerdir="$extractdir/${wrksrc##*/}"
|
|
|
|
mkdir -p "$innerdir"
|
|
|
|
$TAR_CMD -xOf $srcdir/$curfile data.tar.gz |
|
|
|
|
$TAR_CMD -xz -C "$innerdir" -f -
|
2018-10-26 16:39:18 -03:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
|
|
|
|
fi
|
|
|
|
;;
|
2014-03-05 11:02:37 +01:00
|
|
|
*)
|
|
|
|
msg_error "$pkgver: cannot guess $curfile extract suffix. ($cursufx)\n"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
hooks: do-extract: extract to temp dir then rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
2021-09-18 21:35:34 +07:00
|
|
|
|
2023-01-05 09:13:55 +07:00
|
|
|
cd "$extractdir"
|
hooks: do-extract: extract to temp dir then rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
2021-09-18 21:35:34 +07:00
|
|
|
# find "$extractdir" -mindepth 1 -maxdepth 1 -printf '1\n' | wc -l
|
|
|
|
# However, it requires GNU's find
|
|
|
|
num_dirs=0
|
2023-01-05 09:13:55 +07:00
|
|
|
for f in * .*; do
|
hooks: do-extract: extract to temp dir then rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
2021-09-18 21:35:34 +07:00
|
|
|
if [ -e "$f" ] || [ -L "$f" ]; then
|
|
|
|
case "$f" in
|
2023-01-05 09:13:55 +07:00
|
|
|
. | ..) ;;
|
hooks: do-extract: extract to temp dir then rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
2021-09-18 21:35:34 +07:00
|
|
|
*)
|
|
|
|
innerdir="$f"
|
|
|
|
num_dirs=$(( num_dirs + 1 ))
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
done
|
2022-11-09 18:54:00 +07:00
|
|
|
# Special case for num_dirs = 2, and it contains metadata
|
|
|
|
if [ "$num_dirs" != 2 ] || [ "$create_wrksrc" ]; then
|
|
|
|
:
|
|
|
|
elif grep -q 'xmlns="http://pear[.]php[.]net/dtd/package' package.xml 2>/dev/null
|
|
|
|
then
|
|
|
|
# PHP modules' metadata
|
|
|
|
rm -f package.xml
|
|
|
|
for f in */; do innerdir="$f"; done
|
|
|
|
num_dirs=1
|
|
|
|
else
|
|
|
|
for f in *; do
|
|
|
|
# AppleDouble encoded Macintosh file
|
|
|
|
if [ -e "$f" ] && [ -e "._$f" ]; then
|
|
|
|
rm -f "._$f"
|
|
|
|
num_dirs=1
|
|
|
|
innerdir="$f"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
hooks: do-extract: extract to temp dir then rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
2021-09-18 21:35:34 +07:00
|
|
|
rm -rf "$wrksrc"
|
2023-01-05 09:13:55 +07:00
|
|
|
innerdir="$extractdir/$innerdir"
|
|
|
|
cd "$XBPS_BUILDDIR"
|
hooks: do-extract: extract to temp dir then rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
2021-09-18 21:35:34 +07:00
|
|
|
if [ "$num_dirs" = 1 ] && [ -d "$innerdir" ] && [ -z "$create_wrksrc" ]; then
|
|
|
|
# rename the subdirectory (top-level of distfiles) to $wrksrc
|
|
|
|
mv "$innerdir" "$wrksrc" &&
|
|
|
|
rmdir "$extractdir"
|
|
|
|
else
|
2023-02-27 11:41:57 +07:00
|
|
|
mv "$extractdir" "$wrksrc"
|
hooks: do-extract: extract to temp dir then rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
2021-09-18 21:35:34 +07:00
|
|
|
fi ||
|
|
|
|
msg_error "$pkgver: failed to move sources to $wrksrc\n"
|
2014-03-05 11:02:37 +01:00
|
|
|
}
|