#!/bin/bash # adding commands usage() { # how to use this build script cat </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 Server!\n' GARCH="amd64" PLATFORM="server" ;; 'd') 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