From patchwork Wed Jul 9 15:25:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trevor Woerner X-Patchwork-Id: 33330 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CA9A6208CF for ; Wed, 9 Jul 2014 15:25:55 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id eu11sf51621276pac.6 for ; Wed, 09 Jul 2014 08:25:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=FztO2YVtOONzabxzzuPLPaTIr5NxcvQS8jOtp+U7FzI=; b=bDUQQFuwdcOJPpxEsHVN06JXgo+XS8s9raPRF23zJQ5rbjZFV9OlGboo1ovZlkVZM7 312uiJVGDhmf3rjRc2BVhcB/wNBoFoBn6xzJA6CxHmxQBoillCGz7T3t8dOUTzBW0I8z xXyI8lu9FnHVcnFrtxlXtnqs4lDxiy7kayiWuBOCqTU/6NI0+uS83xNUVCSTP+XFz25Y SZP5tPEgln/Qgi5GotJmvCrcPwtLOsAgzZ6/ZjYNB4WuJqU9TX4EkZWCjNSGe2k4bdrO v1WMfJH+n7JQMIeo9eDOLSwXSvqyZOBS4l2uKuULkcJ5ZMt7Kan5ZX17vV7gsgFAuFum oaNQ== X-Gm-Message-State: ALoCoQmj6HTxGpISX705MY77eZA0vvLxSD2CuVVJHEQ5rDIbWZQm39zamla9iLQkOPidwXGQr/Zi X-Received: by 10.70.41.203 with SMTP id h11mr5942071pdl.3.1404919555143; Wed, 09 Jul 2014 08:25:55 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.26.241 with SMTP id 104ls2440902qgv.21.gmail; Wed, 09 Jul 2014 08:25:55 -0700 (PDT) X-Received: by 10.220.81.194 with SMTP id y2mr25176716vck.29.1404919555043; Wed, 09 Jul 2014 08:25:55 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id g18si13965181veh.84.2014.07.09.08.25.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 09 Jul 2014 08:25:55 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id il7so7075061vcb.40 for ; Wed, 09 Jul 2014 08:25:55 -0700 (PDT) X-Received: by 10.221.26.10 with SMTP id rk10mr40359362vcb.0.1404919554972; Wed, 09 Jul 2014 08:25:54 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp56563vcb; Wed, 9 Jul 2014 08:25:54 -0700 (PDT) X-Received: by 10.42.37.13 with SMTP id w13mr40962902icd.13.1404919554413; Wed, 09 Jul 2014 08:25:54 -0700 (PDT) Received: from mail-ig0-f170.google.com (mail-ig0-f170.google.com [209.85.213.170]) by mx.google.com with ESMTPS id ay7si13103580icb.11.2014.07.09.08.25.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 09 Jul 2014 08:25:54 -0700 (PDT) Received-SPF: pass (google.com: domain of trevor.woerner@linaro.org designates 209.85.213.170 as permitted sender) client-ip=209.85.213.170; Received: by mail-ig0-f170.google.com with SMTP id h15so2043443igd.3 for ; Wed, 09 Jul 2014 08:25:54 -0700 (PDT) X-Received: by 10.50.36.106 with SMTP id p10mr14137734igj.9.1404919554098; Wed, 09 Jul 2014 08:25:54 -0700 (PDT) Received: from openSUSE-i7.site (69-165-220-158.dsl.teksavvy.com. [69.165.220.158]) by mx.google.com with ESMTPSA id f19sm10161326igt.13.2014.07.09.08.25.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Jul 2014 08:25:53 -0700 (PDT) From: Trevor Woerner To: meta-freescale@yoctoproject.org Cc: patches@linaro.org, Otavio Salvador , Timur Aydin , Alexandre Belloni , Mario Domenech Goulart Subject: [PATCH][fsl-community-bsp-base] setup-environment: check script has been sourced Date: Wed, 9 Jul 2014 11:25:28 -0400 Message-Id: <1404919528-10899-1-git-send-email-trevor.woerner@linaro.org> X-Mailer: git-send-email 2.0.0.5.gbce14aa X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: trevor.woerner@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Check that this script has been invoked correctly (i.e. that it has been "source"d and not merely run directly). If it has been run directly, don't exit immediately in case the user specified the "help" option, allow the help to be displayed, then exit. Adjust how this script is terminated based on whether it has been sourced or run directly (i.e. use either "return" or "exit" as required). This change fixes an infinite loop that is caused if the user runs this script directly and specifies the help option. These changes have been tested on: bash, dash, and zsh. Signed-off-by: Trevor Woerner --- setup-environment | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/setup-environment b/setup-environment index 5931e2b..d3f89ce 100755 --- a/setup-environment +++ b/setup-environment @@ -24,6 +24,23 @@ NCPU=`grep -c processor /proc/cpuinfo` CWD=`pwd` PROGNAME="setup-environment" +# try to determine if this script has been invoked correctly +# in other words, make sure it has been "source"d +# don't exit out immediately, allow the user to ask for -h +INVOKEGOOD=1 +if [ -n "$ZSH_NAME" ]; then + # check for zsh + if [ -n "$BASH_SOURCE" ]; then + INVOKEGOOD=0 + fi +else + # check for bash, sh, and dash + echo $0 | grep -q $PROGNAME + if [ $? -eq 0 ]; then + INVOKEGOOD=0 + fi +fi + usage() { echo -e "\nUsage: source $PROGNAME @@ -55,6 +72,10 @@ ARGS=$(getopt --options $SHORTOPTS \ --longoptions $LONGOPTS --name $PROGNAME -- "$@" ) # Print the usage menu if invalid options are specified if [ $? != 0 -o $# -lt 1 ]; then + if [ $INVOKEGOOD = 0 ]; then + echo "Error: This script needs to be sourced. Please run as '. $PROGNAME'" + exit 1 + fi usage && clean_up return 1 fi @@ -66,6 +87,9 @@ do -h|--help) usage clean_up + if [ $INVOKEGOOD = 0 ]; then + exit 0 + fi return 0 ;; --) @@ -75,6 +99,11 @@ do esac done +if [ $INVOKEGOOD = 0 ]; then + echo "Error: This script needs to be sourced. Please run as '. $PROGNAME'" + exit 1 +fi + if [ "$(whoami)" = "root" ]; then echo "ERROR: do not use the BSP as root. Exiting..." fi