Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # This script is intended to aid in the initial configuration of a remote host to have the appropriate public key
- # and to have Python2.7 installed so that we can use Ansible on it.
- read -p "Username: " username
- read -s -p "Sudo password: " password
- echo
- read -p "Host/IP: " host
- echo
- echo -e "\e[33m- Copying public key to remote host\e[0m"
- ssh-copy-id -i ~/.ssh/id_rsa.pub ${username}@${host} &>/dev/null
- echo
- if [ $? -eq 0 ]
- then
- ssh -o PasswordAuthentication=no -q ${username}@${host} exit
- if [ $? -eq 0 ]
- then
- ssh ${username}@${host} "bash -s" << EOF
- echo -e "\e[33m- Testing credentials\e[0m";
- echo
- { echo ${password} | sudo -S echo "" &>/dev/null; } || { echo -e "\e[31m[FAILED]\e[0m Invalid sudo credentials." && exit 255; };
- if [ $? -eq 0 ]; then
- echo -e "\e[33m- Updating APT\e[0m";
- echo ${password} | sudo -S apt-get update;
- echo
- echo -e "\e[33m- Upgrading APT\e[0m";
- echo ${password} | sudo -S apt-get upgrade -y;
- echo
- echo -e "\e[33m- Installing Python\e[0m";
- echo ${password} | sudo -S apt-get -y install python2.7 python-simplejson;
- echo
- fi
- EOF
- else echo -e "\e[31m[FAILED]\e[0m Failed to SSH to remote host."
- fi
- else echo -e "\e[31m[FAILED]\e[0m Failed to copy over the public key to the remote host."
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement