bash/snippets/is_chrooted.sh
2018-04-30 02:53:44 +02:00

20 lines
428 B
Bash
Executable File

#!/usr/bin/env bash
# - Test if script is running in a chrooted environment
# -
# - !! Script MUST run with root privileges!!
# -
if [ "$(id -u)" != "0" ]; then
echo -e "\n\tThis script must be run as root.\n" 1>&2
exit 1
fi
if [[ "$(stat -c %d:%i /)" = "$(stat -c %d:%i /proc/1/root/.)" ]]; then
echo -e "\n\tRunning NOT in a chrooted environment.\n"
else
echo -e "\n\tRunning in a chrooted environment.\n"
fi