File prepare_vendor.sh of Package nodejs-signal-ringrtc
#!/bin/bash -e
SIGNAL_URL=$(rpmspec -P *.spec | grep Source1 | sed -e 's/Source1:[ ]*//g')
SIGNAL_TARBALL=$(basename $SIGNAL_URL)
SIGNAL_PKGVERSION=$(rpmspec -P *.spec | grep Version | sed -e 's/Version:[ ]*//g')
SIGNAL_PKGNAME="ringrtc"
SIGNAL_PKGDIR="$(pwd)"
SIGNAL_TMPDIR="$(mktemp --tmpdir -d signal-ringrtc-XXXXXXXX)"
SIGNAL_PATH="${SIGNAL_TMPDIR}/${SIGNAL_PKGNAME}-${SIGNAL_PKGVERSION}"
echo "URL: ${SIGNAL_URL}"
echo "TARBALL: ${SIGNAL_TARBALL}"
echo "NAME: ${SIGNAL_PKGNAME}"
echo "VERSION: ${SIGNAL_PKGVERSION}"
echo "PATH: ${SIGNAL_PATH}"
export save_PATH="${PATH}"
cleanup_tmpdir() {
popd 2>/dev/null || true
rm -rf "${SIGNAL_TMPDIR}"
}
trap cleanup_tmpdir SIGINT
cleanup_and_exit() {
cleanup_tmpdir
if test "$1" = 0 -o -z "$1" ; then
exit 0
else
exit ${1}
fi
}
if [ ! -w "${SIGNAL_TARBALL}" ]; then
wget "${SIGNAL_URL}"
fi
tar -xf "${SIGNAL_TARBALL}" -C "${SIGNAL_TMPDIR}"
pushd "${SIGNAL_PATH}" || cleanup_and_exit 1
#################
# RUST
#################
pushd src/rust || cleanup_and_exit 1
export CARGO_NET_GIT_FETCH_WITH_CLI=true #otherwise cargo fails with warning: spurious network error (3 tries remaining): error reading from the zlib stream; class=Zlib (5)
cargo vendor-filterer --platform='*-unknown-linux-gnu' --platform='*-unknown-linux-gnueabihf' --all-features > ${SIGNAL_PKGDIR}/cargo_config
if [ $? -ne 0 ]; then
echo "ERROR: Failed to get cargo vendor packages"
cleanup_and_exit 1
fi
popd || cleanup_and_exit 1# src/rust
echo '>>>>>> Remove bzip2 vendor'
rm -rvf src/rust/vendor/bzip2-sys/bzip2-*
echo '>>>>>> Remove zstd vendor'
rm -rvf src/rust/vendor/zstd-sys/zstd
rm -vf src/rust/vendor/zstd-sys/*.h
echo '>>>>>> Download cubeb-pulse-rs vendor'
pushd src/rust/vendor/cubeb-sys/libcubeb/src/cubeb-pulse-rs
mkdir -pv .cargo
find . -name Cargo.toml.in -print -exec sh -x -c 'mv -v "$0" "${0%.in}"' {} \;
cargo vendor-filterer --platform='*-unknown-linux-gnu' --platform='*-unknown-linux-gnueabihf' --all-features > .cargo/config
popd
echo '>>>>>> Remove the recursive abomination to endure that we dont accidentally build it'
rm -rvf src/rust/vendor/cubeb-sys/libcubeb/src/cubeb-pulse-rs/vendor/cubeb-sys/libcubeb
echo '>>>>>> Remove speex vendor'
rm -rvf src/rust/vendor/cubeb-sys/libcubeb/subprojects
echo '>>>>>> Remove googletest vendor'
rm -rvf src/rust/vendor/cubeb-sys/libcubeb/googletest
echo '>>>>>> Remove git directories'
find . -name .git -print0 | xargs -0 rm -rf
echo '>>>>>> Remove vendored binaries'
find . -type f -name "*.wasm" -print -delete
find . -name "*.jar" -print -delete
find . -name "*.exe" -print -delete
find . -name "*.node" -print -delete
find . -name "*.dll" -print -delete
find . -name "*.dylib" -print -delete
find . -name "*.so" -print -delete
find . -name "*.o" -print -delete
find . -name "*.a" -print -delete
find -type f | sponge | xargs -P$(nproc) -- sh -c 'file -S "$@" | grep -v '\'' .*script'\'' | grep '\'' .*executable'\'' | tee /dev/stderr | sed '\''s/: .*//'\'' | xargs rm -fv'
#echo '>>>>>> Hardlink duplicate files to reduce extraction time'
#Disabled this — it fails to link sometimes causing tarball nondeterminism
#/usr/lib/rpm/fdupes_wrapper node_modules
# Remove empty directories
echo ">>>>>> Remove empty directories"
find . -type d -empty -print -delete
echo ">>>>>> Package vendor files"
rm -f "$SIGNAL_PKGDIR/vendor.tar.zst"
ZSTD_CLEVEL=19 ZSTD_NBTHREADS=$(nproc) tar --zstd --sort=name -vvScf "${SIGNAL_PKGDIR}/vendor.tar.zst" src/rust/vendor
if [ $? -ne 0 ]; then
cleanup_and_exit 1
fi
popd || cleanup_and_exit 1
cleanup_and_exit 0