Mercurial > hg > aboriginal
annotate more/zapchroot.sh @ 1299:dcf7da6a6633
Add the sha1sum to the LFS tarball.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 22 Nov 2010 17:31:51 -0600 |
parents | 720b109bc978 |
children | ffdc94c67308 |
rev | line source |
---|---|
1278
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1 #!/bin/bash |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 # Copyright 2010 Rob Landley <rob@landley.net> licensed under GPLv2 |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 if [ "$1" == "-d" ] |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 then |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 DELETE=1 |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
8 shift |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
9 fi |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
10 |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
11 # Clean up a chroot directory |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
13 ZAP=$(readlink -f "$1" 2>/dev/null) |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 if [ ! -d "$ZAP" ] |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
16 then |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 echo "usage: zapchroot [-d] dirname" |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
18 exit 1 |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 fi |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
20 |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
21 i="$(readlink -f "$(pwd)")" |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
22 if [ "$ZAP" == "${i:0:${#ZAP}}" ] |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
23 then |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
24 echo "Sanity check failed: cwd is under zapdir" >&2 |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 exit 1 |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 fi |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
28 # Iterate through the second entry of /proc/mounts in reverse order |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
29 |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
30 for i in $(awk '{print $2}' /proc/mounts | tac) |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
31 do |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
32 # De-escape octal versions of space, tab, backslash, newline... |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
33 i=$(echo -e "$i") |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
34 |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
35 # Skip entries that aren't under our chroot |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
36 [ "$ZAP" != "${i:0:${#ZAP}}" ] && continue |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
37 |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
38 echo "Umounting: $i" |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
39 umount "$i" |
a542c58a4c8e
Add zapchroot script that unmounts everything under a directory.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
40 done |