Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- key_name="id_gitosis"
- key_location="$HOME/.ssh"
- ssh_conf_dir="$HOME/.ssh"
- server="example.com"
- echo "keyname '${key_name}'"
- echo "key location: '${key_location}'"
- function must_accept
- {
- question="${1} (y/abort)"
- echo ${question}
- read -r
- ans=$REPLY #must save it or I can only use it once
- until [ "$ans" = "y" ]; do
- if [ "$ans" = "abort" ];then
- echo "aborting as commanded..."
- exit 1
- fi
- echo "valid answers: 'abort', 'y'"
- echo ${question}
- read -r
- ans=$REPLY
- done
- }
- echo "Warning! Warning!"
- must_accept "Will overwrite *everything* in ${ssh_conf_dir}/config"
- (cat <<- :EOF:
- Host icgit
- HostName ${server}
- User git
- IdentityFile ${key_location}/${key_name}
- :EOF:
- ) > ${ssh_conf_dir}/config
- echo "removing earlier keys"
- rm -rf ${key_location}/${key_name}
- rm -rf ${key_location}/${key_name}.pub
- echo "[Generating Key]..."
- ssh-keygen -t rsa -f ${key_location}/${key_name} || exit
- echo "[Adding key to keyring]"
- ssh-add ${key_location}/${key_name}
- echo "[Uploading key to server]"
- scp ${key_location}/${key_name}.pub root@${server}:/root/admin-acc-ssh-key.pub.$$ || exit
- ssh root@${server} << *
- apt-get remove -y --purge gitosis
- rm -rf /srv/gitosis
- userdel git
- rm -rf /home/git
- apt-get install -y gitosis
- adduser --system --shell /bin/sh --gecos 'Git' --group --disabled-password --home /home/git git
- sudo -H -u git gitosis-init < admin-acc-ssh-key.pub.$$
- userdel gitosis
- rm admin-acc-ssh-key.pub.$$
- exit
- *
- echo "checking out admin repo - type ssh key password again plix"
- (
- cd /tmp
- rm -rf gitosis-admin
- git clone git@${server}:gitosis-admin.git
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement