Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- git_user="git"
- git_dir="/var/git"
- if [ -z $1 ] || [ -z $2 ]
- then
- echo "$0 <repository name> <members>..."
- exit 1
- fi
- if [ -d '${git_dir}/${1}.git' ]
- then
- echo "Repository already exists."
- exit 2
- fi
- if [ ! -d ${git_dir} ]
- then
- echo "Git directory dosn't exist"
- exit 3
- fi
- length=$(($#-1))
- members=${@:2:$length}
- repository=$1
- mkdir ${git_dir}/${repository}.git
- cd ${git_dir}/${repository}.git
- git init
- touch .gitignore
- git add .gitignore
- git commit -a -m "Initial commit."
- git remote add origin ${git_user}@localhost:${repository}.git
- git push origin master:refs/heads/master
- # add users to gitosis.conf
- rand_dir=`</dev/urandom tr -dc A-Za-z0-9 | head -c8`
- mkdir ${git_dir}/tmp/ 2> /dev/null
- mkdir ${git_dir}/tmp/${rand_dir} 2> /dev/null
- cd ${git_dir}/tmp/${rand_dir}
- git clone ${git_user}@localhost:gitosis-admin.git .
- touch gitosis.conf
- echo "[group ${repository}]" >> gitosis.conf
- echo "members = ${members}" >> gitosis.conf
- echo "writable = ${repository}\n" >> gitosis.conf
- git commit -a -m 'Added repository ${repository}'
- git push origin master
- rm -rf ${git_dir}/tmp/${rand_dir}
- exit 0
Add Comment
Please, Sign In to add comment