Advertisement
Guest User

Untitled

a guest
May 3rd, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #!/bin/bash
  2. # This script is intended to aid in the initial configuration of a remote host to have the appropriate public key
  3. # and to have Python2.7 installed so that we can use Ansible on it.
  4.  
  5. read -p "Username: " username
  6. read -s -p "Sudo password: " password
  7. echo
  8. read -p "Host/IP: " host
  9. echo
  10.  
  11.  
  12. echo -e "\e[33m- Copying public key to remote host\e[0m"
  13. ssh-copy-id -i ~/.ssh/id_rsa.pub ${username}@${host} &>/dev/null
  14. echo
  15.  
  16. if [ $? -eq 0 ]
  17. then
  18. ssh -o PasswordAuthentication=no -q ${username}@${host} exit
  19. if [ $? -eq 0 ]
  20. then
  21. ssh ${username}@${host} "bash -s" << EOF
  22. echo -e "\e[33m- Testing credentials\e[0m";
  23. echo
  24. { echo ${password} | sudo -S echo "" &>/dev/null; } || { echo -e "\e[31m[FAILED]\e[0m Invalid sudo credentials." && exit 255; };
  25.  
  26. if [ $? -eq 0 ]; then
  27. echo -e "\e[33m- Updating APT\e[0m";
  28. echo ${password} | sudo -S apt-get update;
  29. echo
  30.  
  31. echo -e "\e[33m- Upgrading APT\e[0m";
  32. echo ${password} | sudo -S apt-get upgrade -y;
  33. echo
  34.  
  35. echo -e "\e[33m- Installing Python\e[0m";
  36. echo ${password} | sudo -S apt-get -y install python2.7 python-simplejson;
  37. echo
  38. fi
  39. EOF
  40. else echo -e "\e[31m[FAILED]\e[0m Failed to SSH to remote host."
  41. fi
  42. else echo -e "\e[31m[FAILED]\e[0m Failed to copy over the public key to the remote host."
  43. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement