-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchroot.sh
More file actions
61 lines (56 loc) · 1.45 KB
/
Copy pathchroot.sh
File metadata and controls
61 lines (56 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
mount=false
unmount=false
version=alpha_0.0.1
usage ()
{
echo "This thing assumes you've already mounted your root"
echo "under the /mnt mountpoint. If this is not the case"
echo "then it won't work. You can mount bind the directories"
echo "you need with: bash chroot.sh --mount"
echo "and then chroot with: sudo chroot /mnt"
echo "then after exiting the chroot you can unmount with:"
echo "bash chroot.sh --unmount"
echo "Finally unmount your /mnt manually"
exit 0
}
for option in "$@"; do
case "$option" in
-h | --help)
usage
exit 0 ;;
--version)
echo "$0: Version $version"
exit 0 ;;
--mount)
mount=true ;;
--unmount)
unmount=true ;;
-*)
echo "$0: Unrecognized option '$option'. (--help for usage instructions)"
exit 1
;;
*)
echo "$0: Unrecognized argument '$option'. (--help for usage instructions)"
exit 1
;;
esac
done
if [ "$mount" == "true" ] && [ "$unmount" == "true" ]; then
echo "Error: can't mount and unmount at the same time."
echo ""
usage
exit 1
fi
if [ "$mount" == "false" ] && [ "$unmount" == "false" ]; then
echo "Error: need to choose either --mount or --unmount"
echo ""
usage
exit 1
fi
if [ "$mount" == "true" ]; then
for i in dev proc sys dev/pts run; do sudo mount --bind /$i /mnt/$i ; done
fi
if [ "$unmount" == "true" ]; then
for i in run dev/pts dev proc sys;do sudo umount /mnt/$i; done
fi