Advertisement
jalvani

updatehosts.sh

Apr 5th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.57 KB | None | 0 0
  1. #! /bin/bash
  2. # Script downloads the currently-available hosts file from OurHouse, compares MD5 of the
  3. # downloaded file to the MD5 of the current file. If they do not match, it replaces the
  4. # currently installed file with the downloaded file.
  5.  
  6. # Checks to see how many (if any) arguments were passed. If two arguments were passed,
  7. # it interprets the first as a username, and the second as a password. If only one was
  8. # passed, it uses the currently logged in user's username, and interprets the passed
  9. # argument as a password. If none are passed, it uses the currently logged in username,
  10. # and prompts for password.
  11.  
  12. if [ "$1" != '' ] && [ "$2" != '' ]; then
  13.     user_name=$1
  14.     user_password=$2
  15. elif [ "$1" != '' ] && [ "$2" == '' ]; then
  16.     user_name=$USER
  17.     user_password=$1
  18. else
  19.     user_name=$USER
  20.     read -s -p "Password: " user_password
  21. fi 
  22. echo -e "\n\n"
  23.  
  24.  
  25. # cURLs hosts file from OurHouse
  26. cd $TMPDIR
  27. echo
  28. echo -e `curl -O --ntlm -u 'example.com\'$user_name':'$user_password http://sharepoint.example.com/path/to/hosts/file/hosts.txt`
  29. dl_md5=`md5 -q hosts.txt`
  30. inst_md5=`md5 -q /etc/hosts`
  31.  
  32. echo -e "\n\nFile on Server Checksum:   "$dl_md5
  33. echo -e "File on Localhost Checksum:    "$inst_md5 "\n"
  34.  
  35. if [ "$dl_md5" == "$inst_md5" ]; then  
  36.     response="is current. No need to update."
  37.     echo -e  "/etc/hosts "$response " \n"
  38.     growlnotify -n /etc/hosts -m  " " $response
  39. else
  40.     response="has been updated."
  41.     sudo cp hosts.txt /etc/hosts
  42.     echo -e  "/etc/hosts "$response " \n"
  43.     growlnotify -n /etc/hosts -m  " " $response
  44. fi
  45.  
  46. # Deletes the downloaded file
  47. rm hosts.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement