Created
May 19, 2020 15:38
-
-
Save dsmiley/fdd589758cd74009222c518640b093b5 to your computer and use it in GitHub Desktop.
buildbox similar to crave
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 | |
# | |
# Utility script to rsync and then open a shell or execute commands on a remote host. | |
# Tailored a little bit for Lucene/Solr | |
# @author David Smiley | |
# https://gist.github.com/dsmiley/daff3c978fe234b48a69a01b54ea9914 | |
set -uex | |
REMOTEHOST=buildbox | |
REMOTEPATH="builds$PWD" | |
if [ ! -e ".git" ]; then #file or dir | |
echo "Expecting the current directory to be a git project." | |
exit 1 | |
fi | |
#https://stackoverflow.com/questions/13713101/rsync-exclude-according-to-gitignore-hgignore-svnignore-like-filter-c | |
git -C . ls-files --exclude-standard -oi --directory > /tmp/git-excludeme$$.txt | |
# note: This will fail if the target directory doesn't exist on the remote. This is deliberate to avoid accidents. | |
# Transfer everything in the current directory to the remote. | |
# Use times to detect new stuff. It'll sync times. | |
# Human-readable. Itemize. | |
# Exclude /.git and everything the .gitignore files say to ignore. | |
# Delete remote files except those excluded by our exclude patterns. | |
rsync -rthi --delete --exclude='/.git' --exclude-from=/tmp/git-excludeme$$.txt \ | |
. "$REMOTEHOST:$REMOTEPATH" | |
#FORMER FILTER: --filter="dir-merge,- .gitignore" | |
# However rsync has some slight differences, and some ignored files are in git anyway. | |
# SSH to the machine at the target directory | |
if [ -z "${1-}" ]; then #is $1 defined? | |
# switch to interactive shell (force TTY) | |
ssh -t $REMOTEHOST "cd $REMOTEPATH && exec \$SHELL -l" | |
else | |
# execute args and then quit | |
ssh -t $REMOTEHOST "cd $REMOTEPATH && $@" | |
# BEEP! | |
echo -ne '\007' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment