Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create hil app binary #74

Merged
merged 4 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,8 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# -----------------------------
# -----------------------------

# trace files
*.asc
*.mcap
1 change: 1 addition & 0 deletions cmd/canclienttest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
canclienttest
1 change: 1 addition & 0 deletions cmd/clidispatchertest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
clidispatchertest
2 changes: 2 additions & 0 deletions cmd/hilapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hilapp
!/env
177 changes: 177 additions & 0 deletions cmd/hilapp/build_sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
#!/bin/bash

set -e # Exit on errors

# Initialize verbose flag
VERBOSE=false

# Get current date
CURRENT_DATE=$(date +"%l:%M%PM - %b %-d, %Y")

# Get Git information
GIT_COMMIT=$(git rev-parse --short HEAD)
IS_DIRTY=$(git status --porcelain | wc -l)

if [[ $IS_DIRTY -ne 0 ]]; then
DIRTY_VS_CLEAN="dirty"
else
DIRTY_VS_CLEAN="clean"
fi

# Build flags for ldflags
LDFLAGS="-X 'main.Date=$CURRENT_DATE' -X 'main.GitCommit=${GIT_COMMIT}' -X 'main.DirtyVsClean=${DIRTY_VS_CLEAN}'"

# Parse command-line arguments
while getopts ":e:v" opt; do
case ${opt} in
e ) ENV_FILE="$OPTARG"
;;
v ) VERBOSE=true
;;
\? ) echo "Usage: $0 -e <env_file> [-v]"
exit 1
;;
esac
done
shift $((OPTIND -1))

if [ -z "$ENV_FILE" ]; then
echo "ERROR: Environment file not provided."
exit 1
fi

# Check if environment file exists
if [ ! -f "$ENV_FILE" ]; then
echo "ERROR: Environment file '$ENV_FILE' not found."
exit 1
fi

source "$ENV_FILE" # Load environment variables from file

# Set default values for GOOS and GOARCH if not provided in the environment file
if [ -n "$GOOS" ]; then
GOOS_ARG="GOOS=$GOOS"
fi

if [ -n "$GOARCH" ]; then
GOARCH_ARG="GOARCH=$GOARCH"
fi

if [ -n "$GOARM" ]; then
GOARM_ARG="GOARM=$GOARM"
fi

# Build the Go program with the specified GOOS and GOARCH, if provided
if [ -n "$GOOS_ARG" ] || [ -n "$GOARCH_ARG" ] || [ -n "$GOARM_ARG" ]; then
if [ "$VERBOSE" = true ]; then
echo "Building Go program with specified GOOS and GOARCH..."
fi
BUILD_CMD="$GOOS_ARG $GOARCH_ARG $GOARM_ARG go build -ldflags=\"$LDFLAGS\" -o hilapp main.go"
else
if [ "$VERBOSE" = true ]; then
echo "Building Go program..."
fi
BUILD_CMD="go build -ldflags="$LDFLAGS" -o hilapp main.go"
fi

if [ "$VERBOSE" = true ]; then
echo "Executing build command: $BUILD_CMD"
fi

eval "$BUILD_CMD"

echo ""
echo "-------------------------------"
echo ""

# Check if REMOTE_TARGET is set in the environment file
if [ -n "$REMOTE_TARGET" ]; then
if [ -n "$REMOTE_USER" ] && [ -n "$REMOTE_HOST" ] && [ -n "$BIN_PATH_REMOTE" ]; then
if [ "$VERBOSE" = true ]; then
echo "Syncing binary to remote target..."
fi
# Sync binary to remote target
RSYNC_CMD="rsync -avz -e ssh hilapp '${REMOTE_USER}@${REMOTE_HOST}:${BIN_PATH_REMOTE}'"
if [ "$VERBOSE" = true ]; then
echo "Executing rsync command: $RSYNC_CMD"
fi
eval "$RSYNC_CMD"
echo "Binary synced to remote target."
else
echo "ERROR: Remote user, host, or path not provided in environment file."
fi
else
echo "INFO: No remote target specified in environment file. Keeping binary locally."
fi

echo ""
echo "-------------------------------"
echo ""

if [ -n "$REMOTE_TARGET" ]; then
# Check if RESULTS_SERVER_PATH_LOCAL and RESULTS_PI_PATH are set in the environment file
if [ -n "$RESULTS_SERVER_PATH_LOCAL" ] && [ -n "$RESULTS_SERVER_PATH_REMOTE" ]; then
if [ "$VERBOSE" = true ]; then
echo "Syncing results server folder..."
fi
RSYNC_RESULTS_CMD="rsync -avz -e ssh $RESULTS_SERVER_PATH_LOCAL ${REMOTE_USER}@${REMOTE_HOST}:${RESULTS_SERVER_PATH_REMOTE}"
if [ "$VERBOSE" = true ]; then
echo "Executing rsync command: $RSYNC_RESULTS_CMD"
fi
eval "$RSYNC_RESULTS_CMD"
echo "Results server folder synced."
else
echo "INFO: Results server local folder and/or remote path not provided in environment file. Skipping sync."
fi
fi

echo ""
echo "-------------------------------"
echo ""

if [ -n "$REMOTE_TARGET" ]; then
# Check if CONFIG_YAML_PATH_LOCAL and CONFIG_YAML_PATH_REMOTE are set in the environment file
if [ -n "$CONFIG_YAML_PATH_LOCAL" ] && [ -n "$CONFIG_YAML_PATH_REMOTE" ]; then
if [ "$VERBOSE" = true ]; then
echo "Syncing config.yaml file..."
fi
RSYNC_CONFIG_CMD="rsync -e ssh $CONFIG_YAML_PATH_LOCAL ${REMOTE_USER}@${REMOTE_HOST}:${CONFIG_YAML_PATH_REMOTE}"
if [ "$VERBOSE" = true ]; then
echo "Executing rsync command: $RSYNC_CONFIG_CMD"
fi
eval "$RSYNC_CONFIG_CMD"
echo "config.yaml file synced."
else
echo "INFO: config.yaml local file and/or remote path not provided in environment file. Skipping sync."
fi
fi

echo ""
echo "-------------------------------"
echo ""

if [ -n "$REMOTE_TARGET" ]; then
# Check if TAGS_YAML_PATH_LOCAL and TAGS_YAML_PATH_REMOTE are set in the environment file
if [ -n "$TAGS_YAML_PATH_LOCAL" ] && [ -n "$TAGS_YAML_PATH_REMOTE" ]; then
if [ "$VERBOSE" = true ]; then
echo "Syncing tags.yaml file..."
fi
RSYNC_TAGS_CMD="rsync -e ssh $TAGS_YAML_PATH_LOCAL ${REMOTE_USER}@${REMOTE_HOST}:${TAGS_YAML_PATH_REMOTE}"
if [ "$VERBOSE" = true ]; then
echo "Executing rsync command: $RSYNC_TAGS_CMD"
fi
eval "$RSYNC_TAGS_CMD"
echo "tags.yaml file synced."
else
echo "INFO: tags.yaml local file and/or remote path not provided in environment file. Skipping sync."
fi
fi

echo ""
echo "-------------------------------"
echo ""

echo "Successfully built and synced all targets."
echo ""


3 changes: 3 additions & 0 deletions cmd/hilapp/env/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!raspi.env
13 changes: 13 additions & 0 deletions cmd/hilapp/env/raspi.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
REMOTE_TARGET=1
REMOTE_USER=admin
REMOTE_HOST=100.97.227.63
BIN_PATH_REMOTE=/opt/macfe/bin/hilapp
GOOS=linux
GOARCH=arm
GOARM=7
RESULTS_SERVER_PATH_LOCAL=../../results/server
RESULTS_SERVER_PATH_REMOTE=/opt/macfe/scripts/results
CONFIG_YAML_PATH_LOCAL=../../config/config.yaml
CONFIG_YAML_PATH_REMOTE=/opt/macfe/etc/config.yaml
TAGS_YAML_PATH_LOCAL=../../config/tags.yaml
TAGS_YAML_PATH_REMOTE=/opt/macfe/etc/tags.yaml
Loading
Loading