Skip to content

Commit

Permalink
Merge pull request #867 from jamesgol/implant-vendor-script
Browse files Browse the repository at this point in the history
Trap failed build when running 'go generate' on the implant
  • Loading branch information
moloch-- authored Sep 13, 2022
2 parents 84a95ae + 100b26a commit 70b0667
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions implant/scripts/update-vendor.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#!/bin/sh
#!/bin/bash

set -e

cleanup() {
[ ! -z "$1" ] && echo "Error $1 occurred on $2"

mv "${tempDir}/vendor" "${pwd}/../vendor"
mv "${tempDir}/go.mod" "${pwd}/../go-mod"
mv "${tempDir}/go.sum" "${pwd}/../go-sum"
cd ..
rm -rf "$tempDir"
}

# we are expecting from run from sliver/implant via 'go generate'
cd scripts

Expand All @@ -12,6 +22,10 @@ cp ../go-mod "${tempDir}/go.mod"
cp ../go-sum "${tempDir}/go.sum"
mv ../vendor "${tempDir}/vendor"


# Trap when a build fails so we can reset the environment
trap 'cleanup $? $LINENO' ERR

# build Go file with all imported packages
go run update-vendor.go "$tempDir"
cd "$tempDir"
Expand All @@ -20,8 +34,4 @@ go mod tidy -compat=1.17
go mod vendor

# move updated files back
mv "${tempDir}/vendor" "${pwd}/../vendor"
mv "${tempDir}/go.mod" "${pwd}/../go-mod"
mv "${tempDir}/go.sum" "${pwd}/../go-sum"
cd ..
rm -rf "$tempDir"
cleanup

0 comments on commit 70b0667

Please sign in to comment.