firstrun 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. # run depmod
  14. ### END INIT INFO
  15. # script from https://github.com/igorpecovnik/lib
  16. # modified by https://github.com/bleuchtang/sunxi-debian
  17. N=/etc/init.d/firstrun
  18. set -e
  19. echo ""
  20. echo "##########################################"
  21. echo "## FIRSTRUN SCRIPT ##"
  22. echo "## WAIT SOME MINUTES FOR CONFIGURATIONS ##"
  23. echo "##########################################"
  24. echo ""
  25. case "$1" in
  26. start)
  27. reboot=false
  28. echo ""
  29. echo "######################"
  30. echo "# ssh key generation #"
  31. echo "######################"
  32. echo ""
  33. rm -f /etc/ssh/ssh_host*
  34. dpkg-reconfigure openssh-server
  35. set +e
  36. echo ""
  37. echo "####################"
  38. echo "# Expanding rootfs #"
  39. echo "####################"
  40. echo ""
  41. device="/dev/mmcblk0"
  42. ((echo d; echo n; echo p; echo 1; echo ; echo; echo w;) | fdisk $device)
  43. if [ $? -eq 0 ] ;then
  44. echo "Expanding rootfs success, rebooting automatically."
  45. /sbin/resize2fs /dev/mmcblk0p1 2>/dev/null
  46. reboot=true
  47. else
  48. echo "Expanding rootfs has failed, see log files."
  49. fi
  50. depmod -a
  51. /sbin/insserv -r firstrun
  52. if $reboot;then
  53. /sbin/reboot
  54. fi
  55. ;;
  56. *)
  57. echo "Usage: $N {start}" >&2
  58. exit 1
  59. ;;
  60. esac
  61. exit 0