2022-01-21 18:45:44 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
cleanup() {
|
2022-03-15 15:14:34 +01:00
|
|
|
test -n "${dir}" && rm -rf "${dir}"
|
2022-01-21 18:45:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
error() {
|
|
|
|
echo "An error occurred. Exiting." >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
trap error ERR SIGINT
|
|
|
|
trap cleanup EXIT
|
|
|
|
set -e
|
|
|
|
|
2022-03-15 15:14:34 +01:00
|
|
|
version=$(rpmspec -q --queryformat="%{VERSION}\n" velociraptor.spec|head -1)
|
2022-01-21 18:45:44 +01:00
|
|
|
|
|
|
|
dir="$(realpath "$(mktemp -d vendoring.XXXXXX)")"
|
2022-03-15 15:14:34 +01:00
|
|
|
topdir="$(realpath "$(dirname "$0")")"
|
2022-01-21 18:45:44 +01:00
|
|
|
|
|
|
|
rpmspec -P velociraptor.spec --define "_sourcedir $PWD" | \
|
|
|
|
awk '
|
|
|
|
BEGIN { go=0; };
|
|
|
|
/^%build/ { go=0; };
|
|
|
|
{ if (go) print };
|
2022-03-15 15:14:34 +01:00
|
|
|
/^%setup/ { go=1 }' > ${dir}/setup.sh
|
2022-01-21 18:45:44 +01:00
|
|
|
|
|
|
|
echo "Expanding archive..."
|
2022-03-15 15:14:34 +01:00
|
|
|
cpio -D "${dir}" -id < velociraptor-${version}.obscpio
|
2022-01-21 18:45:44 +01:00
|
|
|
|
|
|
|
echo "Running %prep"
|
2022-03-15 15:14:34 +01:00
|
|
|
cd "${dir}/velociraptor-${version}"
|
|
|
|
sh ${dir}/setup.sh
|
2022-01-21 18:45:44 +01:00
|
|
|
|
|
|
|
echo "Re-vendoring Go code..."
|
|
|
|
rm -rf vendor
|
|
|
|
go mod vendor
|
2022-03-15 15:14:34 +01:00
|
|
|
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"
|
2022-01-21 18:45:44 +01:00
|
|
|
|
|
|
|
echo "Re-vendoring nodejs code..."
|
2022-03-15 15:14:34 +01:00
|
|
|
cd "${dir}/velociraptor-${version}/gui/velociraptor"
|
2022-01-21 18:45:44 +01:00
|
|
|
rm -rf node_modules
|
|
|
|
npm install
|
|
|
|
cd ../..
|
2022-03-15 15:14:34 +01:00
|
|
|
tar Jcf ${dir}/vendor-nodejs-${version}.tar.xz gui/velociraptor/node_modules
|
2022-01-21 18:45:44 +01:00
|
|
|
|
2022-03-15 15:14:34 +01:00
|
|
|
cd "${dir}"
|
|
|
|
mv vendor-golang-*${version}.tar.xz vendor-nodejs-${version}.tar.xz ${topdir}
|
2022-01-21 18:45:44 +01:00
|
|
|
|
2022-03-15 15:14:34 +01:00
|
|
|
for spec in ${topdir}/*.spec; do
|
2022-03-15 03:18:53 +01:00
|
|
|
sed -i "s/^%define vendor_version.*/%define vendor_version %{version}/" ${spec}
|
|
|
|
done
|
2022-02-18 02:36:48 +01:00
|
|
|
|
2022-01-21 18:45:44 +01:00
|
|
|
echo "Done"
|