Skip to content

Instantly share code, notes, and snippets.

@fakhrullah
Created October 27, 2016 12:16
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 fakhrullah/6aa1ed19b3e74fcd19aee6bf4b3d4775 to your computer and use it in GitHub Desktop.
Save fakhrullah/6aa1ed19b3e74fcd19aee6bf4b3d4775 to your computer and use it in GitHub Desktop.
shell script to prepare directory and git repo for autodeploy
#!/bin/sh
if [ $# -eq 0 ]
then
echo "ERROR: None argumetns supplied"
exit 1
fi
if [ -z "$1" ]
then
echo "ERROR: filenam is empty"
exit 1
fi
currentdir=${PWD}
workdir=$1
gitdir="$workdir.git"
echo "\n--------------------------------------"
echo "| Welcome to Hugo Git Deployer |"
echo "--------------------------------------"
echo "\n"
echo "Create work directory and git directory"
echo "\n"
# goto home dir
cd $currentdir
# create directory for repo and deploy
mkdir $workdir
mkdir $gitdir
echo "Initialize git directory\n"
# initialize bare repo
cd $gitdir
git init --bare
echo "Create script to auto update working directory\n"
## create hook file
echo "#!/bin/sh" > hooks/post-receive
echo "git --work-tree=$currentdir/$workdir --git-dir=$currentdir/$gitdir checkout -f" >> hooks/post-receive
echo "cd $currentdir/$workdir" >> hooks/post-receive
echo "hugo" >> hooks/post-receive
## make post-receive executable
chmod +x hooks/post-receive
# Finish, just need git add remote then git push
echo "Done!"
echo "Add this repo : ${logname}@${hostname}:$currentdir/$gitdir in local git"
echo "Then just git push. Web will deploy automatically\n"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment