Advertisement
Guest User

Untitled

a guest
Aug 1st, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2. key_name="id_gitosis"
  3. key_location="$HOME/.ssh"
  4. ssh_conf_dir="$HOME/.ssh"
  5. server="example.com"
  6.  
  7. echo "keyname '${key_name}'"
  8. echo "key location: '${key_location}'"
  9.  
  10. function must_accept
  11. {
  12.     question="${1} (y/abort)"
  13.     echo ${question}
  14.     read -r
  15.     ans=$REPLY #must save it or I can only use it once
  16.     until [ "$ans" = "y" ]; do
  17.         if [ "$ans" = "abort" ];then
  18.             echo "aborting as commanded..."
  19.             exit 1
  20.         fi
  21.         echo "valid answers: 'abort', 'y'"
  22.         echo ${question}
  23.         read -r
  24.         ans=$REPLY
  25.     done
  26. }
  27.  
  28. echo "Warning! Warning!"
  29. must_accept "Will overwrite *everything* in ${ssh_conf_dir}/config"
  30. (cat <<- :EOF:
  31.     Host icgit
  32.     HostName ${server}
  33.     User git
  34.     IdentityFile ${key_location}/${key_name}
  35.    
  36.     :EOF:
  37. ) > ${ssh_conf_dir}/config
  38.  
  39. echo "removing earlier keys"
  40. rm -rf ${key_location}/${key_name}
  41. rm -rf ${key_location}/${key_name}.pub
  42.  
  43. echo "[Generating Key]..."
  44. ssh-keygen -t rsa -f ${key_location}/${key_name} || exit
  45. echo "[Adding key to keyring]"
  46. ssh-add ${key_location}/${key_name}
  47.  
  48. echo "[Uploading key to server]"
  49. scp ${key_location}/${key_name}.pub root@${server}:/root/admin-acc-ssh-key.pub.$$ || exit
  50.  
  51. ssh root@${server} << *
  52.   apt-get remove -y --purge gitosis
  53.   rm -rf /srv/gitosis
  54.   userdel git
  55.   rm -rf /home/git
  56.   apt-get install -y gitosis
  57.   adduser --system --shell /bin/sh --gecos 'Git' --group --disabled-password --home /home/git git
  58.   sudo -H -u git gitosis-init < admin-acc-ssh-key.pub.$$
  59.   userdel gitosis
  60.   rm admin-acc-ssh-key.pub.$$
  61.   exit
  62. *
  63. echo "checking out admin repo - type ssh key password again plix"
  64. (
  65.     cd /tmp
  66.     rm -rf gitosis-admin
  67.     git clone git@${server}:gitosis-admin.git
  68. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement