2024-05-18 06:43:39 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Quick and dirty building shell script which will evolve with more time make inside a Makefile
|
|
|
|
|
2024-06-08 15:57:10 -07:00
|
|
|
|
|
|
|
# stop the script if any command fails
|
|
|
|
set -euo pipefail
|
|
|
|
|
2024-05-18 06:43:39 -07:00
|
|
|
install_go() {
|
2024-06-08 15:57:10 -07:00
|
|
|
go version && { echo "golang is already installed. moving on" && return 0 ; }
|
|
|
|
|
2024-05-18 06:43:39 -07:00
|
|
|
[ -d thirdparty ] || mkdir thirdparty
|
|
|
|
cd thirdparty
|
2024-05-20 08:35:15 -07:00
|
|
|
arch=`uname -i`
|
|
|
|
prog="" # default Go binary tar.gz
|
2024-06-08 15:57:10 -07:00
|
|
|
version="1.22.4"
|
|
|
|
|
2024-05-20 08:35:15 -07:00
|
|
|
case "$arch" in
|
|
|
|
x86_64|amd64)
|
2024-06-08 15:57:10 -07:00
|
|
|
prog="go${version}.linux-amd64.tar.gz";;
|
2024-05-20 08:35:15 -07:00
|
|
|
i?86)
|
2024-06-08 15:57:10 -07:00
|
|
|
prog="go${version}.linux-386.tar.gz";;
|
2024-05-24 02:09:34 -07:00
|
|
|
arm64|aarch64|unknown) # Let assume from now unknown is RPi 5 => TODO: fix
|
2024-06-08 15:57:10 -07:00
|
|
|
prog="go${version}.linux-arm64.tar.gz";;
|
2024-05-20 08:35:15 -07:00
|
|
|
*)
|
|
|
|
printf 'Unsupported architecture: "%s" -> Download or build Go instead\n' "$arch" >&2; exit 2;;
|
2024-05-20 08:50:37 -07:00
|
|
|
esac
|
2024-05-20 08:35:15 -07:00
|
|
|
wget "https://go.dev/dl/$prog"
|
2024-05-20 08:54:35 -07:00
|
|
|
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf $prog
|
2024-05-18 06:43:39 -07:00
|
|
|
export PATH=$PATH:/usr/local/go/bin
|
|
|
|
cd ..
|
|
|
|
rm -R thirdparty
|
|
|
|
}
|
|
|
|
|
|
|
|
building_rfswift() {
|
|
|
|
cd go/rfswift/
|
|
|
|
go build .
|
|
|
|
mv rfswift ../.. # moving compiled file to project's root
|
|
|
|
cd ../..
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "[+] Installing Go"
|
2024-06-08 15:57:10 -07:00
|
|
|
install_go
|
2024-05-18 06:43:39 -07:00
|
|
|
|
|
|
|
echo "[+] Building RF Switch Go Project"
|
|
|
|
building_rfswift
|
|
|
|
|
|
|
|
# Set default values
|
|
|
|
DEFAULT_IMAGE="myrfswift:latest"
|
|
|
|
DEFAULT_DOCKERFILE="Dockerfile"
|
|
|
|
|
|
|
|
# Prompt the user for input with default values
|
|
|
|
read -p "Enter image tag value (default: $DEFAULT_IMAGE): " imagename
|
|
|
|
read -p "Enter value for Dockerfile to use (default: $DEFAULT_DOCKERFILE): " dockerfile
|
|
|
|
|
|
|
|
# Use default values if variables are empty
|
|
|
|
imagename=${imagename:-$DEFAULT_IMAGE}
|
|
|
|
dockerfile=${dockerfile:-$DEFAULT_DOCKERFILE}
|
|
|
|
|
|
|
|
echo "[+] Building the Docker container"
|
2024-06-08 15:57:10 -07:00
|
|
|
sudo docker build . -t $imagename -f $dockerfile
|