Bug 170080 - asterisk init.d scipt without bash
Bug#: 170080 Product:  Gentoo Linux Version: unspecified Platform: All
OS/Version: Linux Status: RESOLVED Severity: enhancement Priority: P2
Resolution: FIXED Assigned To: voip@gentoo.org Reported By: natanael.copa@gmail.com
Component: Ebuilds
URL: 
Summary: asterisk init.d scipt without bash
Keywords:  
Status Whiteboard: 
Opened: 2007-03-09 10:23 0000
Description:   Opened: 2007-03-09 10:23 0000
asterisk init.d script uses bash specific features.
Its trivial to make it run with busybox ash for embedded:

diff -ruN data.orig/etc/init.d/asterisk data/etc/init.d/asterisk
--- data.orig/etc/init.d/asterisk       2006-12-20 10:13:39 +0000
+++ data/etc/init.d/asterisk    2006-12-21 13:30:39 +0000
@@ -174,7 +174,7 @@
        fi

        if [[ -n "${ASTERISK_USER}" ]]; then
-               USER=${ASTERISK_USER/:*/}
+               USER=$(echo $ASTERISK_USER | sed 's/:.*//')
                GROUP=$(echo $ASTERISK_USER | awk -F: '/.*:.*/ { print $2 }')
                if [[ -n "${USER}" ]]; then
                        ASTERISK_OPTS="${ASTERISK_OPTS} -U ${USER}"
@@ -191,15 +191,17 @@
        if [[ "$(echo ${ASTERISK_WRAPPER} | tr [:upper:] [:lower:])" != "yes"
]]; then
                start-stop-daemon --start --exec /usr/sbin/asterisk \
                        ${OPTS} -- ${ASTERISK_OPTS}
+               result=$?
        else
                asterisk_run_loop ${ASTERISK_OPTS} 2>/dev/null &
+               result=$?
        fi

        if [[ $result -eq 0 ]]; then
                # 2 seconds should be enough for asterisk to start
-               sleep 2
-
-               result=$(is_running)
+               sleep 2 
+               is_running
+               result=$?
        fi

        eend $result

------- Comment #1 From Natanael Copa 2007-03-09 13:19:47 0000 -------
Created an attachment (id=112700) [details]
00-unbash.patch

The patch also replaces all [[ with [

------- Comment #2 From solar 2007-03-09 15:29:22 0000 -------
Just a note:

solar@here ~ $ echo FooBar | tr [:upper:] [:lower:]
FooBar
solar@here ~ $ echo FooBar | tr '[:upper:]' '[:lower:]'
foobar

------- Comment #3 From Natanael Copa 2007-03-09 15:36:28 0000 -------
(In reply to comment #2)
> Just a note:
> 
> solar@here ~ $ echo FooBar | tr [:upper:] [:lower:]
> FooBar
> solar@here ~ $ echo FooBar | tr '[:upper:]' '[:lower:]'
> foobar
> 

what shell is that?

# busybox ash
$ echo FooBar | tr [:upper:] [:lower:]
foobar

Should I submit a new patch?

------- Comment #4 From solar 2007-03-09 16:23:04 0000 -------
> what shell is that?

default shell was bash

But I get the same behavior in both busybox and bash where it needs single
ticks.

> Should I submit a new patch?

naa. I'll see if stkn is ok with me commiting your update. I or he will fix it
then.

------- Comment #5 From solar 2007-03-09 21:00:56 0000 -------
  09 Mar 2007; <solar@gentoo.org> files/1.2.0/asterisk.rc6:
  - posix compliant init.d script from Natanael Copa. bug 170080

Thanks.