Skip to content

Instantly share code, notes, and snippets.

@alloyking
Last active July 24, 2017 19:07
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 alloyking/70e0f58358d18679150ea0efcbd72919 to your computer and use it in GitHub Desktop.
Save alloyking/70e0f58358d18679150ea0efcbd72919 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "This will create a new bare repo here."
while [ !1 ]; do
break
done
while [ 1 ]; do
echo -n "Enter the name of the repo: "
read name
# check if empty
if [ ! $name ]; then
echo " ...you need to provide a name"
continue
fi
# add .git suffix to repo name if it doesn't exist
if [ `echo $name | grep -v .git$` ]; then
name=$name.git
fi
# check if dir exists
if [ -a $name ]; then
echo "...a file or directory called '$name' already exists in current directory"
continue
fi
break
done
while [ 1 ]; do
echo -n "Enter the the root path of the website /var/www/yoursite || /usr/share/nginx/html/yoursite: "
read path
# check if empty
if [ ! $path ]; then
echo " ...you need to provide a path"
continue
fi
# check if dir exists
if [ ! -d $path ]; then
echo ".. this directory does not exist"
continue
fi
break
done
while [ 1 ]; do
echo -n "Enter the group if you want a shared repo, leave empty otherwise: "
read group
if [ ! $group ]; then
break
else
if [ `grep ^$group: /etc/group` ]; then
shared="--shared=group"
while [ 1 ]; do
echo -n "Shared repos deny non fast forward by default. Do you want to enable them? [y/N]: "
read resp
if [ "$resp" == "y" -o "$resp" == "Y" ]; then
enable_ff=true
break
elif [ "$resp" == "n" -o "$resp" == "N" -o -z "$resp" ]; then
break
fi
echo "...bad answer, try again [y/N]"
done
break
else
echo "...group '$group' doesn't exist"
fi
fi
done
if [ $group ]; then
echo "Creating repo '$name' for group '$group'."
else
echo "Creating single user repo '$name'."
fi
git init --bare $shared $name
if [ $group ]; then
echo "Chgrping."
chgrp -R $group $name
if [ $enable_ff ]; then
echo "Enabling non fast forward updates."
git config -f $name/config receive.denyNonFastForwards true
fi
fi
hook_path=""
hook_path+="#!/bin/sh\n"
hook_path+="GIT_WORK_TREE=$path git checkout -f\n"
hook_path+="service nginx reload"
echo -e $hook_path > $name/hooks/post-receive
chmod u+x $name/hooks/post-receive
echo "Done!"
@alloyking
Copy link
Author

alloyking commented Jul 24, 2017

bash <(curl -s https://gist.githubusercontent.com/alloyking/70e0f58358d18679150ea0efcbd72919/raw/e00811b7498efcecf47d966e52dabdf8ba5181bc/make-bear-repo.sh)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment