You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
3.6 KiB
Bash

#!/bin/bash
# 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
}
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
RaspberryPi (rpi) y
BeagleBone (bb) y
Desktop (d) n
Server (s) n
EOF
}
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'
}
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')
2 years ago
printf 'Building for Desktop!\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
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