remove mounts automatically
Also combined all these little mount and cleanup helpers into one `cleanup` script with flags.
This commit is contained in:
+90
@@ -0,0 +1,90 @@
|
||||
#!/bin/sh
|
||||
|
||||
if test `id -u` -ne 0
|
||||
then
|
||||
echo "$0 must be run as root."
|
||||
return
|
||||
fi
|
||||
|
||||
FRESH=clean_environment
|
||||
ROOT=test_environment
|
||||
|
||||
add_mount() {
|
||||
if mountpoint "$ROOT$1" > /dev/null
|
||||
then
|
||||
echo "$ROOT$1 already mounted."
|
||||
else
|
||||
echo "Mounting $1 to $ROOT$1"
|
||||
mkdir -p "$ROOT$1"
|
||||
mount -o bind "$1" "$ROOT$1"
|
||||
fi
|
||||
}
|
||||
|
||||
remove_mount() {
|
||||
if mountpoint "$ROOT$1" > /dev/null
|
||||
then
|
||||
echo "Unmounting $ROOT$1"
|
||||
umount "$ROOT$1"
|
||||
fi
|
||||
}
|
||||
|
||||
add_mounts() {
|
||||
add_mount /proc
|
||||
add_mount /sys
|
||||
add_mount /dev
|
||||
add_mount /dev/pts
|
||||
}
|
||||
|
||||
remove_mounts() {
|
||||
remove_mount /dev/pts
|
||||
remove_mount /dev
|
||||
remove_mount /sys
|
||||
remove_mount /proc
|
||||
}
|
||||
|
||||
remove_environment() {
|
||||
if test -d "$ROOT"
|
||||
then
|
||||
# Call this script that automatically unmounts the mount points too.
|
||||
remove_mounts
|
||||
echo "Removing $ROOT"
|
||||
rm -r "$ROOT"
|
||||
else
|
||||
echo "No environment found at $ROOT. Doing nothing."
|
||||
fi
|
||||
}
|
||||
|
||||
remove_everything() {
|
||||
if test -d "$ROOT"
|
||||
then
|
||||
# Call this script that automatically unmounts the mount points too.
|
||||
remove_environment
|
||||
fi
|
||||
|
||||
if test -d "$FRESH"
|
||||
then
|
||||
echo "Removing $FRESH"
|
||||
rm -r "$FRESH"
|
||||
fi
|
||||
|
||||
if test -d debootstrap
|
||||
then
|
||||
echo "Removing debootstrap"
|
||||
rm -r debootstrap
|
||||
fi
|
||||
|
||||
if test -f debootstrap.tar.gz
|
||||
then
|
||||
echo "Removing debootstrap.tar.gz"
|
||||
rm debootstrap.tar.gz
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
everything) remove_everything ;;
|
||||
mounts) remove_mounts ;;
|
||||
add_mounts) add_mounts ;;
|
||||
environment) remove_environment ;;
|
||||
"") remove_environment ;;
|
||||
esac
|
||||
|
||||
Vendored
-32
@@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
if test `id -u` -ne 0
|
||||
then
|
||||
echo "$0 must be run as root."
|
||||
return
|
||||
fi
|
||||
|
||||
if test -d test_environment
|
||||
then
|
||||
# Call this script that automatically unmounts the mount points too.
|
||||
./destroy_environment
|
||||
fi
|
||||
|
||||
if test -d clean_environment
|
||||
then
|
||||
echo "Removing clean_environment"
|
||||
rm -r clean_environment
|
||||
fi
|
||||
|
||||
if test -d debootstrap
|
||||
then
|
||||
echo "Removing debootstrap"
|
||||
rm -r debootstrap
|
||||
fi
|
||||
|
||||
if test -f debootstrap.tar.gz
|
||||
then
|
||||
echo "Removing debootstrap.tar.gz"
|
||||
rm debootstrap.tar.gz
|
||||
fi
|
||||
|
||||
Vendored
+4
-2
@@ -20,7 +20,7 @@ fi
|
||||
if test -e "$ROOT"
|
||||
then
|
||||
echo "Existing installation found at $ROOT, removing."
|
||||
./destroy_environment
|
||||
./cleanup
|
||||
fi
|
||||
|
||||
echo "Copying $FRESH to $ROOT."
|
||||
@@ -28,7 +28,7 @@ cp -r "$FRESH" "$ROOT"
|
||||
|
||||
echo "Initializing $ROOT."
|
||||
|
||||
./mountpoints
|
||||
./cleanup add_mounts
|
||||
|
||||
# Don't bother creating a new tmpfs. We don't want to leak files in, and we
|
||||
# don't want to waste more RAM on a second tmpfs. The whole thing is
|
||||
@@ -38,3 +38,5 @@ chmod 1777 "$ROOT/tmp"
|
||||
cp -r install_scripts "$ROOT/root"
|
||||
|
||||
chroot "$ROOT" /root/install_scripts/user_setup "$@"
|
||||
|
||||
./cleanup mounts
|
||||
|
||||
Vendored
-30
@@ -1,30 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
if test `id -u` -ne 0
|
||||
then
|
||||
echo "$0 must be run as root."
|
||||
return
|
||||
fi
|
||||
|
||||
ROOT=test_environment
|
||||
|
||||
cleanup_mount() {
|
||||
if mountpoint "$1" > /dev/null
|
||||
then
|
||||
echo "Unmounting $1"
|
||||
umount "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
if test -e "$ROOT"
|
||||
then
|
||||
cleanup_mount "$ROOT/dev/pts"
|
||||
cleanup_mount "$ROOT/dev"
|
||||
cleanup_mount "$ROOT/sys"
|
||||
cleanup_mount "$ROOT/proc"
|
||||
echo "Removing $ROOT"
|
||||
rm -r "$ROOT"
|
||||
else
|
||||
echo "No environment found at $ROOT. Doing nothing."
|
||||
fi
|
||||
|
||||
Vendored
+3
-1
@@ -15,6 +15,8 @@ else
|
||||
./create_environment
|
||||
fi
|
||||
|
||||
./mountpoints
|
||||
./cleanup add_mounts
|
||||
|
||||
chroot "$ROOT" sudo -iu user "$@"
|
||||
|
||||
./cleanup mounts
|
||||
|
||||
Reference in New Issue
Block a user