firstrun 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. case "$1" in
  20. start)
  21. reboot=false
  22. echo ""
  23. rm -f /etc/ssh/ssh_host*
  24. dpkg-reconfigure openssh-server
  25. set +e
  26. echo "Expanding rootfs..."
  27. device="/dev/mmcblk0"
  28. ((echo d; echo n; echo p; echo 1; echo ; echo; echo w;) | fdisk $device)>/dev/null
  29. if [ $? -eq 0 ] ;then
  30. echo "Expanding rootfs success, rebooting automatically."
  31. /sbin/resize2fs /dev/mmcblk0p1 2>/dev/null
  32. reboot=true
  33. else
  34. echo "Expanding rootfs has failed, see log files."
  35. fi
  36. depmod -a
  37. /sbin/insserv -r firstrun
  38. if $reboot;then
  39. /sbin/reboot
  40. fi
  41. ;;
  42. *)
  43. echo "Usage: $N {start}" >&2
  44. exit 1
  45. ;;
  46. esac
  47. exit 0