Blame prepare_vendor.sh

1687c9
#!/bin/bash -eux
91b24b
91b24b
ASAR_PKGDIR="$(pwd)"
91b24b
ASAR_PKGVERSION=$(<./*.spec grep ^Version | sed -e 's/Version:[ ]*//g')
91b24b
ASAR_URL="https://github.com/electron/asar/archive/refs/tags/v${ASAR_PKGVERSION}.tar.gz"
91b24b
ASAR_TARBALL=v${ASAR_PKGVERSION}.tar.gz
91b24b
ASAR_TMPDIR=$(mktemp --tmpdir -d asar-XXXXXXXX)
91b24b
ASAR_PATH="$ASAR_TMPDIR/asar-$ASAR_PKGVERSION"
91b24b
91b24b
91b24b
91b24b
echo "VERSION: $ASAR_PKGVERSION"
91b24b
echo "PATH:    $ASAR_PATH"
91b24b
91b24b
cleanup_tmpdir()
91b24b
{
91b24b
    popd 2> /dev/null || exit 1
91b24b
    rm -rf "$ASAR_TMPDIR"
91b24b
}
91b24b
trap cleanup_tmpdir SIGINT
91b24b
91b24b
cleanup_and_exit()
91b24b
{
91b24b
    cleanup_tmpdir
91b24b
    if test "$1" = 0 -o -z "$1"; then
91b24b
        exit 0
91b24b
    else
91b24b
        exit "$1"
91b24b
    fi
91b24b
}
91b24b
91b24b
if [ ! -w "$ASAR_TARBALL" ]; then
91b24b
    wget "$ASAR_URL"
91b24b
fi
91b24b
91b24b
tar -xf "$ASAR_TARBALL" -C "$ASAR_TMPDIR"
91b24b
91b24b
pushd "$ASAR_PATH" || cleanup_and_exit 1
91b24b
91b24b
91b24b
91b24b
echo ">>>>>> Install npm modules"
1687c9
yarn install --frozen-lockfile --ignore-engines --ignore-platform  --ignore-scripts --production --link-duplicates
91b24b
ret=$?
91b24b
if [ $ret -ne 0 ]; then
91b24b
    echo "ERROR: yarn install failed"
91b24b
    cleanup_and_exit 1
91b24b
fi
91b24b
91b24b
echo ">>>>>> Cleanup object files"
91b24b
find node_modules/ -name "*.node" -print -delete
389d59
find node_modules/ -name "*.wasm" -print -delete
91b24b
find node_modules/ -name "*.jar" -print -delete
91b24b
find node_modules/ -name "*.dll" -print -delete
c3e467
find node_modules/ -name "*.exe" -print -delete
91b24b
find node_modules/ -name "*.dylib" -print -delete
91b24b
find node_modules/ -name "*.so" -print -delete
91b24b
find node_modules/ -name "*.o" -print -delete
91b24b
find node_modules/ -name "*.a" -print -delete
91b24b
91b24b
91b24b
91b24b
echo '>>>>>> Remove vendored binaries'
91b24b
#We use sponge to avoid a race condition between find and rm
91b24b
find . -type f| sponge |\
91b24b
    xargs -P"$(nproc)" -- sh -c 'file "$@" | grep -v '\'': .*script'\'' | grep '\'': .*executable'\'' | tee /dev/stderr | sed '\''s/: .*//'\'' | xargs rm -fv'
91b24b
91b24b
91b24b
91b24b
echo ">>>>>> Package vendor files"
1687c9
rm -f "${ASAR_PKGDIR}/vendor.tar.zst"
c3e467
ZSTD_CLEVEL=19 ZSTD_NBTHREADS=$(nproc) tar --zstd --sort=name -vvScf "${ASAR_PKGDIR}/vendor.tar.zst" node_modules
91b24b
if [ $? -ne 0 ]; then
91b24b
    cleanup_and_exit 1
91b24b
fi
c3e467
echo "vendor $(du -sh "${ASAR_PKGDIR}/vendor.tar.zst")"