first-boot-script 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. echo Executing $f $FIRST_BOOT_BASE_DIR
  25. $f $FIRST_BOOT_BASE_DIR
  26. status=$?
  27. if [ 0 -ne "$status" ] ; then
  28. echo "#ERROR# : script $f did not finish with success status !"
  29. cat <<EOF
  30. ###############################################
  31. ###############################################
  32. # FIRST BOOT INITIALIZATION : ERROR #
  33. # Please reboot your system #
  34. ###############################################
  35. ###############################################
  36. EOF
  37. exit $status
  38. fi
  39. fi
  40. done
  41. rm $FIRST_BOOT_BASE_DIR/.mustrun
  42. systemctl disable first-boot-init.service
  43. cat <<EOF
  44. ###############################################
  45. # FIRST BOOT INITIALIZATION : success #
  46. ###############################################
  47. EOF
  48. exit 0