new: global (cross) compilation script

This commit is contained in:
evilsocket 2018-02-11 17:45:55 +01:00
commit 7382cc7cce
6 changed files with 97 additions and 54 deletions

96
build.sh Executable file
View file

@ -0,0 +1,96 @@
#!/bin/bash
VERSION=$(cat core/banner.go | grep Version | cut -d '"' -f 2)
clean() {
rm -rf build
mkdir build
}
bin_dep() {
BIN=$1
which $BIN > /dev/null || { echo "@ Dependency $BIN not found !"; exit 1; }
}
vm_dep() {
HOST=$1
ping -c 1 $HOST > /dev/null || { echo "@ Virtual machine host $HOST not visible !"; exit 1; }
}
build_linux_amd64() {
OUTPUT=$1
echo "@ Building $OUTPUT ..."
go build -o "$OUTPUT" ..
}
build_linux_arm7() {
bin_dep 'arm-linux-gnueabi-gcc'
OUTPUT=$1
OLD=$(pwd)
echo "@ Building $OUTPUT ..."
cd /tmp
rm -rf libpcap-1.8.1
if [ ! -f /tmp/libpcap-1.8.1.tar.gz ]; then
echo "@ Downloading http://www.tcpdump.org/release/libpcap-1.8.1.tar.gz ..."
wget -q http://www.tcpdump.org/release/libpcap-1.8.1.tar.gz -O /tmp/libpcap-1.8.1.tar.gz
fi
echo "@ Cross compiling libpcap for ARM ..."
tar xf libpcap-1.8.1.tar.gz
cd libpcap-1.8.1
export CC=arm-linux-gnueabi-gcc
./configure --host=arm-linux-gnueabi --with-pcap=linux > /dev/null
make CFLAGS='-w' -j4 > /dev/null
echo "@ Compiling $OUTPUT ..."
cd "$OLD"
env CC=arm-linux-gnueabi-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 CGO_LDFLAGS="-L/tmp/libpcap-1.8.1" go build -o "$OUTPUT" ..
rm -rf /tmp/libpcap-1.8.1
}
build_macos_amd64() {
vm_dep 'osxvm'
DIR=/Users/evilsocket/gocode/src/github.com/evilsocket/bettercap-ng
OUTPUT=$1
echo "@ Updating repo on MacOS VM ..."
ssh osxvm "cd $DIR && rm -rf '$OUTPUT' && git checkout . && git pull" > /dev/null
echo "@ Building $OUTPUT ..."
ssh osxvm "export GOPATH=/Users/evilsocket/gocode && cd '$DIR' && PATH=$PATH:/usr/local/bin && go build -o $OUTPUT ." > /dev/null
echo "@ Downloading $OUTPUT ..."
scp -C osxvm:$DIR/$OUTPUT . > /dev/null
}
build_windows_amd64() {
vm_dep 'winvm'
DIR=c:/Users/evilsocket/gopath/src/github.com/evilsocket/bettercap-ng
OUTPUT=$1
echo "@ Updating repo on Windows VM ..."
ssh winvm "cd $DIR && del *.exe && git pull" > /dev/null
echo "@ Building $OUTPUT ..."
ssh winvm "cd $DIR && go build -o $OUTPUT ." > /dev/null
echo "@ Downloading $OUTPUT ..."
scp -C winvm:$DIR/$OUTPUT . > /dev/null
}
clean
cd build
build_linux_amd64 bettercap-ng_linux_amd64_$VERSION
build_linux_arm7 bettercap-ng_linux_arm7_$VERSION
build_macos_amd64 bettercap-ng_macos_amd64_$VERSION
build_windows_amd64 bettercap-ng_windows_amd64_$VERSION.exe
echo
echo
du -sh *
cd --

View file

@ -1,21 +0,0 @@
# nothing to see here, just what i use to cross compile for ARM
DIR=/Users/evilsocket/gocode/src/github.com/evilsocket/bettercap-ng
EXE=bettercap-ng_linux_arm7
echo "@ Updating repo ..."
rm -rf $EXE && git pull
echo "@ Configuring libpcap ..."
rm -rf libpcap-*.*
rm -rf libpcap*
wget http://www.tcpdump.org/release/libpcap-1.8.1.tar.gz
tar xvf libpcap-1.8.1.tar.gz
cd libpcap-1.8.1
export CC=arm-linux-gnueabi-gcc
./configure --host=arm-linux --with-pcap=linux
make
echo "@ Building $EXE ..."
cd ..
env CC=arm-linux-gnueabi-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 CGO_LDFLAGS="-Llibpcap-1.8.1" go build -o $EXE .
rm -rf libpcap-1.8.1

View file

@ -1,3 +0,0 @@
# nothing to see here, quite literally ...
go build -o bettercap-ng_linux_amd64

View file

@ -1,11 +0,0 @@
# nothing to see here, just what i use to build for OS X
DIR=/Users/evilsocket/gocode/src/github.com/evilsocket/bettercap-ng
AMD64_EXE=bettercap-ng_macos_amd64
echo "@ Updating repo ..."
ssh osxvm "cd $DIR && rm -rf $AMD64_EXE && git pull"
echo "@ Building $AMD64_EXE ..."
ssh osxvm "export GOPATH=/Users/evilsocket/gocode && cd $DIR && PATH=$PATH:/usr/local/bin && go build -o $AMD64_EXE ."
scp osxvm:$DIR/$AMD64_EXE .

View file

@ -1,18 +0,0 @@
# nothing to see here, just what i use to build for Windows
#
# -> https://stackoverflow.com/questions/38047858/compile-gopacket-on-windows-64bit
DIR=c:/Users/evilsocket/gopath/src/github.com/evilsocket/bettercap-ng
AMD64_EXE=bettercap-ng_win32_amd64.exe
I386_EXE=bettercap-ng_win32_i386.exe
echo "@ Updating repo ..."
ssh winvm "cd $DIR && del *.exe && git pull"
echo "@ Building $AMD64_EXE ..."
ssh winvm "cd $DIR && go build -o $AMD64_EXE ."
# not worth the effort of installing the 32bit toolchain to be honest ...
# echo "@ Building $I386_EXE ..."
# ssh winvm "cd $DIR && set GOARCH=386 && go build -o $I386_EXE . && dir *.exe"
scp winvm:$DIR/$AMD64_EXE .

View file

@ -2,7 +2,7 @@ package core
const (
Name = "bettercap-ng"
Version = "0.9.0"
Version = "2.0.0"
Author = "Simone 'evilsocket' Margaritelli"
Website = "https://bettercap.org/"
)