From 7a69531c00ecf502fcd9912e3ed9a8d1e7f435a0 Mon Sep 17 00:00:00 2001 From: Nicolas Dechesne Date: Wed, 25 Jan 2017 14:15:43 +0100 Subject: automated: sh-test-lib: add check_root() when needed In a few lib functions , we are running commands which require root. so let's call check_root() whenever it's needed, to avoid adding the check in the test scripts themselves. For example , in many test case we use check_root() mostly because we want to install packages with install_deps(). Let's add a call to check_root() in install_deps() directly, since installing packages *always* require root. Then we can remove un-needed checks from the test case themselves. Change-Id: Ifd76dacf85f21825f2e47cd224a3725c69eba899 Signed-off-by: Nicolas Dechesne --- automated/lib/sh-test-lib | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/automated/lib/sh-test-lib b/automated/lib/sh-test-lib index bdc74e8..1429db6 100755 --- a/automated/lib/sh-test-lib +++ b/automated/lib/sh-test-lib @@ -186,6 +186,8 @@ install_deps() { if [ "${skip_install}" = "True" ] || [ "${skip_install}" = "true" ]; then info_msg "install_deps skipped" else + ! check_root && \ + error_msg "About to install packages, please run this script as root." info_msg "Installing ${pkgs}" dist_name case "${dist}" in @@ -281,6 +283,8 @@ add_key() { [ "$#" -ne 1 ] && error_msg "Usage: add_key url" url="$1" + ! check_root && \ + error_msg "About to use apt-key, please run this script as root." dist_name case "${dist}" in debian|ubuntu) wget -O - "${url}" | apt-key add - ;; @@ -293,6 +297,8 @@ add_repo() { [ "$#" -lt 1 ] && error_msg "Usage: add_repo [backports]" url="$1" + ! check_root && \ + error_msg "About to add a repo, please run this script as root." dist_name case "${dist}" in # Detect Debian/Ubuntu codename and add repo automatically. The same url -- cgit v1.2.3