This repository has been archived by the owner on Dec 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
leadnaut
authored and
leadnaut
committed
Aug 16, 2024
1 parent
1d59744
commit c71bf7e
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/bin/bash | ||
|
||
|
||
WARN="[\033[1;33mWARN\033[0m]" | ||
INFO="[\033[1;32mINFO\033[0m]" | ||
ERROR="[\033[1;31mERROR\033[0m]" | ||
|
||
PATHFILE='deploypaths.txt' | ||
TEMPDIRPATH='package_temp' | ||
|
||
[ -d $TEMPDIRPATH ] | ||
TEMPDIRCHECK=$? | ||
|
||
# Make temp dir if it doesn't exist | ||
if [ $TEMPDIRCHECK == 1 ]; then | ||
mkdir $TEMPDIRPATH | ||
else | ||
echo -e "$INFO Temp directory was pre-existing. I promise not to delete it." | ||
fi | ||
|
||
cleanup () { | ||
# Do not delete the temp dir if it was pre-existing | ||
echo -e "$INFO Cleaning up" | ||
if [ $TEMPDIRCHECK == 1 ]; then | ||
rm -r $TEMPDIRPATH | ||
fi | ||
} | ||
|
||
BUILDPATH="${TEMPDIRPATH}/build" | ||
mkdir $BUILDPATH | ||
|
||
echo -e "$INFO Copying Files" | ||
|
||
while read path; do | ||
if [[ $path == \#* ]]; then | ||
true | ||
elif [ -d $path ]; then | ||
#path is a directory | ||
cp -r --parents $path $BUILDPATH | ||
elif [ -e $path ]; then | ||
#path is just a file | ||
cp --parents $path ${BUILDPATH} | ||
else | ||
echo -e "${WARN}: $path not found" | ||
fi | ||
done <$PATHFILE | ||
|
||
# Hashing directory line from https://stackoverflow.com/questions/545387/linux-compute-a-single-hash-for-a-given-folder-contents | ||
HASH=$( find ${BUILDPATH} -type f -print0 | sort -z | xargs -0 sha1sum | sha1sum ) | ||
TARNAME="build-${HASH:0:8}.tar" # Truncate the hash for a nicer file names | ||
|
||
# Create tarball | ||
echo -e "$INFO Creating Tarball" | ||
if ! tar cf $TARNAME -C $TEMPDIRPATH "./build"; then | ||
echo -e "$ERROR Tarball creation failed" | ||
cleanup | ||
exit 1 | ||
fi | ||
|
||
SSHTARGET=$1 | ||
# Check if we can find target | ||
if ! nc -z $SSHTARGET 22 2>/dev/null; then | ||
echo -e "$ERROR Host unreachable"; | ||
cleanup | ||
exit 1 | ||
fi | ||
|
||
echo -e "$INFO Copying Tarball - destination's password may be needed" | ||
if ! scp -q $TARNAME $SSHTARGET:~/; then | ||
echo -e "$ERROR Copy unsuccessful" | ||
cleanup | ||
exit 1 | ||
fi | ||
|
||
if ! ssh $SSHTARGET "tar xf $TARNAME; rm $TARNAME"; then | ||
echo -e "$ERROR Remote extraction failed" | ||
cleanup | ||
exit 1 | ||
fi | ||
|
||
echo -e "$INFO Deployed Successfully" | ||
cleanup | ||
exit 0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Enter paths of files and directories to be bundled and sent to the pi | ||
# deploy.sh will preserve the source directory layout so imports between files | ||
# should still work if all files are copied in |