Skip to content

Instantly share code, notes, and snippets.

@ncrmro
Created Jun 15, 2020
Embed
What would you like to do?
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