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-08-19 23:19:45 +02:00
|
|
|
if test -n "${gopathdir}"; then
|
|
|
|
chmod -R u+w "${gopathdir}"
|
|
|
|
rm -rf "${gopathdir}"
|
|
|
|
fi
|
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}"
|
2022-12-07 04:37:22 +01:00
|
|
|
tar Jxf ${topdir}/vmlinux.h-5.14.21150400.22-150400-default.tar.xz
|
2022-03-15 15:14:34 +01:00
|
|
|
sh ${dir}/setup.sh
|
2022-01-21 18:45:44 +01:00
|
|
|
|
|
|
|
echo "Re-vendoring Go code..."
|
2022-08-19 23:19:45 +02:00
|
|
|
gopathdir="$(mktemp -d /tmp/gopath.XXXXXXX)"
|
2022-01-21 18:45:44 +01:00
|
|
|
rm -rf vendor
|
2022-08-19 23:19:45 +02:00
|
|
|
export GOPATH="$gopathdir"
|
2022-11-12 02:51:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Vendoring doesn't get along with replaced modules, so symlink to those
|
2022-01-21 18:45:44 +01:00
|
|
|
go mod vendor
|
2022-11-12 02:51:37 +01:00
|
|
|
replace_module() {
|
|
|
|
local mod=$1
|
|
|
|
local path=$2
|
|
|
|
rm -rf "vendor/${mod}"
|
|
|
|
rel="$(echo $mod|tr A-Za-z0-9_- .|sed -e 's/\.\.\.*/../g')"
|
|
|
|
ln -s "${rel}/${path}" "vendor/${mod}"
|
2022-12-07 04:37:22 +01:00
|
|
|
set -x
|
2022-11-12 02:51:37 +01:00
|
|
|
ls -la vendor/${mod}/
|
2022-12-07 04:37:22 +01:00
|
|
|
set +x
|
2022-11-12 02:51:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
replace_module github.com/aquasecurity/libbpfgo third_party/libbpfgo
|
|
|
|
|
2022-03-15 15:14:34 +01:00
|
|
|
tar Jcf ${dir}/vendor-golang-${version}.tar.xz vendor
|
2022-11-12 02:51:37 +01:00
|
|
|
cd "${dir}"
|
|
|
|
mv vendor-golang-*${version}.tar.xz ${topdir}
|
2022-03-15 15:14:34 +01:00
|
|
|
|
|
|
|
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-05-12 22:23:00 +02:00
|
|
|
sed -i "s/^%define vendor_version.*/%define vendor_version ${version}/" ${spec}
|
2022-03-15 03:18:53 +01:00
|
|
|
done
|
2022-02-18 02:36:48 +01:00
|
|
|
|
2022-01-21 18:45:44 +01:00
|
|
|
echo "Done"
|