bt-audio: check for presence of snd-bt-sco
[grml-scripts.git] / usr_sbin / prepare_tmpfs.sh
1 #!/bin/zsh
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 # Latest change: Sam Okt 06 13:23:59 CEST 2007 [mika]
8 ################################################################################
9
10 if [ $UID != 0 ]; then
11   echo "Error: $0 requires root permissions. Exiting."
12   exit 1
13 fi
14
15 setopt nonomatch
16
17 usage(){
18   echo "Usage: $0 <directory> <start|stop>"
19 }
20
21 if ! [ -n "$1" -a -n "$2" ] ; then
22   usage
23   exit 1
24 fi
25
26 DIRECTORY="$1"
27
28 prepare_start () {
29   if ! mount | grep -q "tmpfs on ${DIRECTORY}" ; then
30    if [ -d $DIRECTORY ] ; then
31     if ! [ -d $DIRECTORY.tmpfile ] ; then
32      echo -n "Setting up tmpfs ${DIRECTORY}: "
33      mv $DIRECTORY/ $DIRECTORY.tmpfile && \
34      mkdir $DIRECTORY && \
35      if mount $TMPFS -t tmpfs tmpfs $DIRECTORY ; then
36        cp -a $DIRECTORY.tmpfile/*  $DIRECTORY  &>/dev/null
37        cp -a $DIRECTORY.tmpfile/.* $DIRECTORY  &>/dev/null
38        echo done
39      else
40        echo failed
41      fi
42     else
43      echo "Erorr: tmpdir $DIRECTORY.tmpfile exists already. Exiting."
44      exit 1
45     fi
46    else
47     echo "Error: $DIRECTORY does not exist. Exiting."
48     exit 1
49    fi
50   else
51     echo "Error: $DIRECTORY already mounted. Exiting."
52     exit 1
53   fi
54 }
55
56 prepare_stop () {
57   if mount | grep -q $DIRECTORY ; then
58     echo -n "Unmounting tmpfs ${DIRECTORY}: "
59     umount ${DIRECTORY} && \
60     rmdir $DIRECTORY && \
61     mv $DIRECTORY.tmpfile $DIRECTORY && echo done || echo failed
62   else
63     echo "Error: ${DIRECTORY} not mounted."
64     exit 1
65   fi
66 }
67
68 case "$2" in
69   start)
70      prepare_start || exit 1
71      ;;
72   stop)
73      prepare_stop || exit 1
74      ;;
75   *)
76      usage
77      exit 1
78 esac
79
80 exit 0
81
82 ## END OF FILE #################################################################