From 86dcc8e68bbc8a0205e29a1439a06b9beeafd5ee Mon Sep 17 00:00:00 2001 From: "derat@google.com" Date: Sat, 21 Nov 2009 19:49:49 +0000 Subject: [PATCH] build: Make enter_chroot.sh fail if run as root. BUG=684 Review URL: http://codereview.chromium.org/429006 git-svn-id: svn://chrome-svn/chromeos/trunk@304 06c00378-0e64-4dae-be16-12b19f9950a1 --- common.sh | 7 +++++++ enter_chroot.sh | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/common.sh b/common.sh index fc7a897d61..25dee4a3ed 100644 --- a/common.sh +++ b/common.sh @@ -171,6 +171,13 @@ function assert_outside_chroot { fi } +function assert_not_root_user { + if [ `id -u` = 0 ]; then + echo "This script must be run as a non-root user." + exit 1 + fi +} + # Install a package if it's not already installed function install_if_missing { # Positional parameters from calling script. :? means "fail if unset". diff --git a/enter_chroot.sh b/enter_chroot.sh index 101280dee8..acfa84682d 100755 --- a/enter_chroot.sh +++ b/enter_chroot.sh @@ -10,8 +10,9 @@ # The path to common.sh should be relative to your script's location. . "$(dirname "$0")/common.sh" -# Script must be run outside the chroot +# Script must be run outside the chroot and as a regular user. assert_outside_chroot +assert_not_root_user # Define command line flags # See http://code.google.com/p/shflags/wiki/Documentation10x