#!/bin/sh

if [ "$1" = "stop" ]
then
  echo Unmounting filesystems
  umount -a -r
  mount -o remount -r %root% /
fi

if [ "$1" = "start" ]
then
  # Save /run context
  mkdir -p /boot_tmpdir/run
  mv /run/* /boot_tmpdir/run/

  if [ ! -e /etc/mtab ]
  then
      ln -s /proc/mounts /etc/mtab
  fi
  # Be sure directories exist
  for dir in `awk '!/^(#)/ {print $2}' /etc/fstab`
  do
    [ -d "${dir}" ] || mkdir -p "${dir}"
  done
  mount -a

  # Restore /run context
  mv /boot_tmpdir/run/* /run/

  rm -rf /boot_tmpdir
  # To enable lighttpd to start
  chmod 777 -R /var/log
fi
