igor@0: #!/bin/sh
igor@0: 
igor@0: bind_mounts () {
igor@0:   # set defaults
igor@0:   test -z "$tmpfs_dir" && tmpfs_dir=/var/lib/xenomips
igor@0:   test -z "$rw_dirs" \
igor@0:   && rw_dirs="/var/cache/man /var/lock /var/run /var/log /var/spool /var/tmp /tmp /var/lib/urandom /var/lib/dhcp3 /tmp"
igor@0:   test -z "$copy_dirs" && copy_dirs=""
igor@0:   test -z "$temp_copy_dirs" && temp_copy_dirs="/var/cache/debconf"
igor@0:   test -z "$bindfiles" && bindfiles=""
igor@0:   mount -t tmpfs -o mode=0755 tmpfs $tmpfs_dir
igor@0:   # preserve directory structure
igor@0:   for d in $rw_dirs ; do
igor@0:     if [ -d "$d" ]; then
igor@0:       cd $tmpfs_dir
igor@0:       tar --no-recursion -cpf - $(find $d -type d 2> /dev/null) 2> /dev/null | tar xpf -
igor@0:       mount --bind $tmpfs_dir/$d $d
igor@0:     else
igor@0:       echo "WARNING: $d does not exist"
igor@0:     fi
igor@0:   done  
igor@0:   # copy contents into tmpfs
igor@0:   for d in $copy_dirs $temp_copy_dirs; do
igor@0:     if [ -d "$d" ]; then
igor@0:       cd $tmpfs_dir
igor@0:       tar -cpf - $d 2> /dev/null | tar xpf -
igor@0:       mount --bind $tmpfs_dir/$d $d
igor@0:     else
igor@0:       echo "WARNING: $d does not exist"
igor@0:     fi
igor@0:   done
igor@0:   # mount one file on top of another
igor@0:   for f in $bindfiles ; do
igor@0:     if [ -e "$f" ]; then
igor@0:       mkdir -p "$(dirname $tmpfs_dir/$f)"
igor@0:       cp $f $tmpfs_dir/$f
igor@0:       mount --bind $tmpfs_dir/$f $f
igor@0:     else
igor@0:       echo "WARNING: $f does not exist"
igor@0:     fi
igor@0:   done
igor@0:   touch /var/log/dmesg
igor@0: }
igor@0: 
igor@43: unbind_mounts() {
igor@43: # FIXME
igor@43:     true
igor@43: }
igor@0: 
igor@43: case $1 in
igor@43:     start)
igor@43:         bind_mounts
igor@43:     ;;
igor@43:     stop)
igor@43:         unbind_mounts
igor@43:     ;;
igor@43: esac
igor@0: