Last active
July 24, 2017 19:07
-
-
Save alloyking/70e0f58358d18679150ea0efcbd72919 to your computer and use it in GitHub Desktop.
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 | |
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!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bash <(curl -s https://gist.githubusercontent.com/alloyking/70e0f58358d18679150ea0efcbd72919/raw/e00811b7498efcecf47d966e52dabdf8ba5181bc/make-bear-repo.sh)