Created
June 15, 2020 17:49
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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