2 # Filename: prepare_tmpfs.sh
3 # Purpose: set up a tmpfs of a selected directory
4 # Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 ################################################################################
9 if [ $(id -u) != 0 ] ; then
10 echo "Error: $0 requires root permissions. Exiting."
17 echo "Usage: $0 <directory> <start|stop>"
20 if ! [ -n "$1" -a -n "$2" ] ; then
28 if ! mount | grep -q "tmpfs on ${DIRECTORY}" ; then
29 if [ -d $DIRECTORY ] ; then
30 if ! [ -d $DIRECTORY.tmpfile ] ; then
31 echo -n "Setting up tmpfs ${DIRECTORY}: "
32 mv $DIRECTORY/ $DIRECTORY.tmpfile && \
34 if mount $TMPFS -t tmpfs tmpfs $DIRECTORY ; then
35 cp -a $DIRECTORY.tmpfile/* $DIRECTORY &>/dev/null
36 cp -a $DIRECTORY.tmpfile/.* $DIRECTORY &>/dev/null
42 echo "Erorr: tmpdir $DIRECTORY.tmpfile exists already. Exiting."
46 echo "Error: $DIRECTORY does not exist. Exiting."
50 echo "Error: $DIRECTORY already mounted. Exiting."
56 if mount | grep -q $DIRECTORY ; then
57 echo -n "Unmounting tmpfs ${DIRECTORY}: "
58 umount ${DIRECTORY} && \
60 mv $DIRECTORY.tmpfile $DIRECTORY && echo done || echo failed
62 echo "Error: ${DIRECTORY} not mounted."
69 prepare_start || exit 1
72 prepare_stop || exit 1
81 ## END OF FILE #################################################################