Created
October 27, 2016 12:16
-
-
Save fakhrullah/6aa1ed19b3e74fcd19aee6bf4b3d4775 to your computer and use it in GitHub Desktop.
shell script to prepare directory and git repo for autodeploy
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/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