From 30109fe78e93bf2f88ebe866577bd957af35c98b Mon Sep 17 00:00:00 2001 From: Shaun Taheri Date: Thu, 22 Jun 2017 14:05:48 +0200 Subject: Fix script directory in zsh --- scripts/envsetup.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/envsetup.sh b/scripts/envsetup.sh index 5adf319..7314111 100755 --- a/scripts/envsetup.sh +++ b/scripts/envsetup.sh @@ -1,7 +1,6 @@ -#!/bin/sh +#!/bin/bash SCRIPT="envsetup.sh" - MACHINE=$1 if [ "$#" -lt 1 ]; then @@ -32,8 +31,12 @@ if [ $SOURCED -ne 1 ]; then exit -1 fi -SCRIPTDIR=$(cd $(dirname $BASH_SOURCE) && pwd -P) -METADIR=$(cd $(dirname $BASH_SOURCE)/../.. && pwd -P) +if [ -n "$ZSH_VERSION" ]; then + SCRIPTDIR=$(cd $(dirname $0) && pwd -P) +else + SCRIPTDIR=$(cd $(dirname $BASH_SOURCE) && pwd -P) +fi +METADIR="${SCRIPTDIR}/../.." if [ -e ${BUILDDIR}/conf/local.conf ]; then source $METADIR/poky/oe-init-build-env ${BUILDDIR} -- cgit v1.2.3-54-g00ecf From a33124a4592820f4b3c4deaf6853476df2a2f105 Mon Sep 17 00:00:00 2001 From: Shaun Taheri Date: Fri, 23 Jun 2017 14:26:56 +0200 Subject: Quote all bash variables --- scripts/envsetup.sh | 54 ++++++++++++++++++----------------------------------- 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/scripts/envsetup.sh b/scripts/envsetup.sh index 7314111..c2f27c5 100755 --- a/scripts/envsetup.sh +++ b/scripts/envsetup.sh @@ -1,51 +1,33 @@ #!/bin/bash SCRIPT="envsetup.sh" -MACHINE=$1 +MACHINE="$1" +BUILDDIR="build" -if [ "$#" -lt 1 ]; then - echo "Usage: ${SCRIPT} [builddir]" - return -1 -elif [ "$#" -eq 2 ]; then - BUILDDIR=$2 -else - BUILDDIR=build -fi -BULDDIR=$2 +[[ "$#" -lt 1 ]] && { echo "Usage: ${SCRIPT} [builddir]"; return 1; } +[[ "$#" -eq 2 ]] && { BUILDDIR="$2"; } # detect if this script is sourced: see http://stackoverflow.com/a/38128348/6255594 SOURCED=0 if [ -n "$ZSH_EVAL_CONTEXT" ]; then - [[ $ZSH_EVAL_CONTEXT =~ :file$ ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- $0) && pwd -P); } -elif [ -n "$KSH_VERSION" ]; then - [[ "$(cd $(dirname -- $0) && pwd -P)/$(basename -- $0)" != "$(cd $(dirname -- ${.sh.file}) && pwd -P)/$(basename -- ${.sh.file})" ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- ${.sh.file}) && pwd -P); } + [[ "$ZSH_EVAL_CONTEXT" =~ :file$ ]] && { SOURCED=1; SOURCEDIR=$(cd "$(dirname -- "$0")" && pwd -P); } elif [ -n "$BASH_VERSION" ]; then - [[ $0 != "$BASH_SOURCE" ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- $BASH_SOURCE) && pwd -P); } + [[ "$0" != "${BASH_SOURCE[0]}" ]] && { SOURCED=1; SOURCEDIR=$(cd "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P); } fi -if [ $SOURCED -ne 1 ]; then - unset SOURCED - unset SOURCEDIR - echo "Error: this script needs to be sourced in a supported shell" >&2 - echo "Please check that the current shell is bash, zsh or ksh and run this script as '. $0 '" >&2 - exit -1 +if [[ $SOURCED -ne 1 ]]; then + echo "Error: this script needs to be sourced in a supported shell" >&2 + echo "Please check that the current shell is bash or zsh and run this script as '. $0 '" >&2 + exit 1 fi -if [ -n "$ZSH_VERSION" ]; then - SCRIPTDIR=$(cd $(dirname $0) && pwd -P) -else - SCRIPTDIR=$(cd $(dirname $BASH_SOURCE) && pwd -P) -fi -METADIR="${SCRIPTDIR}/../.." +METADIR="${SOURCEDIR}/../.." +source "$METADIR/poky/oe-init-build-env" "$BUILDDIR" -if [ -e ${BUILDDIR}/conf/local.conf ]; then - source $METADIR/poky/oe-init-build-env ${BUILDDIR} -else - source $METADIR/poky/oe-init-build-env ${BUILDDIR} - echo "METADIR := \"\${@os.path.abspath('${METADIR}')}\"" >> conf/bblayers.conf - cat ${METADIR}/meta-updater/conf/include/bblayers/sota.inc >> conf/bblayers.conf - cat ${METADIR}/meta-updater/conf/include/bblayers/sota_${MACHINE}.inc >> conf/bblayers.conf - echo "MACHINE = \"${MACHINE}\"" >> conf/local.conf - echo "DISTRO = \"poky-sota-systemd\"" >> conf/local.conf +if [[ ! -f "${BUILDDIR}/conf/local.conf" ]]; then + echo "METADIR := \"\${@os.path.abspath('${METADIR}')}\"" >> conf/bblayers.conf + cat "${METADIR}/meta-updater/conf/include/bblayers/sota.inc" >> conf/bblayers.conf + cat "${METADIR}/meta-updater/conf/include/bblayers/sota_${MACHINE}.inc" >> conf/bblayers.conf + echo "MACHINE = \"${MACHINE}\"" >> conf/local.conf + echo "DISTRO = \"poky-sota-systemd\"" >> conf/local.conf fi - -- cgit v1.2.3-54-g00ecf From 0f40a9d48aeffeebccd01124f8e8c43b2e29883c Mon Sep 17 00:00:00 2001 From: Phil Wise Date: Mon, 26 Jun 2017 16:33:56 +0200 Subject: Fix new/existing build directory logic --- scripts/envsetup.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/envsetup.sh b/scripts/envsetup.sh index c2f27c5..ff78681 100755 --- a/scripts/envsetup.sh +++ b/scripts/envsetup.sh @@ -22,12 +22,14 @@ if [[ $SOURCED -ne 1 ]]; then fi METADIR="${SOURCEDIR}/../.." -source "$METADIR/poky/oe-init-build-env" "$BUILDDIR" if [[ ! -f "${BUILDDIR}/conf/local.conf" ]]; then + source "$METADIR/poky/oe-init-build-env" "$BUILDDIR" echo "METADIR := \"\${@os.path.abspath('${METADIR}')}\"" >> conf/bblayers.conf cat "${METADIR}/meta-updater/conf/include/bblayers/sota.inc" >> conf/bblayers.conf cat "${METADIR}/meta-updater/conf/include/bblayers/sota_${MACHINE}.inc" >> conf/bblayers.conf echo "MACHINE = \"${MACHINE}\"" >> conf/local.conf echo "DISTRO = \"poky-sota-systemd\"" >> conf/local.conf +else + source "$METADIR/poky/oe-init-build-env" "$BUILDDIR" fi -- cgit v1.2.3-54-g00ecf