Guest User

Untitled

a guest
Jan 19th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.16 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. git_user="git"
  4. git_dir="/var/git"
  5.  
  6. if [ -z $1 ] || [ -z $2 ]
  7. then
  8.     echo "$0 <repository name> <members>..."
  9.     exit 1
  10. fi
  11.  
  12. if [ -d '${git_dir}/${1}.git' ]
  13. then
  14.     echo "Repository already exists."
  15.     exit 2
  16. fi
  17.  
  18. if [ ! -d ${git_dir} ]
  19. then
  20.     echo "Git directory dosn't exist"
  21.     exit 3
  22. fi
  23.  
  24. length=$(($#-1))
  25. members=${@:2:$length}
  26. repository=$1
  27.  
  28. mkdir ${git_dir}/${repository}.git
  29. cd ${git_dir}/${repository}.git
  30. git init
  31. touch .gitignore
  32. git add .gitignore
  33. git commit -a -m "Initial commit."
  34. git remote add origin ${git_user}@localhost:${repository}.git
  35. git push origin master:refs/heads/master
  36.  
  37. # add users to gitosis.conf
  38. rand_dir=`</dev/urandom tr -dc A-Za-z0-9 | head -c8`
  39. mkdir ${git_dir}/tmp/ 2> /dev/null
  40. mkdir ${git_dir}/tmp/${rand_dir} 2> /dev/null
  41. cd ${git_dir}/tmp/${rand_dir}
  42.  
  43. git clone ${git_user}@localhost:gitosis-admin.git .
  44. touch gitosis.conf
  45. echo "[group ${repository}]" >> gitosis.conf
  46. echo "members = ${members}" >> gitosis.conf
  47. echo "writable = ${repository}\n" >> gitosis.conf
  48. git commit -a -m 'Added repository ${repository}'
  49. git push origin master
  50.  
  51. rm -rf ${git_dir}/tmp/${rand_dir}
  52.  
  53. exit 0
Add Comment
Please, Sign In to add comment