Last active
December 29, 2015 10:09
-
-
Save thomseddon/7655422 to your computer and use it in GitHub Desktop.
Create a git deployment folder on a remote machine
This file contains hidden or 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/bash | |
# Read vars | |
if [ "$1" == "" ]; then | |
echo "Usage: ./git_deploy <folder> <user?> <post-receive?>" | |
exit 1 | |
fi | |
folder=$1 | |
if [ -d "$folder" ]; then | |
echo "$folder already exists" | |
exit 1 | |
fi | |
user=$2 | |
if [ "$2" == "" ]; then | |
user=$USER | |
fi | |
post_receive=$3 | |
# Create folder | |
mkdir $folder | |
cd $folder | |
dir=$(pwd) | |
# Config git | |
git init | |
git config core.worktree $dir | |
git config receive.denycurrentbranch ignore | |
cat > .git/hooks/post-receive <<EOL | |
#!/bin/sh | |
git checkout -f | |
$post_receive | |
EOL | |
chmod +x .git/hooks/post-receive | |
# Fix ownership | |
cd ../ | |
chown $user:$user -R $folder | |
echo | |
echo "Run: git remote add prod ssh://$user@$HOSTNAME$dir" | |
echo "Run: git push prod master" | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment