Skip to content

Instantly share code, notes, and snippets.

@raphiz
Created December 28, 2014 22:46
Show Gist options
  • Save raphiz/43a5d8ee70c8a284fc8a to your computer and use it in GitHub Desktop.
Save raphiz/43a5d8ee70c8a284fc8a to your computer and use it in GitHub Desktop.
Easily deploy Composer Apps to a remote FTP server using curlftpfs, rsync and git
#!/usr/bin/env bash
# Requires: fuse, curlftpfs, rsync, git and composer
set -u
REPOSITORY="https://github.com/raphiz/php-raphael.li.git"
FTP_HOST="myhost.com"
FTP_USER="user"
FTP_PASS="secrit"
FTP_SUBFOLDER="httpdocs"
EXCLUDE=("/.git/")
COMPOSER_BIN="composer"
WORKING_DIR="/tmp/mysite/"
MOUNTPOINT="/mnt/mysite/"
TEMP_DIR=$(mktemp -d)
if [ -d "$WORKING_DIR" ]; then
echo "Folder '$WORKING_DIR' exists! Please delete it first!"
exit 1
fi
if [ "$(ls -A $MOUNTPOINT)" ]; then
echo "The mountpoint at $MOUNTPOINT is not empty!"
exit 1
fi
# Process excludes into rsync parameters
for i in "${!EXCLUDE[@]}"
do
EXCLUDE[i]="--exclude=${EXCLUDE[i]}"
done
# TODO: check if user can write to $MOUNTPOINT
mkdir -p "$WORKING_DIR"
cd "$WORKING_DIR"
git clone "$REPOSITORY" "$WORKING_DIR"
"$COMPOSER_BIN" install --no-dev --optimize-autoloader
# Mount FTP share
mkdir -p "$MOUNTPOINT"
curlftpfs "$FTP_USER:$FTP_PASS@$FTP_HOST" "$MOUNTPOINT"
# Sync and accept defaults
rsync -rlptoDvzh --temp-dir="$TEMP_DIR" "${EXCLUDE[@]}" --delete "$WORKING_DIR" "$MOUNTPOINT$FTP_SUBFOLDER"
# Umount
fusermount -u "$MOUNTPOINT"
# Clean up
cd ~
rm -Rf "$TEMP_DIR"
rm -Rf "$WORKING_DIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment