Guest User

Untitled

a guest
Apr 19th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #!/bin/bash
  2. # usage:
  3. # git_import.sh init
  4. # git_import.sh addkey mygitkey
  5. #
  6. # cd git/your-project
  7. # git_import.sh
  8.  
  9. user=[your user]
  10. host=[your host]
  11.  
  12. # git remote name
  13. remote_name=home
  14.  
  15. # git user home (for adding ssh keys and initilizing)
  16. remote_home=/home/git
  17.  
  18. # git repository parent path
  19. remote_git_parent_path=/git
  20.  
  21. pwd_=`pwd`
  22. name=`basename $pwd_`
  23.  
  24. # ===============
  25. remote_bin=create-git-repo
  26.  
  27. # ===============
  28. if [[ "$1" == "addkey" ]] ; then
  29. if [[ -z $2 ]] ; then
  30. echo "please specify key name"
  31. exit
  32. fi
  33. keyname=$2
  34. ssh-keygen -t dsa -f $keyname
  35. scp $keyname.pub $user@$host:$keyname.pub
  36. ssh $user@$host "sudo sh -c 'cat $keyname.pub >> $remote_home/.ssh/authorized_keys' "
  37. echo SSH Key Added
  38.  
  39. elif [[ "$1" == "init" ]] ; then
  40. cat <<END > /tmp/init.sh
  41. #!/bin/bash
  42. name=\$1
  43.  
  44. cd $remote_git_parent_path
  45. if [[ -e \$name.git ]] ; then
  46. echo "Repository Exist"
  47. exit
  48. fi
  49. sudo -u git mkdir \$name.git
  50. cd \$name.git
  51. sudo git init --bare
  52. cd ..
  53. sudo chown -R git: \$name.git
  54. sudo chmod -R g+rw \$name.git
  55. END
  56. # create git user
  57. ssh $user@$host 'sudo useradd -m -s `which git-shell` git ;' \
  58. "sudo mkdir $remote_git_parent_path "\
  59. "sudo chown -R git:git $remote_git_parent_path"\
  60. "sudo -u git mkdir $remote_home/.ssh"\
  61. "sudo -u git chmod 700 $remote_home/.ssh"\
  62. "sudo -u git chmod 600 $remote_home/.ssh/authorized_keys"
  63.  
  64. scp /tmp/init.sh $user@$host:$remote_bin
  65. rm /tmp/init.sh
  66. echo Done
  67. exit
  68. fi
  69.  
  70.  
  71. echo "Creating Repository"
  72. ssh $user@$host "bash $remote_bin $name"
  73.  
  74. echo "Adding Remote"
  75. git remote add $remote_name git@$host:$remote_git_parent_path/$name.git
  76. git checkout master
  77.  
  78. echo "Pushing to Remote"
  79. git push $remote_name master
  80. echo Done
Add Comment
Please, Sign In to add comment