50-hostname 521 B

12345678910111213141516171819202122232425
  1. #!/bin/bash
  2. # Licence : GPL v3
  3. # Author: Laurent HUBERT
  4. #
  5. # Changes the machine hostname
  6. #
  7. cat <<EOF
  8. ##############################
  9. # Changing hostname #
  10. ##############################
  11. EOF
  12. read -p "Please enter new hostname: " answer
  13. if [ -n "$answer" ]
  14. then
  15. echo Changing hostname to $answer
  16. current=$(hostname)
  17. sed -i.firstboot.backup s/$current/$answer/g /etc/hostname
  18. sed -i.firstboot.backup s/$current/$answer/g /etc/hosts
  19. hostname $answer
  20. exit 0
  21. else
  22. # Exit with non zero status
  23. exit 1
  24. fi