Skip to content

Instantly share code, notes, and snippets.

@ncrmro
Created June 15, 2020 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ncrmro/ac6fa59c9125ac612c827391998e09fb to your computer and use it in GitHub Desktop.
Save ncrmro/ac6fa59c9125ac612c827391998e09fb to your computer and use it in GitHub Desktop.
A script to build and copy binary to remote host (pi in this case) only if src is changed and then run said binary.
#!/bin/sh
set -e
## Current folder name
PROJECT_NAME=${PWD##*/}
DEPLOY_HOST=pi
DEPLOY_USER=pi
CHECKSUM_FILE=target/checksum
CHECKSUM_LOCK=$(cksum Cargo.lock)
CHECKSUM_SRC=$(grep -ar -e . --include="*.rs" src | cksum | cut -c-32)
mkdir -p target
# Create file if not exists
touch $CHECKSUM_FILE
PREVIOUS_CHECKSUM=`cat $CHECKSUM_FILE`
CHECKSUM="$CHECKSUM_LOCK $CHECKSUM_SRC"
if [ ! "$CHECKSUM" = "$PREVIOUS_CHECKSUM" ]; then
echo "Different checksums building and deploying"
docker-compose up --exit-code-from build build || exit 1
scp target/arm-unknown-linux-gnueabihf/release/$PROJECT_NAME $DEPLOY_USER@$DEPLOY_HOST:/home/$DEPLOY_USER/
echo $CHECKSUM > $CHECKSUM_FILE
else
echo "No differences detected reflashing existing binary."
fi
ssh -t -t $DEPLOY_USER@$DEPLOY_HOST /home/$DEPLOY_USER/$PROJECT_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment