50-hostname 660 B

123456789101112131415161718192021222324252627
  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. echo "> Hostname changed to $answer <"
  21. exit 0
  22. else
  23. # Exit with non zero status
  24. echo "### Could not change hostname ###"
  25. exit 1
  26. fi