summaryrefslogtreecommitdiff
path: root/addons/x11infoscreen/etc/init.d/flashybrid
blob: 5ab4037d5c0bd23acddabf7852551dcca6802e85 (plain)
  1. #!/bin/sh
  2. # Set up/shutdown the flashybrid system, including the ramdisk and partial
  3. # directory bind mounts. This needs to run at the part of system bootup that
  4. # mounts all the disks. It should also run at shutdown right before
  5. # filesystems are unmounted.
  6. CONFDIR=/etc/flashybrid
  7. if [ -e $CONFDIR/config ]; then
  8. . $CONFDIR/config
  9. fi
  10. ENABLED=no
  11. if [ -e /etc/default/flashybrid ]; then
  12. . /etc/default/flashybrid
  13. fi
  14. if [ -z "$RAMMOUNT" ]; then
  15. exit 0
  16. fi
  17. is_mounted () {
  18. grep -q " $1 " /proc/mounts
  19. }
  20. case "$1" in
  21. start)
  22. if [ "$ENABLED" != yes ]; then
  23. echo "Not setting up flashybrid system: disabled."
  24. exit
  25. fi
  26. printf "Setting up flashybrid system..."
  27. # Set up partial directories and so on, make sure disk is
  28. # unmounted.
  29. fh-embed >/dev/null
  30. # Set up ram disk to hold variable data.
  31. if ! is_mounted $RAMMOUNT; then
  32. mount tmpfs -t tmpfs $RAMMOUNT
  33. fi
  34. # Temporary directories on ram disk.
  35. for dir in $(grep -v '^#' $CONFDIR/ramtmp); do
  36. mkdir -p -m 1777 $RAMMOUNT/$dir
  37. if is_mounted $dir; then
  38. umount $dir
  39. fi
  40. mount --bind $RAMMOUNT/$dir $dir
  41. done
  42. # Copy data from flash to ram disk for these directories.
  43. for dir in $(grep -v '^#' $CONFDIR/ramstore); do
  44. # Skip dirs that are not present.
  45. if [ -d $dir ]; then
  46. ramdir=$RAMMOUNT$dir
  47. if is_mounted $dir; then
  48. umount $dir
  49. fi
  50. if is_mounted $ramdir.flash; then
  51. umount $ramdir.flash
  52. fi
  53. if [ ! -d $ramdir ]; then
  54. mkdir -p ${ramdir%/*} # dirname
  55. cp -a $dir $ramdir
  56. fi
  57. mkdir -p $ramdir.flash
  58. mount --bind $dir $ramdir.flash
  59. mount --bind $ramdir $dir
  60. fi
  61. done
  62. # Make sure virtual filesystems are properly mounted
  63. invoke-rc.d mountvirtfs start || /bin/true
  64. echo "done."
  65. ;;
  66. stop)
  67. if [ "$ENABLED" != yes ]; then
  68. echo "Not shutting down flashybrid system: disabled."
  69. exit
  70. fi
  71. printf "Shutting down flashybrid system..."
  72. # Copy data to flash.
  73. # Remount the flash read-write so the copies to it will work.
  74. mount -o remount,rw /
  75. for dir in $(grep -v '^#' $CONFDIR/ramstore); do
  76. if [ -d $RAMMOUNT/$dir ] && [ -d $RAMMOUNT/$dir.flash ]; then
  77. # rsync is used to avoid churning the flash
  78. # unnecessarily. The trailing slashes are very
  79. # important..
  80. rsync --delete -a $RAMMOUNT/$dir/ $RAMMOUNT/$dir.flash/
  81. fi
  82. done
  83. for dir in $(grep -v '^#' $CONFDIR/ramtmp); do
  84. if is_mounted $dir; then
  85. umount $dir
  86. fi
  87. done
  88. for dir in $(grep -v '^#' $CONFDIR/ramstore); do
  89. ramdir=$RAMMOUNT$dir
  90. if is_mounted $ramdir.flash; then
  91. umount $ramdir.flash
  92. fi
  93. if is_mounted $dir; then
  94. umount $dir
  95. fi
  96. done
  97. if is_mounted $RAMMOUNT; then
  98. umount $RAMMOUNT
  99. fi
  100. echo "done."
  101. ;;
  102. restart|force-reload)
  103. $0 stop
  104. $0 start
  105. ;;
  106. *)
  107. echo "Usage: $0 {start|stop|restart|force-reload}"
  108. exit 1
  109. ;;
  110. esac