6 # =====================================================================
8 # Copyright (C) 2006, 2007 by Keith Marshall
9 # mailto:keithmarshall@users.sourceforge.net
11 # This file is part of MSYS
12 # http://www.mingw.org/msys.shtml
14 # MSYS is free software. It is provided "as is", in the hope that it
15 # may be useful; there is NO WARRANTY OF ANY KIND, not even an implied
16 # warranty of MERCHANTABILITY or FITNESS FOR ANY PARTICULAR PURPOSE.
17 # At no time will the author accept liability for damages, however
18 # caused, resulting from the use of this software.
20 # Permission is granted to copy and redistribute this software, either
21 # as is, or in modified form, provided that:--
23 # 1) All such copies are distributed with the same rights
26 # 2) The preceding disclaimer of warranty and liabality is
27 # retained verbatim, in all copies.
29 # 3) Accreditation of the original author remains in place.
31 # 4) Modified copies are clearly identified as such, with
32 # additional accreditation given to the authors of each
35 # =====================================================================
37 # Exactly one argument is required...
42 # Normally, it specifies the mount point to be released,
43 # but it may also represent a mounted directory path name,
44 # for which all bound mount points are to be filtered out
45 # of the "mount table" file.
47 MNTPATH=`echo "$1" | tr '\\\\' /`
48 TMPFILE=${TMPDIR-"/tmp"}/mnttab$$.tmp
49 MNTTAB=${MNTTAB-"/etc/fstab"}
51 if cat "$MNTTAB" | tr '\\' / | awk '
53 # Copy the "mount table" to a temporary file, filtering
54 # out all active mount point records which match MNTPATH,
55 # (the specified argument); set exit status to:--
56 # 0: if at least one mount point is matched;
57 # 1: if no match is found.
61 /^#/ { print; keep = "no"; $0 = "!'$MNTPATH'" }
62 $2 == "'$MNTPATH'" { keep = "no"; status = 0 }
63 { $2 = "!" } $0 == "'$MNTPATH' !" { keep = "no"; status = 0 }
64 keep != "no" { print keep }
65 END { exit status }' > "$TMPFILE"
68 # At least one mount point was selected to release...
69 # Replace the active "mount table" file with the regenerated
70 # copy, so completing the operation.
72 cp "$TMPFILE" "$MNTTAB"
77 # No active mount point matched the specified argument...
78 # Discard the temporary file, complain, and bail out.
81 echo >&2 "$0: '$1' is not mounted"
87 # The command line did not specify exactly one argument...
88 # Complain, and bail out.
90 echo >&2 "$0: incorrect number of arguments"
91 echo >&2 "usage: umount <path>"
95 # On successful completion, ensure we set the exit status appropriately.
99 # $RCSfile$: end of file