cleaned up files and fixed build script
parent
204ba6fb82
commit
710910def0
@ -1,24 +1,150 @@
|
||||
#!/bin/bash
|
||||
echo "Purging old builds"
|
||||
rm -v bin/* 2>/dev/null
|
||||
|
||||
echo "Removing Logs"
|
||||
rm -v bin/log/* 2>/dev/null
|
||||
# adding commands
|
||||
usage() {
|
||||
# how to use this build script
|
||||
cat <<EOF
|
||||
usage: $0 [-c][-l][-i s] s1 [s2....]
|
||||
s1, s2, etc. the systems to build for (see -l)
|
||||
Options:
|
||||
-c, --clean cleans the bin folder of any existing builds
|
||||
-f, --force same as clean but skips prompt
|
||||
-l, --list list available systems to build for
|
||||
-s, --scp will attempt to scp to aplicable devices
|
||||
-h, --help display this message
|
||||
EOF
|
||||
}
|
||||
|
||||
echo "Building reactor binaries"
|
||||
env GOOS=linux GOARCH=arm GOARM=7 go build -o bin/reactor_linux_arm cmd/reactor/main.go
|
||||
env GOOS=linux GOARCH=arm64 go build -o bin/reactor_linux_arm64 cmd/reactor/main.go
|
||||
list_systems() {
|
||||
# list available systems to build for
|
||||
cat <<EOF
|
||||
Name (shorthand) SCP available? (y/n)
|
||||
$0 Name or $0 (shorthand) will build for the device
|
||||
|
||||
echo "Building tui binaries"
|
||||
env GOOS=linux GOARCH=arm GOARM=7 go build -o bin/tui_linux_arm cmd/tui/main.go
|
||||
env GOOS=linux GOARCH=arm64 go build -o bin/tui_linux_arm64 cmd/tui/main.go
|
||||
env GOOS=linux GOARCH=amd64 go build -o bin/tui_linux_amd64 cmd/tui/main.go
|
||||
RaspberryPi (rpi) y
|
||||
BeagleBone (bb) y
|
||||
Desktop (d) n
|
||||
Server (s) n
|
||||
EOF
|
||||
}
|
||||
|
||||
echo "Building server binary"
|
||||
env GOOS=linux GOARCH=amd64 go build -o bin/server_linux_amd64 cmd/server/main.go
|
||||
clean_builds() {
|
||||
# cleans old builds
|
||||
if [[ "$FORCE"=true ]] ; then
|
||||
printf 'Cleaning old builds... \n'
|
||||
rm -v bin/* 2>/dev/null
|
||||
else
|
||||
read -p "Clean old builds?(y/n) " -n 1 -r
|
||||
if [[ $REPLY =~ ^[Yy]$ ]] ; then
|
||||
rm -v bin/* 2>/dev/null
|
||||
fi
|
||||
fi
|
||||
printf 'Clean!\n'
|
||||
}
|
||||
|
||||
echo "Compressing binaries for distrubution"
|
||||
tar -czf pireactor.tar.gz -C bin reactor_linux_arm64
|
||||
tar -czf bbreactor.tar.gz -C bin reactor_linux_arm
|
||||
tar -czf server.tar.gz -C bin server_linux_amd64
|
||||
tar -czf tui.tar.gz -C bin tui_linux_amd64 tui_linux_arm tui_linux_arm64
|
||||
create_build() {
|
||||
# create build for $1
|
||||
case $1 in
|
||||
'rpi' )
|
||||
printf 'Building for Raspberry Pi!\n'
|
||||
GARCH="arm64"
|
||||
PLATFORM="reactor"
|
||||
;;
|
||||
'bb')
|
||||
printf 'Building for BeagleBone!\n'
|
||||
GARCH="arm"
|
||||
GARM="GOARM=7"
|
||||
PLATFORM="reactor"
|
||||
;;
|
||||
's')
|
||||
printf 'Building for BeagleBone!\n'
|
||||
GARCH="amd64"
|
||||
PLATFORM="server"
|
||||
;;
|
||||
'd')
|
||||
printf 'Building for BeagleBone!\n'
|
||||
GARCH="amd64"
|
||||
PLATFORM="server"
|
||||
;;
|
||||
* )
|
||||
printf 'ERROR: %s type unrecognized!\n' "$1"
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
# setting up build
|
||||
OUTFILE=$(printf '%s_linux_%s' "$PLATFORM" "$GARCH")
|
||||
INFILE=$(printf '%s/main.go' "$PLATFORM")
|
||||
# building
|
||||
env GOOS=linux GOARCH="$GARCH" $GARM go build -o bin/"$OUTFILE" cmd/"$INFILE"
|
||||
echo "Finished"
|
||||
if [[ "$SCP"=true ]] ; then
|
||||
printf 'Attempting to transfer to %s\n' "$2"
|
||||
if [[ "$1" == "bb" ]] ; then
|
||||
printf 'Copying to %s\n' "192.168.100.90"
|
||||
scp "$HOME/FRMS/bin/$OUTFILE" debian:~/
|
||||
else
|
||||
printf 'SCP Not available!\n'
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# handle long form
|
||||
for arg in "$@"; do
|
||||
shift
|
||||
case "$arg" in
|
||||
'--help') set -- "$@" "-h" ;;
|
||||
'--list') set -- "$@" "-l" ;;
|
||||
'--scp') set -- "$@" "-s" ;;
|
||||
'--clean') set -- "$@" "-c" ;;
|
||||
'--force') set -- "$@" "-f" ;;
|
||||
*) set -- "$@" "$arg" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# handle args
|
||||
while getopts "lcsfh" opt ; do
|
||||
case "$opt" in
|
||||
'h' )
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
'c' )
|
||||
clean_builds
|
||||
;;
|
||||
'f' )
|
||||
FORCE=true
|
||||
clean_builds
|
||||
;;
|
||||
's' )
|
||||
SCP=true
|
||||
;;
|
||||
'l')
|
||||
list_systems
|
||||
;;
|
||||
'?' )
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
|
||||
for dev in "$@"; do
|
||||
case "$dev" in
|
||||
'RaspberryPi') dev='rpi' ;;
|
||||
'BeagleBone') dev='bb' ;;
|
||||
'Server') dev='s' ;;
|
||||
'Desktop') dev='d' ;;
|
||||
esac
|
||||
echo "$dev"
|
||||
create_build "$dev"
|
||||
done
|
||||
printf 'Nothing else to do!\n'
|
||||
|
||||
# echo "Compressing binaries for distrubution"
|
||||
# tar -czf pireactor.tar.gz -C bin reactor_linux_arm64
|
||||
# tar -czf bbreactor.tar.gz -C bin reactor_linux_arm
|
||||
# tar -czf server.tar.gz -C bin server_linux_amd64
|
||||
# tar -czf tui.tar.gz -C bin tui_linux_amd64 tui_linux_arm tui_linux_arm64
|
||||
|
@ -1,2 +0,0 @@
|
||||
#!/bin/bash
|
||||
env GOOS=linux GOARCH=arm GOARM=7 go build -o ../../bin/
|
@ -1,2 +0,0 @@
|
||||
#!/bin/bash
|
||||
go build -race -o ../../bin/server_$GOOS_$GOARCH
|
Loading…
Reference in New Issue