You are not logged in.
Modified patch using if [ -n "$BASH" ]; then ...
Patch is against current git.
Please test.
diff --git a/functions b/functions
index 6be008f..fe3fc66 100644
--- a/functions
+++ b/functions
@@ -165,10 +165,19 @@ stop_daemon() {
}
#Source additional functions at the end to allow overrides
-if [ -d /etc/rc.d/functions.d/ ]; then
- for f in $(/bin/ls /etc/rc.d/functions.d/); do
- . /etc/rc.d/functions.d/$f
- done
+for f in /etc/rc.d/functions.d/*; do
+ [ -e "$f" ] && . /etc/rc.d/functions.d/$f
+done
+
+# convert bash arrays for backward compat
+if [ -n "$BASH" ]; then
+ eval 'MODULES="${MODULES[@]}"'
+ eval 'MOD_BLACKLIST="${MOD_BLACKLIST[@]}"'
+ eval 'INTERFACES="${INTERFACES[@]}"'
+ eval 'BOND_INTERFACES="${BOND_INTERFACES[@]}"'
+ eval 'BRIDGE_INTERFACES="${BRIDGE_INTERFACES[@]}"'
+ eval 'ROUTES="${ROUTES[@]}"'
+ eval 'DAEMONS="${DAEMONS[@]}"'
fi
# End of file
diff --git a/netfs b/netfs
index 25db4e1..1a18229 100755
--- a/netfs
+++ b/netfs
@@ -1,6 +1,5 @@
-#!/bin/bash
+#!/bin/sh
-# sourcing our current rc.conf requires this to be a bash script
. /etc/rc.conf
. /etc/rc.d/functions
diff --git a/network b/network
index 8c17ee7..a74d538 100755
--- a/network
+++ b/network
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
. /etc/rc.conf
. /etc/rc.d/functions
@@ -54,7 +54,7 @@ ifdown()
iflist()
{
- for ifline in ${INTERFACES[@]}; do
+ for ifline in ${INTERFACES}; do
if [ "$ifline" = "${ifline#!}" ]; then
printf " $ifline:\t"
else
@@ -89,7 +89,7 @@ rtdown()
rtlist()
{
- for rtline in ${ROUTES[@]}; do
+ for rtline in ${ROUTES}; do
if [ "$rtline" = "${rtline#!}" ]; then
printf " $rtline:\t"
else
@@ -102,7 +102,7 @@ rtlist()
bond_up()
{
- for ifline in ${BOND_INTERFACES[@]}; do
+ for ifline in ${BOND_INTERFACES}; do
if [ "$ifline" = "${ifline#!}" ]; then
eval bondcfg="\$bond_${ifline}"
/sbin/ifenslave $ifline $bondcfg || error=1
@@ -112,7 +112,7 @@ bond_up()
bridge_up()
{
- for br in ${BRIDGE_INTERFACES[@]}; do
+ for br in ${BRIDGE_INTERFACES}; do
if [ "$br" = "${br#!}" ]; then
# if the bridge already exists, remove it
if [ "$(/sbin/ifconfig $br 2>/dev/null)" ]; then
@@ -132,7 +132,7 @@ bridge_up()
bridge_down()
{
- for br in ${BRIDGE_INTERFACES[@]}; do
+ for br in ${BRIDGE_INTERFACES}; do
if [ "$br" = "${br#!}" ]; then
/usr/sbin/brctl delbr $br
fi
@@ -152,7 +152,7 @@ case "$1" in
# bring up bridge interfaces
bridge_up
# bring up ethernet interfaces
- for ifline in ${INTERFACES[@]}; do
+ for ifline in ${INTERFACES}; do
if [ "$ifline" = "${ifline#!}" ]; then
ifup $ifline || error=1
fi
@@ -160,7 +160,7 @@ case "$1" in
# bring up bond interfaces
bond_up
# bring up routes
- for rtline in "${ROUTES[@]}"; do
+ for rtline in ${ROUTES}; do
if [ "$rtline" = "${rtline#!}" ]; then
rtup $rtline || error=1
fi
@@ -181,12 +181,12 @@ case "$1" in
stat_busy "Stopping Network"
rm_daemon network
error=0
- for rtline in "${ROUTES[@]}"; do
+ for rtline in ${ROUTES}; do
if [ "$rtline" = "${rtline#!}" ]; then
rtdown $rtline || error=1
fi
done
- for ifline in ${INTERFACES[@]}; do
+ for ifline in ${INTERFACES}; do
if [ "$ifline" = "${ifline#!}" ]; then
ifdown $ifline || error=1
fi
diff --git a/rc.conf b/rc.conf
index 48455f8..120b1b3 100644
--- a/rc.conf
+++ b/rc.conf
@@ -32,11 +32,11 @@ USECOLOR="yes"
# MOD_BLACKLIST: Prevent udev from loading these modules
# MODULES: Modules to load at boot-up. Prefix with a ! to blacklist.
#
-# NOTE: Use of 'MOD_BLACKLIST' is deprecated. Please use ! in the MODULES array.
+# NOTE: Use of 'MOD_BLACKLIST' is deprecated. Please use ! in the MODULES list.
#
MOD_AUTOLOAD="yes"
#MOD_BLACKLIST=() #deprecated
-MODULES=()
+MODULES=''
# Scan for LVM volume groups at startup, required if you use LVM
USELVM="no"
@@ -60,14 +60,14 @@ HOSTNAME="myhost"
# Wireless: See network profiles below
#
eth0="eth0 192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255"
-INTERFACES=(eth0)
+INTERFACES='eth0'
# Routes to start at boot-up (in this order)
# Declare each route then list in ROUTES
# - prefix an entry in ROUTES with a ! to disable it
#
gateway="default gw 192.168.0.1"
-ROUTES=(!gateway)
+ROUTES='!gateway'
# Enable these network profiles at boot-up. These are only useful
# if you happen to need multiple network configurations (ie, laptop users)
@@ -78,7 +78,7 @@ ROUTES=(!gateway)
#
# This now requires the netcfg package
#
-#NETWORKS=(main)
+#NETWORKS='main'
# -----------------------------------------------------------------------
# DAEMONS
@@ -88,4 +88,4 @@ ROUTES=(!gateway)
# - prefix a daemon with a ! to disable it
# - prefix a daemon with a @ to start it up in the background
#
-DAEMONS=(syslog-ng network netfs crond)
+DAEMONS='syslog-ng network netfs crond'
diff --git a/rc.local b/rc.local
index 4950cba..e51ecc1 100755
--- a/rc.local
+++ b/rc.local
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# /etc/rc.local: Local multi-user startup script.
#
diff --git a/rc.local.shutdown b/rc.local.shutdown
index fe60462..e96ac7d 100755
--- a/rc.local.shutdown
+++ b/rc.local.shutdown
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# /etc/rc.local.shutdown: Local shutdown script.
#
diff --git a/rc.multi b/rc.multi
index 731e48e..1583792 100755
--- a/rc.multi
+++ b/rc.multi
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# /etc/rc.multi
#
@@ -10,12 +10,12 @@
[ -r /etc/sysctl.conf ] && /sbin/sysctl -q -p &>/dev/null
# Start daemons
-for daemon in "${DAEMONS[@]}"; do
+for daemon in ${DAEMONS}; do
if [ "$daemon" = "${daemon#!}" ]; then
if [ "$daemon" = "${daemon#@}" ]; then
start_daemon $daemon
else
- start_daemon_bkgd ${daemon:1}
+ start_daemon_bkgd ${daemon#@}
fi
fi
done
diff --git a/rc.shutdown b/rc.shutdown
index 59f6e25..3c6073e 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# /etc/rc.shutdown
#
@@ -24,12 +24,12 @@ fi
if [ "$PREVLEVEL" = "3" -o "$PREVLEVEL" = "5" ]; then
# Shutdown daemons
- let i=${#DAEMONS[@]}
- while [ $i -ge 0 ]; do
- if [ "${DAEMONS[$i]:0:1}" != '!' ]; then
- ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@}
- fi
- let i=i-1
+ reverse=
+ for daemon in $DAEMONS; do
+ [ "$daemon" = "${daemon#\!}" ] && reverse="$daemon $reverse"
+ done
+ for daemon in $DAEMONS; do
+ ck_daemon ${daemon#@} || stop_daemon ${daemon#@}
done
# find any leftover daemons and shut them down in reverse order
if [ -d /var/run/daemons ]; then
diff --git a/rc.single b/rc.single
index f32e373..08b5a79 100755
--- a/rc.single
+++ b/rc.single
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# /etc/rc.single: Single-user startup script.
#
@@ -8,12 +8,12 @@
if [ "$PREVLEVEL" = "3" -o "$PREVLEVEL" = "5" ]; then
# Shutdown daemons
- let i=${#DAEMONS[@]}
- while [[ i -gt 0 ]]; do
- if [[ $(echo ${DAEMONS[$i]} | /bin/grep '^[^\!]' | /usr/bin/wc -l) -eq 1 ]]; then
- /etc/rc.d/${DAEMONS[$i]#@} stop
- fi
- let i=i-1
+ reverse=
+ for daemon in ${DAEMONS}; do
+ [ "${daemon}" = "${daemon#\!}" ] && reverse="$daemon $reverse"
+ done
+ for deamon in $reverse; do
+ /etc/rc.d/${daemon#@} stop
done
# find any leftover daemons and shut them down
if [ -d /var/run/daemons ]; then
@@ -37,7 +37,7 @@ if [ "$PREVLEVEL" != "N" ]; then
if [ -x /etc/start_udev -a -d /sys/block ]; then
# We have a start_udev script and /sys appears to be mounted, use UDev
status "Starting UDev Daemon" /etc/start_udev
- if [ "$(/bin/pidof -o %PPID /sbin/udevd)" ]; then
+ if /bin/pidof -o %PPID /sbin/udevd >/dev/null; then
# If an old udevd is kicking around, we'll have to remount pts and shm
/bin/umount /dev/shm /dev/pts >/dev/null 2>&1
/bin/mount /dev/pts
diff --git a/rc.sysinit b/rc.sysinit
index 39cf7f9..5fe35d1 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# /etc/rc.sysinit
#
@@ -87,7 +87,7 @@ fi
if ! [ "$load_modules" = "off" ]; then
if [ -f /proc/modules ]; then
stat_busy "Loading Modules"
- for mod in "${MODULES[@]}"; do
+ for mod in ${MODULES}; do
if [ "$mod" = "${mod#!}" ]; then
/sbin/modprobe $mod
fi
@@ -97,8 +97,8 @@ if ! [ "$load_modules" = "off" ]; then
if [ -d /proc/acpi ]; then
stat_busy "Loading standard ACPI modules"
ACPI_MODULES="ac battery button fan processor thermal"
- k="$(echo $BLACKLIST ${MOD_BLACKLIST[@]} | /bin/sed 's|-|_|g')"
- j="$(echo ${MODULES[@]} | /bin/sed 's|-|_|g')"
+ k="$(echo $BLACKLIST ${MOD_BLACKLIST} | /bin/sed 's|-|_|g')"
+ j="$(echo ${MODULES} | /bin/sed 's|-|_|g')"
#add disabled MODULES (!) to blacklist - much requested feature
for m in ${j}; do
[ "$m" != "${m#!}" ] && k="${k} ${m#!}"
@@ -201,7 +201,7 @@ if [ -f /etc/crypttab -a -n "$(/bin/grep -v ^# /etc/crypttab | /bin/grep -v ^$)"
else
$CS $copts create $cname $csrc < /dev/console
fi
- elif [ "${cpass:0:1}" != "/" ]; then
+ elif [ "${cpass#/}" = "$cpass" ]; then
if $CS isLuks $csrc 2>/dev/null; then
echo "$cpass" | $CS $copts luksOpen $csrc $cname >/dev/null
elseOffline
Are there already patches to make (most) initscripts POSIX compliant yet?
Proud Ex-Arch user.
Still an ArchLinux lover though.
Currently on Kubuntu 9.10
Offline
Are there already patches to make (most) initscripts POSIX compliant yet?
there's no such thing as "posix compliant initscripts" - changing bash to sh doesnt make them any more compliant with anything, it's just changing the programming language used and makes some people happy.
Last edited by iphitus (2008-06-21 00:02:56)
Offline
LTSmash wrote:Are there already patches to make (most) initscripts POSIX compliant yet?
there's no such thing as "posix compliant initscripts" - changing bash to sh doesnt make them any more compliant with anything, it's just changing the programming language used and makes some people happy.
I'm sorry, didn't mean that, what I actually meant to say is that the syntax of the scripts would be POSIX compliant... not the scripts on themselves... and I don't really care about the lenguage used, but to implement some work that makes faster bootsplashing, even if this is stupid I would like to see it done, because maybe it works...
Proud Ex-Arch user.
Still an ArchLinux lover though.
Currently on Kubuntu 9.10
Offline
Are there already patches to make (most) initscripts POSIX compliant yet?
The patches I posted should do that. They are tested with dash, bash and im pretty sure they work without any problem in busybox ash too.
Note that it does not affect initscripts in packages. Fixing the packages is a bigger job. (but not impossible)
Offline
LTSmash wrote:Are there already patches to make (most) initscripts POSIX compliant yet?
there's no such thing as "posix compliant initscripts" - changing bash to sh doesnt make them any more compliant with anything, it's just changing the programming language used and makes some people happy.
The patch I pasted above changes the iniscripts so the work with any POSIX compilant shell by removing the use of bash arrays and some bash specific subsututions.
At the end, code is cleaner and compatible with non-bash shells (like dash)
Offline
interesting, I'll try that. I see that I missed some in my attempt to do it, so the result was really bad...
UPDATE: tried the patch. when /bin/sh is bash it boots just fine. when it's set to dash, I have this:
> Distributed under the GNU General Public License (GPL)
------------------------------
:: Starting UDev Daemon [DONE]
:: Loading Modules [DONE]
:: Loading standard ACPI modules [DONE]
:: Loading UDev uevents [DONE]
> UDev uevent processing time: 2146ms
:: Bringing up loopback interface [DONE]
:: Mounting Root Read-only [DONE]
:: Checking Filesystems [DONE]
:: Mounting Local Filesystems [DONE]
:: Activating Swap [DONE]
:: Configuring System Clock [DONE]
:: Initializing Random Seed [DONE]
:: Removing Leftover Files [BUSY]
/bin/rm: cannot remove `/var/lock/dmraid': Is a directory
/bin/rm: cannot remove `/var/lock/sane': Is a directory
/bin/rm: cannot remove `.' directory `/tmp/.'
/bin/rm: cannot remove `..' directory `/tmp/..'
/bin/mkdir: cannot create directory `/tmp/.ICE-unix': File exists
/bin/mkdir: cannot create directory `/tmp/.X11-unix': File exists
[DONE]
:: Setting Hostname: w7j [DONE]
:: Updating Module Dependencies [DONE]
:: Setting Locale: en_US.utf8 [DONE]
:: Setting Consoles to UTF-8 mode [BUSY]
\e%G\e%G [DONE]
:: Loading Keyboard Map: fr-pc [DONE]
:: Loading Console Font: ter-g14n [BUSY]
\e(K\e(K [DONE]
INIT: Entering runlevel: 5
:: Starting Syslog-NG [DONE]
:: Starting D-BUS system messagebus [DONE]
:: Starting acpid [DONE]
:: Restoring ALSA Levels [DONE]
:: Starting Network [BUSY] [DONE]
:: Starting Cron Daemon [DONE]
:: Starting Hardware Abstraction Layer [DONE]
:: Starting bluetooth subsystem: [BUSY] hcid [DONE]
:: Starting gpm [BKGD] :: Starting cups [BKGD] :: Starting arch32 [BKGD] :: Starting ifplugd [BKGD] :: Starting avahi-daemon [BKGD] /bin/stty: standard input: Inappropriate ioctl for device
/bin/stty: standard input: Inappropriate ioctl for device
/bin/stty: standard input: Inappropriate ioctl for device
/bin/stty: standard input: Inappropriate ioctl for device
/bin/stty: standard input: Inappropriate ioctl for device
:: Starting Avahi mDNS/DNS-SD Daemon 9G [BUSY] :: Starting Arch32 chroot 9G [BUSY] :: Starting GPM Daemon 9G [BUSY] :: Starting CUPS Daemon 9G [BUSY] 9G [DONE]
:: Starting ifplugd 9G [BUSY] 9G [DONE]
9G [DONE]
[: 14: /bin/bash: unexpected operator
9G [DONE]
eth0 wlan09G [DONE]it is interesting, because it seems to uncover some initscripts issues unrelated to dash.
first, we see that a number of /bin/rm fail. from rc.sysinit:
stat_busy "Removing Leftover Files"
/bin/rm -f /etc/nologin &>/dev/null
/bin/rm -f /etc/shutdownpid &>/dev/null
/bin/rm -f /var/lock/* &>/dev/null
/bin/rm -rf /tmp/* /tmp/.* &>/dev/null
/bin/rm -f /forcefsck &>/dev/null
(cd /var/run && /usr/bin/find . ! -type d -exec /bin/rm -f -- {} \; )
: > /var/run/utmp
# Keep {x,k,g}dm happy with xorg
/bin/mkdir /tmp/.ICE-unix && /bin/chmod 1777 /tmp/.ICE-unix
/bin/mkdir /tmp/.X11-unix && /bin/chmod 1777 /tmp/.X11-unix
stat_donefor starters, '&>' should be replaced by '2>&1 >/dev/null' for use with (da)sh.
this is certainly related to the previous shutdown which may not have run things properly (but I couldn't capture it). yet some (all) of these dirs may need to be cleaned at startup, yet rm has no -r there.
second, there seem to be an issue to display escape codes properly: at the beginning everything is displayed properly with nice colors, then things start to go wrong. you can see that 'starting network' has issues, and indeed, it is not displayed properly, without colors at all, when the ones around it just work. the same goes for bluetooth, but then, background started jobs just display wrong. also, font setting and utf-8 switching display escape code as-is. maybe this is due to a bashism WRT escaping too.
the same kind of issue appears on shutdown.
also, there is this "[: 14: /bin/bash: unexpected operator" issue that I'm still tracking down.
Last edited by lloeki (2008-06-23 14:57:22)
To know recursion, you must first know recursion.
Offline
Well in ubuntu the #!/bin/bash (script header) did nothing because sh would always run dash
some scripts would not work because they were bash scripts and dash did not start them correctly.
anyway: bash is more used, but I guess I prefer it faster, and migrating is not a problem.
+1 for dash
If people do not believe that mathematics is simple, it is only because they do not realize how complicated life is.
Simplicity is the ultimate sophistication.
Offline
Offline