SHA256
1
0
forked from pool/velociraptor
velociraptor/update-vendoring.sh

60 lines
1.4 KiB
Bash
Raw Normal View History

#!/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}\n" velociraptor.spec|head -1)
dir="$(realpath "$(mktemp -d vendoring.XXXXXX)")"
topdir="$(realpath "$(dirname "$0")")"
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 ${dir}/setup.sh
echo "Re-vendoring Go code..."
rm -rf vendor
go mod vendor
tar Jcf ${dir}/vendor-golang-${version}.tar.xz vendor
cd "${dir}/velociraptor-${version}/contrib/kafka-humio-gateway"
rm -rf vendor
go mod vendor
cd "${dir}/velociraptor-${version}"
tar Jcf "${dir}/vendor-golang-kafka-humio-gateway-${version}.tar.xz" "contrib/kafka-humio-gateway/vendor"
echo "Re-vendoring nodejs code..."
cd "${dir}/velociraptor-${version}/gui/velociraptor"
rm -rf node_modules
npm install
cd ../..
tar Jcf ${dir}/vendor-nodejs-${version}.tar.xz gui/velociraptor/node_modules
cd "${dir}"
mv vendor-golang-*${version}.tar.xz vendor-nodejs-${version}.tar.xz ${topdir}
for spec in ${topdir}/*.spec; do
sed -i "s/^%define vendor_version.*/%define vendor_version %{version}/" ${spec}
done
echo "Done"