aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2015-05-04 13:38:50 +0300
committerAlexandru DAMIAN <alexandru.damian@intel.com>2015-06-10 15:31:12 +0100
commitbd95425c35c7d8386c57329e425aa7802537b479 (patch)
treea2a2343a5d87394e58252d060c174fa799b3e4db
parenta5bc29083d4f85a5695f3f62d5badb783c6f7224 (diff)
downloadbitbake-bd95425c35c7d8386c57329e425aa7802537b479.tar.gz
toaster: Code cleanup: bashisms
Fixed the following bashisms: replaced echo -e -> printf removed 'function' from function definitions replaced $(< ${file}) -> `cat ${file}` Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
-rwxr-xr-xbin/toaster55
1 files changed, 28 insertions, 27 deletions
diff --git a/bin/toaster b/bin/toaster
index ee199374e..0fa8b6014 100755
--- a/bin/toaster
+++ b/bin/toaster
@@ -28,23 +28,24 @@
# Helper function to kill a background toaster development server
-function webserverKillAll()
+webserverKillAll()
{
local pidfile
for pidfile in ${BUILDDIR}/.toastermain.pid; do
if [ -f ${pidfile} ]; then
- while kill -0 $(< ${pidfile}) 2>/dev/null; do
- kill -SIGTERM -$(< ${pidfile}) 2>/dev/null
- sleep 1
- # Kill processes if they are still running - may happen in interactive shells
- pkill -U $UID -f "python.*manage.py runserver"
- done;
- rm ${pidfile}
+ pid=`cat ${pidfile}`
+ while kill -0 $pid 2>/dev/null; do
+ kill -SIGTERM -$pid 2>/dev/null
+ sleep 1
+ # Kill processes if they are still running - may happen in interactive shells
+ ps fux | grep "python.*manage.py runserver" | awk '{print $2}' | xargs kill
+ done
+ rm ${pidfile}
fi
done
}
-function webserverStartAll()
+webserverStartAll()
{
# do not start if toastermain points to a valid process
if ! cat "${BUILDDIR}/.toastermain.pid" 2>/dev/null | xargs -I{} kill -0 {} ; then
@@ -62,7 +63,7 @@ function webserverStartAll()
if [ $retval -eq 1 ]; then
echo "Failed db sync, stopping system start" 1>&2
elif [ $retval -eq 2 ]; then
- echo -e "\nError on migration, trying to recover... \n"
+ printf "\nError on migration, trying to recover... \n"
python $BBBASEDIR/lib/toaster/manage.py migrate orm 0001_initial --fake
retval=0
python $BBBASEDIR/lib/toaster/manage.py migrate orm || retval=1
@@ -87,7 +88,7 @@ function webserverStartAll()
# Helper functions to add a special configuration file
-function addtoConfiguration()
+addtoConfiguration()
{
file=$1
shift
@@ -98,13 +99,13 @@ function addtoConfiguration()
INSTOPSYSTEM=0
# define the stop command
-function stop_system()
+stop_system()
{
# prevent reentry
if [ $INSTOPSYSTEM -eq 1 ]; then return; fi
INSTOPSYSTEM=1
if [ -f ${BUILDDIR}/.toasterui.pid ]; then
- kill $(< ${BUILDDIR}/.toasterui.pid ) 2>/dev/null
+ kill `cat ${BUILDDIR}/.toasterui.pid` 2>/dev/null
rm ${BUILDDIR}/.toasterui.pid
fi
BBSERVER=0.0.0.0:-1 bitbake -m
@@ -117,12 +118,12 @@ function stop_system()
INSTOPSYSTEM=0
}
-function check_pidbyfile() {
- [ -e $1 ] && kill -0 $(< $1) 2>/dev/null
+check_pidbyfile() {
+ [ -e $1 ] && kill -0 `cat $1` 2>/dev/null
}
-function notify_chldexit() {
+notify_chldexit() {
if [ $NOTOASTERUI -eq 0 ]; then
check_pidbyfile ${BUILDDIR}/.toasterui.pid && return
stop_system
@@ -130,16 +131,16 @@ function notify_chldexit() {
}
-function verify_prereq() {
+verify_prereq() {
# Verify prerequisites
if ! echo "import django; print (1,) == django.VERSION[0:1] and django.VERSION[1:2][0] in (6,)" | python 2>/dev/null | grep True >/dev/null; then
- echo -e "This program needs Django 1.6. Please install with\n\npip install django==1.6\n"
+ printf "This program needs Django 1.6. Please install with\n\npip install django==1.6\n"
return 2
fi
if ! echo "import south; print reduce(lambda x, y: 2 if x==2 else 0 if x == 0 else y, map(lambda x: 1+cmp(x[1]-x[0],0), zip([0,8,4], map(int,south.__version__.split(\".\"))))) > 0" | python 2>/dev/null | grep True >/dev/null; then
- echo -e "This program needs South 0.8.4. Please install with\n\npip install south==0.8.4\n"
+ printf "This program needs South 0.8.4. Please install with\n\npip install south==0.8.4\n"
return 2
fi
return 0
@@ -182,42 +183,42 @@ if [ `basename \"$0\"` = `basename \"${SRCFILE}\"` ]; then
# Start just the web server, point the web browser to the interface, and start any Django services.
if ! verify_prereq; then
- echo -e "Error: Could not verify that the needed dependencies are installed. Please use virtualenv and pip to install dependencies listed in toaster-requirements.txt" 1>&2
+ echo "Error: Could not verify that the needed dependencies are installed. Please use virtualenv and pip to install dependencies listed in toaster-requirements.txt" 1>&2
exit 1
fi
if [ -n "$BUILDDIR" ]; then
- echo -e "Error: It looks like you sourced oe-init-build-env. Toaster cannot start in build mode from an oe-core build environment.\n You should be starting Toaster from a new terminal window." 1>&2
+ printf "Error: It looks like you sourced oe-init-build-env. Toaster cannot start in build mode from an oe-core build environment.\n You should be starting Toaster from a new terminal window." 1>&2
exit 1
fi
# Define a fake builddir where only the pid files are actually created. No real builds will take place here.
BUILDDIR=/tmp/toaster_$$
if [ -d "$BUILDDIR" ]; then
- echo -e "Previous toaster run directory $BUILDDIR found, cowardly refusing to start. Please remove the directory when that toaster instance is over" 2>&1
+ echo "Previous toaster run directory $BUILDDIR found, cowardly refusing to start. Please remove the directory when that toaster instance is over" 2>&1
exit 1
fi
mkdir -p "$BUILDDIR"
RUNNING=1
- function trap_ctrlc() {
+ trap_ctrlc() {
echo "** Stopping system"
webserverKillAll
RUNNING=0
}
- function do_cleanup() {
+ do_cleanup() {
find "$BUILDDIR" -type f | xargs rm
rmdir "$BUILDDIR"
}
- function cleanup() {
+ cleanup() {
if grep -ir error "$BUILDDIR" >/dev/null; then
if grep -irn "That port is already in use" "$BUILDDIR"; then
echo "You can use the \"webport=PORTNUMBER\" parameter to start Toaster on a different port (port $WEB_PORT is already in use)"
do_cleanup
else
- echo -e "\nErrors found in the Toaster log files present in '$BUILDDIR'. Directory will not be cleaned.\n Please review the errors and notify toaster@yoctoproject.org or submit a bug https://bugzilla.yoctoproject.org/enter_bug.cgi?product=Toaster"
+ printf "\nErrors found in the Toaster log files present in '$BUILDDIR'. Directory will not be cleaned.\n Please review the errors and notify toaster@yoctoproject.org or submit a bug https://bugzilla.yoctoproject.org/enter_bug.cgi?product=Toaster"
fi
else
echo "No errors found, removing the run directory '$BUILDDIR'"
@@ -248,7 +249,7 @@ fi
if ! verify_prereq; then
- echo -e "Error: Could not verify that the needed dependencies are installed. Please use virtualenv and pip to install dependencies listed in toaster-requirements.txt" 1>&2
+ echo "Error: Could not verify that the needed dependencies are installed. Please use virtualenv and pip to install dependencies listed in toaster-requirements.txt" 1>&2
return 1
fi