Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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