50-hostname 697 B

1234567891011121314151617181920212223242526272829
  1. #!/bin/bash
  2. # Licence : GPL v3
  3. # Author: Laurent HUBERT
  4. #
  5. # Example file for first-boot-script
  6. # Copy this file to a new file and add permission execution to the new file
  7. # Example:
  8. # # cp skeleton 02-myscript
  9. # # chmod +x 02-myscript
  10. #
  11. cat <<EOF
  12. ##############################
  13. # Changing hostname #
  14. ##############################
  15. EOF
  16. # Example Section : asking user to enter a value
  17. read -p "Please enter new hostname: " answer
  18. if [ -n "$answer" ]
  19. then
  20. echo Changing hostname to $answer
  21. current=$(hostname)
  22. sed -i.firstboot.backup s/$current/$answer/g /etc/hostname
  23. sed -i.firstboot.backup s/$current/$answer/g /etc/hosts
  24. exit 0
  25. else
  26. # Exit with non zero status
  27. exit 1
  28. fi