Skip to content

Commit

Permalink
Create hil app binary (#74)
Browse files Browse the repository at this point in the history
* Add hilapp binary

* Create state package and move all states

* Move packages
  • Loading branch information
samparent97 authored May 6, 2024
1 parent 2a453ca commit d58e9d6
Show file tree
Hide file tree
Showing 43 changed files with 1,010 additions and 95 deletions.
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

0 comments on commit d58e9d6

Please sign in to comment.