87 lines
1.6 KiB
Bash
Executable File
87 lines
1.6 KiB
Bash
Executable File
#!/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" -q
|
|
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" -q
|
|
then
|
|
echo "Unmounting $ROOT$1"
|
|
umount "$ROOT$1"
|
|
fi
|
|
}
|
|
|
|
add_mounts() {
|
|
add_mount /proc
|
|
add_mount /sys
|
|
add_mount /dev
|
|
add_mount /dev/pts
|
|
add_mount /tmp/.X11-unix
|
|
}
|
|
|
|
remove_mounts() {
|
|
remove_mount /tmp/.X11-unix
|
|
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 -f xbps-static*.tar.xz
|
|
then
|
|
echo "Removing xbps-static tarballs."
|
|
rm xbps-static*.tar.xz
|
|
fi
|
|
}
|
|
|
|
case "$1" in
|
|
everything) remove_everything ;;
|
|
mounts) remove_mounts ;;
|
|
add_mounts) add_mounts ;;
|
|
environment) remove_environment ;;
|
|
"") remove_environment ;;
|
|
esac
|
|
|