first-boot-script 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. # Licence : GPL v3
  3. # Author: Laurent HUBERT
  4. #
  5. # Executes each script from scripts dir if they are executable
  6. FIRST_BOOT_BASE_DIR=/etc/first-boot
  7. FIRST_BOOT_SCRIPTS_DIR=$FIRST_BOOT_BASE_DIR/scripts
  8. if [ ! -r /etc/first-boot/.mustrun ]
  9. then
  10. exit 0
  11. fi
  12. cat <<EOF
  13. ###############################################
  14. # FIRST BOOT INITIALIZATION SCRIPT #
  15. ###############################################
  16. EOF
  17. if [[ $EUID -ne 0 ]]; then
  18. echo "This script cannot work if not super-user. Please run as root" 1>&2
  19. exit 1
  20. fi
  21. for f in $(ls $FIRST_BOOT_SCRIPTS_DIR/*)
  22. do
  23. if [ -x $f ] ; then
  24. $f $FIRST_BOOT_BASE_DIR
  25. status=$?
  26. if [ 0 -ne "$status" ] ; then
  27. echo "#ERROR# : script $f did not finish with success status !"
  28. cat <<EOF
  29. ###############################################
  30. ###############################################
  31. # FIRST BOOT INITIALIZATION : ERROR #
  32. # Please reboot your system #
  33. ###############################################
  34. ###############################################
  35. EOF
  36. exit $status
  37. fi
  38. fi
  39. done
  40. rm $FIRST_BOOT_BASE_DIR/.mustrun
  41. systemctl disable first-boot-init.service
  42. cat <<EOF
  43. ###############################################
  44. # FIRST BOOT INITIALIZATION : success #
  45. ###############################################
  46. EOF
  47. # Starts tty1 after that script is finished
  48. systemctl start getty@tty1.service
  49. exit 0