[bitbake-devel] [PATCH 03/11] toaster: Make toaster script working in zsh

Alex DAMIAN alexandru.damian at intel.com
Mon May 11 10:58:34 UTC 2015


From: Ed Bartosh <ed.bartosh at linux.intel.com>

Fixed shell syntax not understood by zsh. Made toaster
script to work for both shells in both modes: sourced and
directly called.

[YOCTO #6964]

Signed-off-by: Ed Bartosh <ed.bartosh at linux.intel.com>
---
 bin/toaster | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/bin/toaster b/bin/toaster
index 792fb72..8568c13 100755
--- a/bin/toaster
+++ b/bin/toaster
@@ -63,7 +63,7 @@ function webserverStartAll()
             retval=0
             python $BBBASEDIR/lib/toaster/manage.py migrate orm || retval=1
         fi
-	if [ "x$TOASTER_MANAGED" == "x1" ]; then
+	if [ "$TOASTER_MANAGED" '==' '1' ]; then
 	        python $BBBASEDIR/lib/toaster/manage.py migrate bldcontrol || retval=1
 		python $BBBASEDIR/lib/toaster/manage.py checksettings  --traceback || retval=1
 	fi
@@ -97,7 +97,7 @@ INSTOPSYSTEM=0
 function stop_system()
 {
     # prevent reentry
-    if [ $INSTOPSYSTEM == 1 ]; then return; fi
+    if [ $INSTOPSYSTEM -eq 1 ]; then return; fi
     INSTOPSYSTEM=1
     if [ -f ${BUILDDIR}/.toasterui.pid ]; then
         kill $(< ${BUILDDIR}/.toasterui.pid ) 2>/dev/null
@@ -119,7 +119,7 @@ function check_pidbyfile() {
 
 
 function notify_chldexit() {
-    if [ $NOTOASTERUI == 0 ]; then
+    if [ $NOTOASTERUI -eq 0 ]; then
         check_pidbyfile ${BUILDDIR}/.toasterui.pid && return
         stop_system
     fi
@@ -143,8 +143,7 @@ function verify_prereq() {
 
 
 # read command line parameters
-
-BBBASEDIR=`dirname ${BASH_SOURCE}`/..
+BBBASEDIR=`dirname ${BASH_SOURCE:-${(%):-%x}}`/..
 RUNNING=0
 
 NOTOASTERUI=0
@@ -168,8 +167,9 @@ for param in $*; do
     esac
 done
 
+[ -z "$ZSH_NAME" ] && SRCFILE=${BASH_SOURCE} || SRCFILE=$_
 
-if [ -z "$ZSH_NAME" ] && [ `basename \"$0\"` = `basename \"$BASH_SOURCE\"` ]; then
+if [ `basename \"$0\"` = `basename \"${SRCFILE}\"` ]; then
     # We are called as standalone. We refuse to run in a build environment - we need the interactive mode for that.
     # Start just the web server, point the web browser to the interface, and start any Django services.
 
@@ -183,7 +183,7 @@ if [ -z "$ZSH_NAME" ] && [ `basename \"$0\"` = `basename \"$BASH_SOURCE\"` ]; th
         exit 1;
     fi
 
-    if [ "x`which daemon`" == "x" ]; then
+    if ! which daemon >/dev/null 2>&1; then
         echo -e "Failed dependency; toaster needs the 'daemon' program in order to be able to start builds'. Please install the 'daemon' program from your distribution repositories or http://www.libslack.org/daemon/" 1>&2;
 	exit 1;
     fi
@@ -251,14 +251,14 @@ fi
 
 
 # We make sure we're running in the current shell and in a good environment
-if [ -z "$BUILDDIR" ] || [ -z `which bitbake` ]; then
+if [ -z "$BUILDDIR" ] ||  ! which bitbake >/dev/null 2>&1 ; then
     echo "Error: Build environment is not setup or bitbake is not in path." 1>&2;
     return 2
 fi
 
 
 # Determine the action. If specified by arguments, fine, if not, toggle it
-if [ "x$1" == "xstart" ] || [ "x$1" == "xstop" ]; then
+if [ "$1" '==' 'start' ] || [ "$1" '==' 'stop' ]; then
     CMD="$1"
 else
     if [ -z "$BBSERVER" ]; then
@@ -274,16 +274,16 @@ echo "The system will $CMD."
 
 lock=1
 if [ -e $BUILDDIR/bitbake.lock ]; then
-    (flock -n 200 ) 200<$BUILDDIR/bitbake.lock || lock=0
+    python -c "import fcntl; fcntl.flock(open(\"$BUILDDIR/bitbake.lock\"), fcntl.LOCK_EX|fcntl.LOCK_NB)" 2>/dev/null || lock=0
 fi
 
-if [ ${CMD} == "start" ] && [ $lock -eq 0 ]; then
+if [ ${CMD} '==' 'start' ] && [ $lock -eq 0 ]; then
     echo "Error: bitbake lock state error. File locks show that the system is on." 1>&2
     echo "Please wait for the current build to finish, stop and then start the system again." 1>&2
     return 3
 fi
 
-if [ ${CMD} == "start" ] && [ -e $BUILDDIR/.toastermain.pid ] && kill -0 `cat $BUILDDIR/.toastermain.pid`; then
+if [ ${CMD} '==' 'start' ] && [ -e $BUILDDIR/.toastermain.pid ] && kill -0 `cat $BUILDDIR/.toastermain.pid`; then
     echo "Warning: bitbake appears to be dead, but the Toaster web server is running. Something fishy is going on." 1>&2
     echo "Cleaning up the web server to start from a clean slate."
     webserverKillAll
@@ -311,7 +311,7 @@ case $CMD in
             echo "Bitbake server start failed"
         else
             export BBSERVER=0.0.0.0:-1
-            if [ $NOTOASTERUI == 0 ]; then        # we start the TOASTERUI only if not inhibited
+            if [ $NOTOASTERUI -eq 0 ]; then        # we start the TOASTERUI only if not inhibited
                 bitbake --observe-only -u toasterui >>${BUILDDIR}/toaster_ui.log 2>&1 & echo $! >${BUILDDIR}/.toasterui.pid
             fi
         fi
-- 
1.9.1




More information about the bitbake-devel mailing list