#!/bin/bash cleanup() { test -n "$dir" && rm -rf "$dir" } error() { echo "An error occurred. Exiting." >&2 } trap error ERR SIGINT trap cleanup EXIT set -e version=$(rpmspec -q --queryformat="%{VERSION}" velociraptor.spec) dir="$(realpath "$(mktemp -d vendoring.XXXXXX)")" rpmspec -P velociraptor.spec --define "_sourcedir $PWD" | \ awk ' BEGIN { go=0; }; /^%build/ { go=0; }; { if (go) print }; /^%setup/ { go=1 }' > $dir/setup.sh echo "Expanding archive..." cpio -D "$dir" -id < velociraptor-${version}.obscpio echo "Running %prep" cd "$dir/velociraptor-${version}" sh ../setup.sh echo "Re-vendoring Go code..." rm -rf vendor go mod vendor tar Jcf ../vendor-golang-${version}.tar.xz vendor echo "Re-vendoring nodejs code..." cd gui/velociraptor rm -rf node_modules npm install cd ../.. tar Jcf ../vendor-nodejs-${version}.tar.xz gui/velociraptor/node_modules cd .. mv vendor-golang-${version}.tar.xz vendor-nodejs-${version}.tar.xz .. echo "Done"