firstrun 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. ### BEGIN INIT INFO
  3. # Provides: firstrun
  4. # Required-Start: $all
  5. # Required-Stop:
  6. # Should-Start:
  7. # Default-Start: 2 3 4 5
  8. # Default-Stop: 0 1 6
  9. # Short-Description: Script to run when first starting
  10. # Description: Something needs to be done when is
  11. # starting at first time.
  12. # regenerate ssh host key
  13. # expanding root partition
  14. # run depmod
  15. ### END INIT INFO
  16. # script from https://github.com/igorpecovnik/lib
  17. # modified by https://github.com/bleuchtang/sunxi-debian
  18. N=/etc/init.d/firstrun
  19. case "$1" in
  20. start)
  21. echo ""
  22. echo "##########################################"
  23. echo "## FIRSTRUN INIT SCRIPT ##"
  24. echo "## WAIT SOME MINUTES FOR CONFIGURATIONS ##"
  25. echo "##########################################"
  26. echo ""
  27. echo "######################"
  28. echo "# ssh key generation #"
  29. echo "######################"
  30. echo ""
  31. rm -f /etc/ssh/ssh_host*
  32. dpkg-reconfigure openssh-server
  33. # do not resize if root is crypted
  34. /sbin/insserv -r firstrun
  35. if [ ! -e /etc/crypttab ]; then
  36. echo ""
  37. echo "############################"
  38. echo "# Expanding root partition #"
  39. echo "############################"
  40. (echo d; echo n; echo p; echo 1; echo ; echo; echo w) | fdisk /dev/mmcblk0
  41. /sbin/insserv secondrun
  42. echo ""
  43. echo "##################"
  44. echo "# Reboot #"
  45. echo "##################"
  46. echo ""
  47. /sbin/reboot
  48. fi
  49. ;;
  50. *)
  51. echo "Usage: $N {start}" >&2
  52. exit 1
  53. ;;
  54. esac
  55. exit 0