Skip to content

Instantly share code, notes, and snippets.

@blbradley
Created July 28, 2013 23:32
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 blbradley/6100716 to your computer and use it in GitHub Desktop.
Save blbradley/6100716 to your computer and use it in GitHub Desktop.
Deploy over SFTP, for those moments when your host tells you to go fuck yourself.
#!/bin/sh
# Requirements:
# Install expect and make sure it's on your path
# sftp with working '-r' option
GIT_DIR=$1
HOST=$2
PASSWORD=$3
if [ ! -d "$GIT_DIR" ] ; then
echo "First argument is not a directory. Exiting..."
exit 1
fi
DIRS=`cd $GIT_DIR && git ls-files | sed 's:[^/]*$::'| sed '/^$/d' | sort -u`
FILES=`cd $GIT_DIR && git ls-files`
expect - <<END
set timeout -1
spawn sftp -r $HOST
expect password:
send "$PASSWORD\r"
expect sftp>
send "lcd $GIT_DIR\r"
foreach d { $DIRS } {
expect sftp>
send "mkdir \$d\r"
}
foreach f { $FILES } {
expect sftp>
send "put \$f\r"
}
expect sftp>
send "quit\r"
expect eof
exit 0
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment