File prepare_vendor.sh of Package signal-desktop
#!/bin/bash
# shellcheck disable=2181
SIGNAL_URL=$(rpmspec -P ./*.spec | grep Source0 | sed -e 's/Source0:[ ]*//g')
SIGNAL_TARBALL=$(basename "$SIGNAL_URL")
SIGNAL_PKGVERSION=$(rpmspec -P ./*.spec | grep ^Version | sed -e 's/Version:[ ]*//g')
SIGNAL_PKGNAME="Signal-Desktop"
SIGNAL_PKGDIR="$(pwd)"
SIGNAL_TMPDIR=$(mktemp --tmpdir -d signal-desktop-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"
cleanup_tmpdir()
{
popd 2> /dev/null || exit 1
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
export ELECTRON_SKIP_BINARY_DOWNLOAD=1
export RUSTC_BOOTSTRAP=1 # needed to build signal-client
export SIGNAL_ENV=production
mkdir -p vendor/node/bin
ln -s /usr/bin/node${NODE_VERSION} vendor/node/bin/node
ln -s /usr/bin/npm${NODE_VERSION} vendor/node/bin/npm
ls -l vendor/node/bin/
echo ">>>>>> Patch package.json"
cp -p package.json package.json.orig
echo ">>>>>> Fix node version requirement (package.json)"
sed -i 's#"node": "#&>=#' package.json
echo ">>>>>> Use signal-client source (package.json)"
SIGNAL_CLIENT_VERSION=$(jq -cj '.dependencies."@signalapp/libsignal-client"' package.json)
sed -i 's|"@signalapp/libsignal-client": "|"@signalapp/libsignal-client": "https://github.com/signalapp/libsignal-client#v|' package.json
sed 's|"resolutions": {|"resolutions": {\n "@signalapp/libsignal-client": "https://github.com/signalapp/libsignal-client#v'${SIGNAL_CLIENT_VERSION}'",|' -i package.json
echo ">>>>>> Remove HEIF/HEIC support (package.json)"
sed -i '/"heic-convert": .*/d' package.json
sed -i '/".*heicConverter.bundle.js".*/d' package.json
diff -u package.json.orig package.json
echo -n ">>>>>> Export PATH="
export PATH="$SIGNAL_PATH/vendor/node/bin:$PATH"
echo "$PATH"
echo ">>>>>> Install npm modules"
yarn install --pure-lockfile --ignore-engines --ignore-scripts
ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: yarn install failed"
cleanup_and_exit 1
fi
echo ">>>>>> Apply patches from upstream"
cat patches/* | patch -p1 --verbose
ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: yarn install failed"
cleanup_and_exit 1
fi
echo -n ">>>>>> Export PATH="
export PATH="$PATH:$SIGNAL_PATH/node_modules/.bin"
echo "$PATH"
######################### HACK: the git-lfs server is down, currently, i had to uninstall git-lfs and copy sqlcipher.tar.gz from an older tarball
#cp -pv /media/sf_tcs/sqlcipher.tar.gz node_modules/better-sqlite3/deps/sqlcipher.tar.gz
#Protobufjs tries to download some seemingly random packages during runtime.
#It has listed them in devDeps but not deps, so yarn install does not pick them
echo ">>>>>> Download deps for protobufjs"
pushd node_modules/protobufjs || cleanup_and_exit 1
npm install semver jsdoc tmp escodegen --no-save --ignore-scripts
if [ $? -ne 0 ]; then
echo "ERROR: npm install failed for protobufjs"
cleanup_and_exit 1
fi
popd
echo ">>>>>> Download rust vendor for signal-client"
pushd node_modules/@signalapp/libsignal-client || cleanup_and_exit 1
cargo vendor
mkdir .cargo
cat > .cargo/config << EOF
[source.crates-io]
replace-with = "vendored-sources"
[source."https://github.com/dignifiedquire/num-bigint"]
git = "https://github.com/dignifiedquire/num-bigint"
rev = "56576b592fea6341b7e1711a1629e4cc1bfc419c"
replace-with = "vendored-sources"
[source."https://github.com/signalapp/curve25519-dalek"]
git = "https://github.com/signalapp/curve25519-dalek"
branch = "lizard2"
replace-with = "vendored-sources"
[source."https://github.com/signalapp/boring"]
git = "https://github.com/signalapp/boring"
branch = "libsignal"
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "vendor"
EOF
echo ">>>>>> Download node vendor for signal-client"
pushd node || cleanup_and_exit 1
yarn install --pure-lockfile --ignore-engines --ignore-scripts
if [ $? -ne 0 ]; then
echo "ERROR: yarn install failed for singal-client"
cleanup_and_exit 1
fi
# shellcheck disable=2035
mv * ../
mv .* ../
popd || cleanup_and_exit 1 # XXX FIXME
popd || cleanup_and_exit 1
echo ">>>>>> Clean up release files"
rm -rf release
rm -rf dist
echo ">>>>>> Remove sharp vendor"
rm -rf node_modules/sharp/vendor
echo ">>>>>> Remove googletest vendor"
rm -rf node_modules/@signalapp/libsignal-client/vendor/boring-sys/deps/boringssl/src/third_party/googletest
echo ">>>>>> Cleanup object dirs"
find node_modules/ -type d -name "*.o.d" -print0 | xargs -0 rm -rvf
find node_modules/ -type d -name "__pycache__" -print0 | xargs -0 rm -rvf
echo ">>>>>> Cleanup object files"
find node_modules/ -name "*.node" -print -delete
find node_modules/ -name "*.jar" -print -delete
find node_modules/ -name "*.dll" -print -delete
find node_modules/ -name "*.dylib" -print -delete
find node_modules/ -name "*.so" -print -delete
find node_modules/ -name "*.o" -print -delete
find node_modules/ -name "*.a" -print -delete
find node_modules/ -name "*.wasm" -print -delete
find node_modules/ -name "*.snyk-*.flag" -print -delete
find node_modules/ -name "builderror.log" -print -delete
find node_modules/ -name ".deps" -type d -print0 | xargs -0 rm -rvf
sed -i "/\.deps/d" node_modules/.yarn-integrity
echo ">>>>>> Cleanup build info"
find node_modules/ -name "package.json" -exec sed -i "s#$SIGNAL_PATH#/tmp#g" {} \;
echo '>>>>>> Remove vendored binaries'
#We use sponge to avoid a race condition between find and rm
find . -type f|grep -Fv wycheproof | sponge |\
xargs -P"$(nproc)" -- sh -c 'file "$@" | grep -v '\'': .*script'\'' | grep '\'': .*executable'\'' | tee /dev/stderr | sed '\''s/: .*//'\'' | xargs rm -fv'
echo ">>>>>> Package vendor files"
#I would like to use zst, as it decompresses MUCH faster, but unfortunately it is not supported by OBS diff view yet
rm -f "${SIGNAL_PKGDIR}/vendor.tar.xz"
XZ_OPT="-T$(nproc) -e9 -vv" tar -vvcJf "${SIGNAL_PKGDIR}/vendor.tar.xz" node_modules vendor
if [ $? -ne 0 ]; then
cleanup_and_exit 1
fi
echo "vendor $(du -sh "${SIGNAL_PKGDIR}/vendor.tar.xz")"
popd || cleanup_and_exit 1
cleanup_and_exit 0