Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # usage:
- # git_import.sh init
- # git_import.sh addkey mygitkey
- #
- # cd git/your-project
- # git_import.sh
- user=[your user]
- host=[your host]
- # git remote name
- remote_name=home
- # git user home (for adding ssh keys and initilizing)
- remote_home=/home/git
- # git repository parent path
- remote_git_parent_path=/git
- pwd_=`pwd`
- name=`basename $pwd_`
- # ===============
- remote_bin=create-git-repo
- # ===============
- if [[ "$1" == "addkey" ]] ; then
- if [[ -z $2 ]] ; then
- echo "please specify key name"
- exit
- fi
- keyname=$2
- ssh-keygen -t dsa -f $keyname
- scp $keyname.pub $user@$host:$keyname.pub
- ssh $user@$host "sudo sh -c 'cat $keyname.pub >> $remote_home/.ssh/authorized_keys' "
- echo SSH Key Added
- elif [[ "$1" == "init" ]] ; then
- cat <<END > /tmp/init.sh
- #!/bin/bash
- name=\$1
- cd $remote_git_parent_path
- if [[ -e \$name.git ]] ; then
- echo "Repository Exist"
- exit
- fi
- sudo -u git mkdir \$name.git
- cd \$name.git
- sudo git init --bare
- cd ..
- sudo chown -R git: \$name.git
- sudo chmod -R g+rw \$name.git
- END
- # create git user
- ssh $user@$host 'sudo useradd -m -s `which git-shell` git ;' \
- "sudo mkdir $remote_git_parent_path "\
- "sudo chown -R git:git $remote_git_parent_path"\
- "sudo -u git mkdir $remote_home/.ssh"\
- "sudo -u git chmod 700 $remote_home/.ssh"\
- "sudo -u git chmod 600 $remote_home/.ssh/authorized_keys"
- scp /tmp/init.sh $user@$host:$remote_bin
- rm /tmp/init.sh
- echo Done
- exit
- fi
- echo "Creating Repository"
- ssh $user@$host "bash $remote_bin $name"
- echo "Adding Remote"
- git remote add $remote_name git@$host:$remote_git_parent_path/$name.git
- git checkout master
- echo "Pushing to Remote"
- git push $remote_name master
- echo Done
Add Comment
Please, Sign In to add comment