Re: [arch-general] [PATCH 1/2] kill_everything: Reduce number of -f tests

2010-09-09 Thread Victor Lowther


Thomas Bächler tho...@archlinux.org wrote:

Am 08.09.2010 06:16, schrieb Victor Lowther:
 On Tue, Sep 7, 2010 at 10:47 PM, Dave Reisner d...@falconindy.com
wrote:
 Instead of checking for the existance of a file in /var/run/daemons
on
 every iteration, handle the null case by setting nullglob. The shopt
 call is done inside a subshell as to not bother the environment
since we
 may be going to runlevel 1 only temporarily.
 
 I thought about just enabling nullglobs and extglobs unconditionally
 in functions, but decided that was too likely to get objections no
 matter how unlikely breakage was. :)

As for nullglob, I do think it is useful and enabling it might be
useful
in so many places - I didn't even know this option, it would have been
useful for me before. I am in favor of enabling nullglob in function
and
dropping that subshell.

Sounds good to me - nullglob is useful in general,  and enabling it should not 
break anything else in the initscripts package. 

Do we need extglob anywhere? I don't think so.

I will take a look.

-- 
Sent from my Nexus One with K-9 Mail. Please excuse my brevity.


Re: [arch-general] [PATCH 1/2] kill_everything: Reduce number of -f tests

2010-09-09 Thread Victor Lowther


Nathan Wayde kum...@konnichi.com wrote:

On 09/09/10 16:19, Victor Lowther wrote:


 Thomas Bächlertho...@archlinux.org  wrote:

 Am 08.09.2010 06:16, schrieb Victor Lowther:
 On Tue, Sep 7, 2010 at 10:47 PM, Dave Reisnerd...@falconindy.com
 wrote:
 Instead of checking for the existance of a file in
/var/run/daemons
 on
 every iteration, handle the null case by setting nullglob. The
shopt
 call is done inside a subshell as to not bother the environment
 since we
 may be going to runlevel 1 only temporarily.

 I thought about just enabling nullglobs and extglobs
unconditionally
 in functions, but decided that was too likely to get objections no
 matter how unlikely breakage was. :)

 As for nullglob, I do think it is useful and enabling it might be
 useful
 in so many places - I didn't even know this option, it would have
been
 useful for me before. I am in favor of enabling nullglob in function
 and
 dropping that subshell.

 Sounds good to me - nullglob is useful in general,  and enabling it
should not break anything else in the initscripts package.

 Do we need extglob anywhere? I don't think so.

 I will take a look.


I don't see anywhere in the initscripts that has this issue but you 
might want to take a look at dotglob for the future, because with 
nullglob you break the behaviour of commands that work like ls. i.e `ls

*.ext` etc. would result in ls being passed an argument '*.ext' in the 
event that *.ext doesn't match anything. With nullglob set, no argument

gets passed and you end up with just `ls` which is likely to cause 
subtle bugs.

Sounds like another reason to never parse the output of ls in a shell script ( 
not that I needed more).
-- 
Sent from my Nexus One with K-9 Mail. Please excuse my brevity.


Re: [arch-general] [PATCH 01/48] Bashification of initscripts

2010-09-07 Thread Victor Lowther
On Tue, Sep 7, 2010 at 3:32 PM, Thomas Bächler tho...@archlinux.org wrote:
 Am 30.06.2010 23:47, schrieb Victor Lowther:
 Despite efforts to make the initscripts POSIX, we use bash 4.0 features.

 Bashifying this framework should result in about a 30% speedup, assuming no
 IO latency and that all programs we call also take zero time. :)

 I just pushed the patches - I was going to do more review of some of
 them, but I am apparently too busy. Please post any patches (especially
 if a correction of patch 21 is needed, I haven't finished reading the
 discussion) rebased on the current initscripts.git.

Your last patch has a typo (missed close paren):

diff --git a/rc.sysinit b/rc.sysinit
index b25f7ac..dc916a2 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -275,7 +275,7 @@ stat_busy Removing Leftover Files
 /bin/rm -f /var/lock/* /dev/null
 /bin/rm -rf /tmp/* /tmp/.* /dev/null
 /bin/rm -f /forcefsck /dev/null
-[[ -d /var/run ]]  /usr/bin/find /var/run/ \! -type d -delete  )
+[[ -d /var/run ]]  /usr/bin/find /var/run/ \! -type d -delete
 : | /var/run/utmp
 /bin/chmod 0664 /var/run/utmp
 # Keep {x,k,g}dm happy with xorg


Re: [arch-general] [PATCH 01/48] Bashification of initscripts

2010-09-07 Thread Victor Lowther
On Tue, Sep 7, 2010 at 10:47 PM, Dave Reisner d...@falconindy.com wrote:
 On Tue, Sep 07, 2010 at 10:32:28PM +0200, Thomas Bächler wrote:
 Am 30.06.2010 23:47, schrieb Victor Lowther:
  Despite efforts to make the initscripts POSIX, we use bash 4.0 features.
 
  Bashifying this framework should result in about a 30% speedup, assuming no
  IO latency and that all programs we call also take zero time. :)

 I just pushed the patches - I was going to do more review of some of
 them, but I am apparently too busy. Please post any patches (especially
 if a correction of patch 21 is needed, I haven't finished reading the
 discussion) rebased on the current initscripts.git.


 I'm noticing that in general, the vim modelines aren't followed. Not
 sure what editor was used to rebase these scripts, but the mix of tabs
 and spaces for indents is somewhat irritating. I'm about to send a pair of
 patches (neither of which address this) but which follow the modeline.

Blame my ongoing Emacs education. I learned about
(custom-set-variables '(indent-tabs-mode nil)) after doing most of the
work, and dropped the whitespace cleanup patches due to size.

Otherwise, I ignored the vim modelines -- 2 characters per indentation
is not really enough, and most of the preexisting code happily ignored
it anyways.

 d



Re: [arch-general] [PATCH 1/2] kill_everything: Reduce number of -f tests

2010-09-07 Thread Victor Lowther
On Tue, Sep 7, 2010 at 10:47 PM, Dave Reisner d...@falconindy.com wrote:
 Instead of checking for the existance of a file in /var/run/daemons on
 every iteration, handle the null case by setting nullglob. The shopt
 call is done inside a subshell as to not bother the environment since we
 may be going to runlevel 1 only temporarily.

I thought about just enabling nullglobs and extglobs unconditionally
in functions, but decided that was too likely to get objections no
matter how unlikely breakage was. :)

 ---
  functions |    4 +++-
  1 files changed, 3 insertions(+), 1 deletions(-)

 diff --git a/functions b/functions
 index b9ba718..7a0c4f8 100644
 --- a/functions
 +++ b/functions
 @@ -206,11 +206,13 @@ kill_everything() {
     # $1 = where we are being called from.
     # This is used to determine which hooks to run.
     # Find daemons NOT in the DAEMONS array. Shut these down first
 +    (
 +    shopt -s nullglob
     for daemon in /var/run/daemons/*; do
 -        [[ -f $daemon ]] || continue
         daemon=${daemon##*/}
        in_array $daemon ${daemo...@]} || stop_daemon $daemon
     done
 +    )

     # Shutdown daemons in reverse order
     for ((i=${#daemo...@]}-1; i=0; i--)); do
 --
 1.7.2.3




Re: [arch-general] [PATCH 21/48] Both rc.single and rc.shutdown use the same code to kill everything.

2010-09-01 Thread Victor Lowther
On Wed, Sep 1, 2010 at 5:41 AM, Kurt J. Bosch
kjb-temp-2...@alpenjodel.de wrote:
 2010-08-31 13:16, Dave Reisner:

 On Tue, Aug 31, 2010 at 10:07:52AM +0200, Kurt J. Bosch wrote:

 --snip--

 I suggest:

  From b202be97f8dc1c0c68aaea792d4457c674c673f3 Mon Sep 17 00:00:00 2001
 From: Kurt J. Boschkjb-temp-2...@alpenjodel.de
 Date: Tue, 31 Aug 2010 09:57:47 +0200
 Subject: [PATCH 17/17] Correct behaviour of kill_everything()

 ---
  functions |   11 +--
  1 files changed, 5 insertions(+), 6 deletions(-)

 diff --git a/functions b/functions
 index b9ba718..3ca7324 100644
 --- a/functions
 +++ b/functions
 @@ -205,10 +205,9 @@ ck_status() {
  kill_everything() {
      # $1 = where we are being called from.
      # This is used to determine which hooks to run.
 -    # Find daemons NOT in the DAEMONS array. Shut these down first
 -    for daemon in /var/run/daemons/*; do
 -        [[ -f $daemon ]] || continue
 -        daemon=${daemon##*/}
 +    # Find daemons NOT in the DAEMONS array.
 +    # Shut these down first in reverse order.
 +    for daemon in $( /bin/ls -t /var/run/daemons ); do
        in_array $daemon ${daemo...@]} || stop_daemon $daemon
      done

 @@ -220,7 +219,7 @@ kill_everything() {

        # Terminate all processes
      stat_busy Sending SIGTERM To Processes
 -    run_hook $1_prekillall
 +    run_hook ${1}_prekillall
      /sbin/killall5 -15  /dev/null
      /bin/sleep 5
      stat_done
 @@ -230,7 +229,7 @@ kill_everything() {
      /bin/sleep 1
      stat_done

 -    run_hook $1_postkillall
 +    run_hook ${1}_postkillall
  }

  activate_vgs() {
 --
 1.7.0.3


 Parsing the output of ls will never be better than using shell globbing
 no matter how much simpler it might make the code appear to be. Not only
 are you avoiding a fork, but the shell glob will properly handle any odd
 characters thrown into the mix. You'll see breakage on something as
 simple as a space in your suggestion. While I'm inclined to believe that
 there will never be a space in the name of a daemon in Arch, if we're
 going for pure Bash in this rewrite, let's use Bash instead of
 mindlessly forking.

 NAK. The patch just reverts breaking of the current behaviour which is
 shutdown daemons in reverse order of start. AFAIK bash globbing is unable to
 sort on timestamps, right?

Bash globbing cannot handle it, but bash knows how to test file
timestamps, so we could code something up that handles killing the
daemons in reverse timestamp order if we had to. However, there is no
reason to think that the order is significant for daemons not in
$DAEMONS.  If there are any dependencies that this code does not
handle gracefully, the offending daemons will be killed when we kill
-15 and then kill -9 the rest of the processes.  If a daemon does not
handle SIGTERM gracefully because of dependency issues, it has other,
more significant problems.


Re: [arch-general] [PATCH 28/48] Use bash-style conditionals when setting up the hardware clock.

2010-09-01 Thread Victor Lowther
On Fri, Aug 20, 2010 at 2:12 AM, Kurt J. Bosch
kjb-temp-2...@alpenjodel.de wrote:
 On 2010-08-19 23:12, Victor Lowther wrote:

 On Aug 19, 2010 10:08 AM, Kurt J. Boschkjb-temp-2...@alpenjodel.de
 wrote:

 On 2010-08-19 10:19, Jan de Groot wrote:

 On Thu, 2010-08-19 at 00:56 -0400, Dave Reisner wrote:

 Couldn't we avoid all this by just flipping a switch in the kernel?

 CONFIG_RTC_DRV_CMOS=y

 If it's compiled into the kernel, udev picks it up and creates
 the /dev
 nodes for us.

 Which still locks out the people who use a custom kernel with this
 driver compiled as module. IMHO the init scripts should work with both
 module and built-in.


 So why not let udev do the job? Patch below. I modified my initcpio to
 get rid of the devtmpfs. A ls -l /dev/rtc* added between the new
 /sbin/udevadm settle and the initial clock setting showed /dev/rtc0 and
 /dev/rtc -  rtc0. So I think this should work.

 I did *not* move the sysinit_udevlaunched hook together with udev start
 to avoid insane creation times of dev nodes because this hook is used
 for some early udev triggering in fbsplash-extras (AUR).

 Patch against bashification-redux:

  From 22d410a2566964d58752d443a1312a6eb552660a Mon Sep 17 00:00:00 2001
 From: Kurt J. Boschkjb-temp-2...@alpenjodel.de
 Date: Thu, 19 Aug 2010 16:46:23 +0200
 Subject: [PATCH 17/17] Correct rtc dev nodes creation using udev

 ---
 rc.sysinit | 22 +++---
 1 files changed, 7 insertions(+), 15 deletions(-)

 diff --git a/rc.sysinit b/rc.sysinit
 index 4421def..2415967 100755
 --- a/rc.sysinit
 +++ b/rc.sysinit
 @@ -46,6 +46,12 @@ else
 /bin/dmesg -n 3
 fi

 +echo  /proc/sys/kernel/hotplug
 +
 +stat_busy Starting UDev Daemon
 +/sbin/udevd --daemon
 +stat_done
 +
 HWCLOCK_PARAMS=--hctosys
 case $HARDWARECLOCK in
 UTC) HWCLOCK_PARAMS+= --utc;;
 @@ -56,15 +62,7 @@ esac
 if [[ $HWCLOCK_PARAMS ]]; then
 # enable rtc access
 /sbin/modprobe -q -a rtc-cmos rtc genrtc
 - # If devtmpfs is used, the required RTC device already exists now
 - # Otherwise, create whatever device is available
 - if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then
 - for dev in /sys/class/rtc/rtc0/dev /sys/class/misc/rtc/dev; do
 - [[ -e $dev ]] || continue
 - IFS=: read -r major minor  $dev
 - /bin/mknod /dev/rtc c $major $minor
 - done
 - fi
 + /sbin/udevadm settle

 # Do a clock set here for a few reasons:
 # 1. Make creation time on udev nodes sane (FS#8665)
 @@ -79,12 +77,6 @@ if [[ $HWCLOCK_PARAMS ]]; then
 fi
 fi

 -echo  /proc/sys/kernel/hotplug
 -
 -stat_busy Starting UDev Daemon
 -/sbin/udevd --daemon
 -stat_done
 -
 run_hook sysinit_udevlaunched

 # Trigger udev uevents
 --
 1.7.2.1



 I like this one the best.

 Sent from my Nexus One. Sorry for top posting.

 Corrected

 Hmm, the patch might break things with custom non modular kernels without
 devtmpfs though. No modules loading no uevents and no dev nodes. On the
 other hand reading the hwclock man page, I'm a bit uncertain whether that
 piece will ever use /dev/rtc0 without a symlink from /dev/rtc. Instead it
 might actually fall back to direct I/O with the current code and with the
 patched one too.

 Moreover I found a couple of interesting things:
 * The system clock is already set (by the kernel - in spite of
 CONFIG_RTC_HCTOSYS not set) even without doing anything. Weird, but with UTC
 hardware clock I even get correct mtimes in early user space.
 * man hwclock:
 --systz
 Reset the System Time based on the current timezone.
 ...
 This is an alternate option to --hctosys that does not read the
 hardware clock, and may be used in system startup scripts for recent
 2.6 kernels where you know the System Time contains the Hardware
 Clock time.
 I switched my hardware clock to localtime, reverted my patch and modified
 rc.sysinit to use -systz instead of --hctosys for the first hwclock call and
 also disabled the entire rtc modprobe and mknod code. A date command
 inserted for testing spit out the correct time.
 From the util-linux-ng list:
 Indeed, we may be running hwclock --systz before /dev is mounted.
 Getting rid of the pre fsck hwclock --hctosys would also on the average save
 another half second of boot up time beside removing some ugly code.

 AFAIKS we can go one of three ways:
 * Use udev expecting CONFIG_RTC_DRV_CMOS=m or fall back to direct I/O
 * Use --systz, drop the ugly code and expect some help from the kernel
 * Use an even more ugly code creating the missing symlink:

 Corrected non udev patch against bashification-redux:

 From 4e5d6a763af8f45c63ad53aa99b82246f90c0b43 Mon Sep 17 00:00:00 2001
 From: Kurt J. Bosch kjb-temp-2...@alpenjodel.de
 Date: Fri, 20 Aug 2010 09:04:46 +0200
 Subject: [PATCH 17/17] Really correct rtc dev nodes creation

 ---
  rc.sysinit |   15 +--
  1 files changed, 9 insertions(+), 6 deletions(-)

 diff --git a/rc.sysinit b/rc.sysinit
 index 4421def..1ff37cc 100755
 --- a/rc.sysinit
 +++ b/rc.sysinit
 @@ -58,12 +58,15 @@ if [[ $HWCLOCK_PARAMS ]]; then
/sbin/modprobe -q

Re: [arch-general] [PATCH 28/48] Use bash-style conditionals when setting up the hardware clock.

2010-08-19 Thread Victor Lowther
I like this one the best.

Sent from my Nexus One. Sorry for top posting.

On Aug 19, 2010 10:08 AM, Kurt J. Bosch kjb-temp-2...@alpenjodel.de
wrote:
 Am 2010-08-19 10:19, schrieb Jan de Groot:
 On Thu, 2010-08-19 at 00:56 -0400, Dave Reisner wrote:
 Couldn't we avoid all this by just flipping a switch in the kernel?

 CONFIG_RTC_DRV_CMOS=y

 If it's compiled into the kernel, udev picks it up and creates
 the /dev
 nodes for us.

 Which still locks out the people who use a custom kernel with this
 driver compiled as module. IMHO the init scripts should work with both
 module and built-in.


 So why not let udev do the job? Patch below. I modified my initcpio to
 get rid of the devtmpfs. A ls -l /dev/rtc* added between the new
 /sbin/udevadm settle and the initial clock setting showed /dev/rtc0 and
 /dev/rtc - rtc0. So I think this should work.

 I did *not* move the sysinit_udevlaunched hook together with udev start
 to avoid insane creation times of dev nodes because this hook is used
 for some early udev triggering in fbsplash-extras (AUR).

 Patch against bashification-redux:

 From 22d410a2566964d58752d443a1312a6eb552660a Mon Sep 17 00:00:00 2001
 From: Kurt J. Bosch kjb-temp-2...@alpenjodel.de
 Date: Thu, 19 Aug 2010 16:46:23 +0200
 Subject: [PATCH 17/17] Correct rtc dev nodes creation using udev

 ---
 rc.sysinit | 22 +++---
 1 files changed, 7 insertions(+), 15 deletions(-)

 diff --git a/rc.sysinit b/rc.sysinit
 index 4421def..2415967 100755
 --- a/rc.sysinit
 +++ b/rc.sysinit
 @@ -46,6 +46,12 @@ else
 /bin/dmesg -n 3
 fi

 +echo  /proc/sys/kernel/hotplug
 +
 +stat_busy Starting UDev Daemon
 +/sbin/udevd --daemon
 +stat_done
 +
 HWCLOCK_PARAMS=--hctosys
 case $HARDWARECLOCK in
 UTC) HWCLOCK_PARAMS+= --utc;;
 @@ -56,15 +62,7 @@ esac
 if [[ $HWCLOCK_PARAMS ]]; then
 # enable rtc access
 /sbin/modprobe -q -a rtc-cmos rtc genrtc
 - # If devtmpfs is used, the required RTC device already exists now
 - # Otherwise, create whatever device is available
 - if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then
 - for dev in /sys/class/rtc/rtc0/dev /sys/class/misc/rtc/dev; do
 - [[ -e $dev ]] || continue
 - IFS=: read -r major minor  $dev
 - /bin/mknod /dev/rtc c $major $minor
 - done
 - fi
 + /sbin/udevadm settle

 # Do a clock set here for a few reasons:
 # 1. Make creation time on udev nodes sane (FS#8665)
 @@ -79,12 +77,6 @@ if [[ $HWCLOCK_PARAMS ]]; then
 fi
 fi

 -echo  /proc/sys/kernel/hotplug
 -
 -stat_busy Starting UDev Daemon
 -/sbin/udevd --daemon
 -stat_done
 -
 run_hook sysinit_udevlaunched

 # Trigger udev uevents
 --
 1.7.2.1




Re: [arch-general] [PATCH 28/48] Use bash-style conditionals when setting up the hardware clock.

2010-08-18 Thread Victor Lowther
I am missing the difference. Diff please?

Sent from my Nexus One

On Aug 18, 2010 2:41 AM, Kurt J. Bosch kjb-temp-2...@alpenjodel.de
wrote:
 Am 2010-06-30 23:47, schrieb Victor Lowther:
 Trying to stick with POSIX syntax only just slows things down.
 ---
 rc.sysinit | 27 +++
 1 files changed, 11 insertions(+), 16 deletions(-)

 diff --git a/rc.sysinit b/rc.sysinit
 index 29adeca..f3e60b7 100755
 --- a/rc.sysinit
 +++ b/rc.sysinit
 @@ -44,27 +44,22 @@ fi

 HWCLOCK_PARAMS=--hctosys
 case $HARDWARECLOCK in
 - UTC) $HWCLOCK_PARAMS --utc;;
 - localtime) HWCLOCK_PARAMS=$HWCLOCK_PARAMS --localtime;;
 + UTC) HWCLOCK_PARAMS+= --utc;;
 + localtime) HWCLOCK_PARAMS+= --localtime;;
 *) HWCLOCK_PARAMS=;;
 esac

 -if [ -n $HWCLOCK_PARAMS ]; then
 +if [[ $HWCLOCK_PARAMS ]]; then
 # enable rtc access
 - /sbin/modprobe -q rtc-cmos
 - # some custom kernels use rtc/genrtc, try to load those too
 - /sbin/modprobe -q rtc
 - /sbin/modprobe -q genrtc
 + /sbin/modprobe -q -a rtc-cmos rtc genrtc
 # If devtmpfs is used, the required RTC device already exists now
 # Otherwise, create whatever device is available
 - if [ ! -c /dev/rtc -a ! -c /dev/rtc0 ]; then
 - if [ -f /sys/class/rtc/rtc0/dev ]; then
 - IFS=: read -r major minor /sys/class/rtc/rtc0/dev
 - /bin/mknod /dev/rtc0 c $major $minor
 - elif [ -f /sys/class/misc/rtc/dev ]; then
 - IFS=: read -r major minor /sys/class/misc/rtc/dev
 - /bin/mknod /dev/rtc c $major $minor
 - fi
 + if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then
 + for dev in /sys/class/rtc/rtc0/dev /sys/class/misc/rtc/dev; do
 + [[ -e $dev ]] || continue
 + IFS=: read -r major minor $dev
 + /bin/mknod /dev/rtc c $major $minor
 + done
 fi

 Actually this doesn't do the same. What about the following?

 if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then
 for dev in /sys/class/rtc/rtc0 /sys/class/misc/rtc; do
 [[ -e $dev/dev ]] || continue
 IFS=: read -r major minor $dev/dev
 /bin/mknod /dev/${dev##*/} c $major $minor
 done
 fi



Re: [arch-general] [PATCH 01/48] Bashification of initscripts

2010-08-01 Thread Victor Lowther
On Sat, Jul 31, 2010 at 11:54 AM, Thomas Bächler tho...@archlinux.org wrote:
 Am 31.07.2010 18:44, schrieb Victor Lowther:
 On Fri, Jul 23, 2010 at 5:51 PM, Thomas Bächler tho...@archlinux.org wrote:
 Am 23.07.2010 22:58, schrieb Victor Lowther:
 After looking over it again, you are correct -- split into array does
 not do The Right Thing here.  It will be easy to fix -- by the time
 you read this it will have been fixed and rebased back into
 bashification-redux.

 It is, thanks. I'll have to look at that in more detail when I am less
 tired. When that's done, I can release new initscripts so we can do
 lng testing.

 How goes the rest of the review?


 I only wanted to have a closer look at the cryptsetup patch before I
 pull this into master. But as you noticed, I didn't take the time to do
 so yet.

No problem.  Anything I can do to help?


Re: [arch-general] [PATCH 01/48] Bashification of initscripts

2010-07-31 Thread Victor Lowther
On Fri, Jul 23, 2010 at 5:51 PM, Thomas Bächler tho...@archlinux.org wrote:
 Am 23.07.2010 22:58, schrieb Victor Lowther:
 After looking over it again, you are correct -- split into array does
 not do The Right Thing here.  It will be easy to fix -- by the time
 you read this it will have been fixed and rebased back into
 bashification-redux.

 It is, thanks. I'll have to look at that in more detail when I am less
 tired. When that's done, I can release new initscripts so we can do
 lng testing.

How goes the rest of the review?


Re: [arch-general] [PATCH 01/48] Bashification of initscripts

2010-07-23 Thread Victor Lowther
On Fri, Jul 23, 2010 at 7:29 AM, Thomas Bächler tho...@archlinux.org wrote:
 Am 17.07.2010 16:24, schrieb Victor Lowther:
 Sorry for taking so long. Apart from squashing the trivial
 bashifications, all patches I didn't comment on are ACKed.

 That is cool.  I went ahead and reworked/squashed everthing I considered
 a trivial bashification into 6 or 7 patches after taking into account
 the feedback from the ML.  The result is the bashification-redux branch
 @ git://fnordovax.org/~victor/arch-initscripts -- it is now 16 patches
 instead of 48, but the end result is exactly the same. I can post it to
 the ML if you like.

 I looked over the new branch and found it much more readable. And
 although some of the patches are not 100% clean yet (at least one
 contains a trivial change that wasn't advertised in the commit), I like it.

 Just a remark about the cryptsetup/crypttab rework (that one is scary,
 and I didn't read it in details yet): The last column of crypttab can
 contain space, meaning that everything past the fourth column will be
 treated as one column (the options column). Did you take that into
 account? I don't think so.

After looking over it again, you are correct -- split into array does
not do The Right Thing here.  It will be easy to fix -- by the time
you read this it will have been fixed and rebased back into
bashification-redux.

 I know that crypttab is ugly and scary, and I was planning to replace it
 with something sane, I just never got around to actually doing it.


[arch-general] [PATCH 2/4] Add very basic transaction hooks to alpm.

2010-07-23 Thread Victor Lowther
libalpm compliant programs now support running pre-commit and post-commit
hooks.  Currently, the implementation is as simple as I can make it --
if /etc/pacman.d/hooks.d/transact.sh exists, it will be run with the
'pre-commit' parameter just before a transaction is committed, and it will
be run with 'post-commit' after the transaction has been completed.

The intent is for transact.sh to be a wrapper that calls scripts in
/etc/pacman.d/hooks.d/transact.d with the arg it is passed, but since this
is just for a demo I did not actually include any of that.

I also didn't bother adhering to any of the coding standards, as that will
be easy enough to fix up once we have something a bit more fleshed out.
---
 lib/libalpm/hooks.c |   28 
 lib/libalpm/hooks.h |4 
 lib/libalpm/trans.c |4 +++-
 3 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/lib/libalpm/hooks.c b/lib/libalpm/hooks.c
index 9630c70..5982ea5 100644
--- a/lib/libalpm/hooks.c
+++ b/lib/libalpm/hooks.c
@@ -30,6 +30,7 @@
 #include sys/types.h
 #include sys/stat.h
 #include sys/statvfs.h
+#include sys/wait.h
 #include errno.h
 
 /* libalpm */
@@ -46,3 +47,30 @@
 #include alpm.h
 #include deps.h
 #include cache.h
+
+int alpm_hook_transact(char* phase) {
+  char filename[PATH_MAX];
+  struct stat sbuf;
+  pid_t childpid, retpid;
+  int status;
+  /* ignore transaction hooks when targeting another root filesystem
+  if (!strcmp(handle-root,/))
+  return 1;*/
+  snprintf(filename,PATH_MAX,%s/transact.sh,ALPM_HOOKS_DIR);
+  /* if we cannot stat transact.sh, just return */
+  if (stat(filename,sbuf) != 0)
+return 1;
+  fflush(NULL);
+  childpid=fork();
+  if (childpid == -1) {
+return 1;
+  } else if (childpid == 0) {
+execl(filename,transact.sh,phase,(char *)0);
+  } else {
+/* return the exit status of the transact.sh program. */
+do {
+  retpid = waitpid(childpid,status,0);
+} while (!WIFEXITED(status)  !WIFSIGNALED(status));
+  }
+  return !WEXITSTATUS(status);
+}
diff --git a/lib/libalpm/hooks.h b/lib/libalpm/hooks.h
index d60b1f4..f79d2c4 100644
--- a/lib/libalpm/hooks.h
+++ b/lib/libalpm/hooks.h
@@ -25,4 +25,8 @@
 
 #include alpm.h
 
+#define ALPM_HOOKS_DIR /etc/pacman.d/hooks.d
+
+int alpm_hook_transact(char*);
+
 #endif /*ALPM_HOOKS_H */
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index 523f33b..ed26aa6 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -195,7 +195,8 @@ int SYMEXPORT alpm_trans_commit(alpm_list_t **data)
if(trans-add == NULL  trans-remove == NULL) {
return(0);
}
-
+if (! alpm_hook_transact(pre-commit))
+  return (-1);
trans-state = STATE_COMMITING;
 
if(trans-add == NULL) {
@@ -211,6 +212,7 @@ int SYMEXPORT alpm_trans_commit(alpm_list_t **data)
}
 
trans-state = STATE_COMMITED;
+alpm_hook_transact(post-commit);
 
return(0);
 }
-- 
1.7.1.1



[arch-general] [PATCH 1/4] Add skeleton for hooks support

2010-07-23 Thread Victor Lowther
This begins work on adding some sort of hook infrastructure to pacman.
There has been much discussion and little code that I have seen, so I figured
I would go ahead an implement a very basic skeleton for transaction hooks
support.

---
 lib/libalpm/Makefile.am |1 +
 lib/libalpm/{sync.h = hooks.c} |   34 +-
 lib/libalpm/{add.h = hooks.h}  |   19 ---
 3 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/lib/libalpm/Makefile.am b/lib/libalpm/Makefile.am
index 3473a73..b4fdadf 100644
--- a/lib/libalpm/Makefile.am
+++ b/lib/libalpm/Makefile.am
@@ -44,6 +44,7 @@ libalpm_la_SOURCES = \
sync.h sync.c \
trans.h trans.c \
util.h util.c \
+   hooks.h hooks.c \
version.c
 
 libalpm_la_LDFLAGS = -no-undefined -version-info $(LIB_VERSION_INFO)
diff --git a/lib/libalpm/sync.h b/lib/libalpm/hooks.c
similarity index 65%
copy from lib/libalpm/sync.h
copy to lib/libalpm/hooks.c
index 000a09c..9630c70 100644
--- a/lib/libalpm/sync.h
+++ b/lib/libalpm/hooks.c
@@ -1,9 +1,10 @@
 /*
- *  sync.h
+ *  hooks.c
  *
  *  Copyright (c) 2006-2010 Pacman Development Team pacman-...@archlinux.org
  *  Copyright (c) 2002-2006 by Judd Vinet jvi...@zeroflux.org
  *  Copyright (c) 2005 by Aurelien Foret orel...@chez.com
+ *  Copyright (c) 2005 by Christian Hamar kr...@linuxforum.hu
  *  Copyright (c) 2005, 2006 by Miklos Vajna vmik...@frugalware.org
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,14 +20,29 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see http://www.gnu.org/licenses/.
  */
-#ifndef _ALPM_SYNC_H
-#define _ALPM_SYNC_H
 
-#include alpm.h
-
-int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t 
*dbs_sync, alpm_list_t **data);
-int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data);
+#include config.h
 
-#endif /* _ALPM_SYNC_H */
+#include stdlib.h
+#include stdio.h
+#include string.h
+#include unistd.h
+#include sys/types.h
+#include sys/stat.h
+#include sys/statvfs.h
+#include errno.h
 
-/* vim: set ts=2 sw=2 noet: */
+/* libalpm */
+#include hooks.h
+#include trans.h
+#include alpm_list.h
+#include package.h
+#include util.h
+#include log.h
+#include handle.h
+#include add.h
+#include remove.h
+#include sync.h
+#include alpm.h
+#include deps.h
+#include cache.h
diff --git a/lib/libalpm/add.h b/lib/libalpm/hooks.h
similarity index 73%
copy from lib/libalpm/add.h
copy to lib/libalpm/hooks.h
index eb37dc7..d60b1f4 100644
--- a/lib/libalpm/add.h
+++ b/lib/libalpm/hooks.h
@@ -1,8 +1,11 @@
 /*
- *  add.h
+ *  hooks.h
  *
  *  Copyright (c) 2006-2010 Pacman Development Team pacman-...@archlinux.org
  *  Copyright (c) 2002-2006 by Judd Vinet jvi...@zeroflux.org
+ *  Copyright (c) 2005 by Aurelien Foret orel...@chez.com
+ *  Copyright (c) 2005 by Christian Hamar kr...@linuxforum.hu
+ *  Copyright (c) 2006 by Miklos Vajna vmik...@frugalware.org
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -17,15 +20,9 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see http://www.gnu.org/licenses/.
  */
-#ifndef _ALPM_ADD_H
-#define _ALPM_ADD_H
+#ifndef _ALPM_HOOKS_H
+#define _ALPM_HOOKS_H
 
-#include db.h
-#include alpm_list.h
-#include trans.h
+#include alpm.h
 
-int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db);
-
-#endif /* _ALPM_ADD_H */
-
-/* vim: set ts=2 sw=2 noet: */
+#endif /*ALPM_HOOKS_H */
-- 
1.7.1.1



[arch-general] [PATCH 3/4] Add a PKGBUILD for easy testing.

2010-07-23 Thread Victor Lowther
We don't need the whole usual pkgbuild, but having one in the git tree sure
makes testing simpler.

---
 PKGBUILD |   60 
 1 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000..16cf977
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,60 @@
+# $Id: PKGBUILD 83376 2010-06-21 12:52:09Z dan $
+# Maintainer: Aaron Griffin aa...@archlinux.org
+# Maintainer: Dan McGee d...@archlinux.org
+
+pkgname=pacman-git
+pkgver=$(date +%s)
+pkgrel=$(git log --pretty=format:%h |head -n 1)
+pkgdesc=A library-based package manager with dependency support
+arch=('i686' 'x86_64')
+url=http://www.archlinux.org/pacman/;
+license=('GPL')
+groups=('base')
+depends=('bash' 'libarchive=2.7.1' 'libfetch=2.25' 'pacman-mirrorlist')
+makedepends=('asciidoc')
+optdepends=('fakeroot: for makepkg usage as normal user')
+provides=('pacman=')
+backup=('etc/pacman.conf' 'etc/makepkg.conf')
+conflicts=('pacman')
+options=(!libtool)
+
+build() {
+  cd ..
+  ./autogen.sh
+  ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-doc
+  make || return 1
+}
+
+package() {
+  cd $srcdir/..
+  srcdir=$PWD
+  make DESTDIR=$pkgdir install || return 1
+
+  # install Arch specific stuff
+  mkdir -p $pkgdir/etc
+  # set things correctly in the default conf file
+  case $CARCH in
+i686)
+  mycarch=i686
+  mychost=i686-pc-linux-gnu
+  myflags=-march=i686 
+  ;;
+x86_64)
+  mycarch=x86_64
+  mychost=x86_64-unknown-linux-gnu
+  myflags=-march=x86-64 
+  ;;
+  esac
+  sed -i $pkgdir/etc/makepkg.conf \
+-e s|@car...@]|$mycarch|g \
+-e s|@cho...@]|$mychost|g \
+-e s|@carchfla...@]|$myflags|g
+
+  # install completion files
+  mkdir -p $pkgdir/etc/bash_completion.d/
+  install -m644 contrib/bash_completion $pkgdir/etc/bash_completion.d/pacman
+  mkdir -p $pkgdir/usr/share/zsh/site-functions/
+  install -m644 contrib/zsh_completion 
$pkgdir/usr/share/zsh/site-functions/_pacman
+}
+
+# vim: set ts=2 sw=2 et:
-- 
1.7.1.1



[arch-general] [PATCH 4/4] Add INTERRUPTED to transaction hooks support.

2010-07-23 Thread Victor Lowther
If a transaction is interrupted, the hooks need to know so that they
can roll back anything that needs to be rolled back.
---
 lib/libalpm/trans.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index ed26aa6..d212f50 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -235,6 +235,7 @@ int SYMEXPORT alpm_trans_interrupt()
RET_ERR(PM_ERR_TRANS_TYPE, -1));
 
trans-state = STATE_INTERRUPTED;
+alpm_hook_transact(INTERRUPTED);
 
return(0);
 }
-- 
1.7.1.1



Re: [arch-general] [PATCH 1/4] Add skeleton for hooks support

2010-07-23 Thread Victor Lowther
On Fri, Jul 23, 2010 at 4:26 PM, Thomas Bächler tho...@archlinux.org wrote:
 Am 23.07.2010 23:07, schrieb Victor Lowther:
 This begins work on adding some sort of hook infrastructure to pacman.
 There has been much discussion and little code that I have seen, so I figured
 I would go ahead an implement a very basic skeleton for transaction hooks
 support.

 You probably want to post that to pacman-dev instead. It might not get a
 proper audience, and thus lack of review, on arch-general.

Is it closed the way arch-dev-public is?


Re: [arch-general] [PATCH 44/48] Save error messages to /dev/tty9.

2010-07-17 Thread Victor Lowther
On Fri, 2010-07-16 at 14:09 +0200, Thomas Bächler wrote:
 Am 30.06.2010 23:47, schrieb Victor Lowther:
  ---
   functions |4 
   1 files changed, 4 insertions(+), 0 deletions(-)
  
  diff --git a/functions b/functions
  index 9ec8b5e..f1dce8a 100644
  --- a/functions
  +++ b/functions
  @@ -4,6 +4,10 @@
   
   # width:
   
  +grep -q initdebug  {
  +exec 2/dev/tty9
  +}
  +
   STAT_COL=80
   if [[ ! -t 1 ]]; then
   USECOLOR=
 
 Apart from Kurt's comment:
 
 Won't this cause errors to be omitted from the console? I'd much rather
 implement a full boot logging using bootlogd, but last time I tried, it
 was broken. Redirecting stderr away from the normal output seems
 unhelpful, and unecessary.

The intent was to redirect the errors to be redirected to tty9 -- when I
was debugging these scripts, syntax errors kept getting nuked by the
gettys and X starting up, so putting them on a tty that was not running
a getty seemed like the easiest solution.

 I'd much rather omit this in favor of a patch that adds proper boot
 logging, which is a feature we really need.

No problem.  The bashification-redux branch @
git://fnordovax.org/~victor/arch-initscripts has this as the last patch
to make it easy to drop.


-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] [PATCH 43/48] Add a PKGBUILD for building initscripts-git for testing.

2010-07-17 Thread Victor Lowther
On Fri, 2010-07-16 at 14:06 +0200, Thomas Bächler wrote:
 Am 30.06.2010 23:47, schrieb Victor Lowther:
  This builds straight out of a git checkout.
  ---
   PKGBUILD |   23 +++
   1 files changed, 23 insertions(+), 0 deletions(-)
  
  diff --git a/PKGBUILD b/PKGBUILD
  new file mode 100644
  index 000..79b3403
  --- /dev/null
  +++ b/PKGBUILD
  @@ -0,0 +1,23 @@
  +pkgname=initscripts-git
  +pkgver=$(date +%s)
  +pkgrel=$(git log --pretty=format:%h |head -n 1)
  +pkgdesc=System initialization/bootup scripts
  +arch=('i686' 'x86_64')
  +url=http://www.archlinux.org;
  +license=('GPL')
  +groups=('base')
  +conflicts=('initscripts')
  +provides=('initscripts=')
  +backup=(etc/inittab etc/rc.conf etc/rc.local etc/rc.local.shutdown)
  +depends=('glibc' 'bash' 'awk' 'grep' 'coreutils' 'sed' 'udev=139-1'
  + 'net-tools' 'ncurses' 'kbd' 'findutils' 'sysvinit')
  +optdepends=('bridge-utils: Network bridging support'
  +'dhcpcd: DHCP network configuration'
  +'wireless_tools: Wireless networking')
  +source=()
  +sha256sums=()
  +
  +build() {
  +  cd ..
  +  DESTDIR=${pkgdir} ./install.sh
  +}
 
 Not necessary IMO, but nice to have. Should come with a .gitignore patch
 that adds '*pkg.tar.*'.

It is nice to have -- being able to 
makepkg  sudo pacman -U inits*.tar.*
sure does make it easier to test things.

Why do you think a .gitignore patch is needed?  Unless someone does
something silly like adding the tarball to the git repo git will ignore
it anyways.


-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] Keep older kernel intact while upgrading to new kernel

2010-07-17 Thread Victor Lowther
On Sat, 2010-07-17 at 18:05 +0400, Евгений Борисов wrote:
 I think it's a bad idea, because the directory /lib/modules/$oldVersion$
 will be removed when the package is upgraded kernel. Trivial solution not
 exists.

My solution is to hand-roll my own kernels and initramfs'es after
removing the kernel and mkinitcpio packages.  The way Arch handles its
kernel packages is a weak point -- Fedora and Ubuntu get this bit right.

 2010/7/17 ganlu rhythm@gmail.com
 
  -BEGIN PGP SIGNED MESSAGE-
  Hash: SHA1
 
  On 2010年07月17日 15:46, Ionuț Bîru wrote:
   On 07/17/2010 09:27 AM, Madhurya Kakati wrote:
   Hi,
   While updating to a new kernel pacman replaces the older kernel with
   the new
   one. Is there someway to keep the older kernel in /boot and have new
   entries
   for new kernel in menu.lst while keeping old entries intact?
  
   no
  
  You can alway do it manually, simply copy the old kernel image as other
  name before you update, then modify the correspondent line in menu.1st
  file.
  -BEGIN PGP SIGNATURE-
  Version: GnuPG v1.4.10 (GNU/Linux)
  Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
 
  iQEcBAEBAgAGBQJMQWwCAAoJEOaLWowX7DBTyPYH/jVEL3/YbKpw4g2YQeEDIKhN
  E1HHpBq0LLxHmqe5N8C79VzGV8V2RSu/B6qsmzjO3f98xd2E+ev4Etd8YGOV5vvU
  pkKu+UOeDEubFrX75L1/802wTIfO5DI21VaLpRKD/+JJ2R2rTa1Bk2HmTF5DWmoh
  mpVXOydJyIXNeu2BVUemjn4TK2t6IGs22yCI107F5uD3SV1ZtpavsZ3xZCav3e6B
  x2R8C2NCF/r3BnVE3BYh9AlX617/F03hCQPOKMyXjLnMylrVvfkxMM1Q9kW97pcl
  nGR+1YUbNgTnaylyls2dOp4UAwzALcCDVwq9oJnitTcR6f/OlIH6ELUtX0gvUUU=
  =t+0W
  -END PGP SIGNATURE-
 

-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] [PATCH 43/48] Add a PKGBUILD for building initscripts-git for testing.

2010-07-17 Thread Victor Lowther
On Sat, 2010-07-17 at 16:34 +0200, Thomas Bächler wrote:
 Am 17.07.2010 16:13, schrieb Victor Lowther:
  Why do you think a .gitignore patch is needed?  Unless someone does
  something silly like adding the tarball to the git repo git will ignore
  it anyways.
 
 You want to keep git status clean, especially with __git_ps1. If there
 is nothing changed/to commit, I want to see a clean git status output.

Huh.  I guess I have never used git status before.


-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] Keep older kernel intact while upgrading to new kernel

2010-07-17 Thread Victor Lowther
On Sat, 2010-07-17 at 23:10 +0800, Ng Oon-Ee wrote:
 On Sat, 2010-07-17 at 09:17 -0500, Victor Lowther wrote:
  On Sat, 2010-07-17 at 18:05 +0400, Евгений Борисов wrote:
   I think it's a bad idea, because the directory /lib/modules/$oldVersion$
   will be removed when the package is upgraded kernel. Trivial solution not
   exists.
  
  My solution is to hand-roll my own kernels and initramfs'es after
  removing the kernel and mkinitcpio packages.  The way Arch handles its
  kernel packages is a weak point -- Fedora and Ubuntu get this bit right.
 
 Yeah, why not keep all previous kernels and headers around. We could
 automatically extend menu.lst too!

It wold be better than updating to a new kernel, rebooting, and having
to boot to a LiveCD to get back into your system because the new kernel
fscked things up.

Keeping versioned header files also comes in handy -- I take it you heve
never tried any sort of testing with out-of-tree drivers or kernel
subsystems? Using DKMS on arch is a pointless waste of time because
older kernel headers are not kept around.

 I'm not sure what you like about Fedora and Ubuntu handling of kernels,
 but I found it very annoying to have all that stuff hanging around.
 Would be worse with rolling release I'm sure.

I like knowing that I will not have to hunt for a LiveCD or a rescue USB
drive if a kernel update renders the system unbootable.

-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] Keep older kernel intact while upgrading to new kernel

2010-07-17 Thread Victor Lowther
On Sat, 2010-07-17 at 10:42 -0500, Thomas Dziedzic wrote:
 On Sat, Jul 17, 2010 at 10:38 AM, Victor Lowther
 victor.lowt...@gmail.com wrote:
  On Sat, 2010-07-17 at 23:10 +0800, Ng Oon-Ee wrote:
  On Sat, 2010-07-17 at 09:17 -0500, Victor Lowther wrote:
   On Sat, 2010-07-17 at 18:05 +0400, Евгений Борисов wrote:
I think it's a bad idea, because the directory 
/lib/modules/$oldVersion$
will be removed when the package is upgraded kernel. Trivial solution 
not
exists.
  
   My solution is to hand-roll my own kernels and initramfs'es after
   removing the kernel and mkinitcpio packages.  The way Arch handles its
   kernel packages is a weak point -- Fedora and Ubuntu get this bit right.
 
  Yeah, why not keep all previous kernels and headers around. We could
  automatically extend menu.lst too!
 
  It wold be better than updating to a new kernel, rebooting, and having
  to boot to a LiveCD to get back into your system because the new kernel
  fscked things up.
 
  Keeping versioned header files also comes in handy -- I take it you heve
  never tried any sort of testing with out-of-tree drivers or kernel
  subsystems? Using DKMS on arch is a pointless waste of time because
  older kernel headers are not kept around.
 
  I'm not sure what you like about Fedora and Ubuntu handling of kernels,
  but I found it very annoying to have all that stuff hanging around.
  Would be worse with rolling release I'm sure.
 
  I like knowing that I will not have to hunt for a LiveCD or a rescue USB
  drive if a kernel update renders the system unbootable.
 
 
 
 This wouldn't be a problem if you have a backup kernel :)

Oh, I do.  I would just prefer to work with the package management
framework, not work around it.

-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] [PATCH 01/48] Bashification of initscripts

2010-07-11 Thread Victor Lowther
On Sun, Jul 11, 2010 at 4:45 AM, Thomas Bächler tho...@archlinux.org wrote:
 First of all: Sorry that I haven't finished the review, I have been busy
 with work and the heat kept me from thinking clearly.

 Am 07.07.2010 06:25, schrieb Dan McGee:
 On Tue, Jul 6, 2010 at 11:03 PM, Allan McRae al...@archlinux.org wrote:
 Here is a quick review on all these patches.   I recommend that the lvm and
 crypttab changes get a decent amount of testing before these go live as they
 are the biggest changes being done.

  Why has this been removed:
    -if [ -x /etc/rc.local.shutdown ]; then
    - /etc/rc.local.shutdown
    -fi
  Ah... it has been moved to another place in another commit.  Please
 document these sorts of changes in your commit message and preferably do the
 entire move in one commit.

 If there was one thing I wasn't so fond of in these patches, it seemed
 like there were too many. The beauty of git is the ability to go back
 and squash and split patches in a way that makes a lot more sense to
 others- it might not have been the way or order you did things in, but
 you should try as hard as possible to make a commit the largest
 logical unit that makes sense, but still small enough to grasp fully.

 If there are ever closely-related changes strewn across multiple
 patches in a patch set, you should probably think about merging those
 commits.

 I agree with Dan here. For example, all the commits that are merely
 replace [ with [[ and no functional changes should be one commit only.

Going back through and rewriting the patch series to do that will be
jsut about as much effort as creating the original one was.  If I had
know that was what your preference was, I would have written it that
way to begin with.  Since the end result is going to be the same once
the patch series is applied, though, I don't really see the point of
making modifications beyond bugfixes.

 I will release new initscripts and mkinitcpio now with a fix that needs
 to go to core before we do such a major change in initscripts.




[arch-general] [PATCH 1/2] Add daemon-functions to the initscripts package.

2010-07-11 Thread Victor Lowther
This file encapsulates most common rc.d daemon script idioms, and should allow
most of then to be about 6 lines long (not including whitespace)

Using it will require some modifications to the /etc/conf.d files, as
the generic functions expect all daemon options to be in $OPTS

Among other things, this will close feature request# 18654

It was written on top of my bashification patch series, but is mostly 
independent
of it.

---
 daemon-functions |   72 ++
 functions|2 +
 2 files changed, 74 insertions(+), 0 deletions(-)

diff --git a/daemon-functions b/daemon-functions
new file mode 100755
index 000..5f7660a
--- /dev/null
+++ b/daemon-functions
@@ -0,0 +1,72 @@
+#!/bin/bash
+# This file contains helper functions for initscripts in /etc/rc.d.
+# I am keeping it seperate from the main /etc/rc.d/functions for now.
+# Using this file makes most /etc/rc.d files as simple as
+# #!/bin/bash
+# DAEMON=/path/to/daemon
+# case $1 in
+#start|stop|restart|status) $1;;
+#*) usage;;
+# esac
+
+shopt -s extglob
+
+# first, source our usual files.
+. /etc/rc.conf
+. /etc/rc.d/functions
+
+# Next, declare some useful helper functions
+have_daemon() {
+local f
+[[ $DAEMON  -x $DAEMON ]] || return 1
+[[ $DAEMONNAME ]] || DAEMONNAME=${0##*/}
+PIDS=($(pidof -o %PPID $DAEMON))
+[[ $DAEMONCONF ]] || \
+for f in $DAEMONNAME $DAEMONNAME.conf; do
+[[ -f /etc/conf.d/$f ]] || continue
+DAEMONCONF=/etc/conf.d/$f
+break
+done
+return 0
+}
+
+start() {
+have_daemon || exit 1
+[[ -f $DAEMONCONF ]]  . $DAEMONCONF
+stat_busy Starting $DAEMONNAME
+if [[ ! $PIDS ]]  $DAEMON $OPTS /dev/null 21; then
+add_daemon $DAEMONNAME
+stat_done
+else
+stat_fail
+fi
+}
+
+stop() {
+have_daemon || exit 1
+stat_busy Stopping $DAEMONNAME
+if [[ $PIDS ]]  kill ${pi...@]} /dev/null 21; then
+rm_daemon $DAEMONNAME
+stat_done
+else
+stat_fail
+fi
+}
+
+restart() {
+have_daemon || exit 1
+stat_busy Restarting $DAEMONNAME 
+$0 stop
+sleep 1
+$0 start
+}
+
+status() {
+have_daemon || exit 1
+stat_busy Checking status of $DAEMONNAME
+ck_status $DAEMONNAME
+}
+
+usage() {
+echo Usage: $0 {start|stop|restart|status}
+}
\ No newline at end of file
diff --git a/functions b/functions
index 5e9a3b5..83f8fb7 100644
--- a/functions
+++ b/functions
@@ -197,8 +197,10 @@ status_stopped() {
 ck_status() {
   if ! ck_daemon $1; then
 status_started
+return 0
   else
 status_stopped
+return 1
   fi
 }
 
-- 
1.7.1.1



[arch-general] [PATCH 2/2] Add daemon-functions to install.sh

2010-07-11 Thread Victor Lowther
---
 install.sh |5 -
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/install.sh b/install.sh
index 2b2cbbc..122d4a2 100755
--- a/install.sh
+++ b/install.sh
@@ -14,7 +14,10 @@ done
 
 install -D -m755 adjtime.cron ${DESTDIR}/etc/cron.hourly/adjtime
 
-install -D -m644 functions ${DESTDIR}/etc/rc.d/functions || exit 1
+for i in functions daemon-functions; do
+install -D -m644 $i ${DESTDIR}/etc/rc.d/$1 || exit 1
+done
+
 for i in network netfs; do
   install -D -m755 $i ${DESTDIR}/etc/rc.d/$i || exit 1
 done
-- 
1.7.1.1



[arch-general] [PATCH 1/1] Make umounting filesystems much more paranoid.

2010-07-11 Thread Victor Lowther
In addition to just umounting filesystems, we also try to tear down volume 
groups, 
crypt mappings, and loopback devices.  We skip /, /proc, /sys, and /dev when 
umounting filesystems.

We do all of the above in a loop, escalating how forcible we are in umounting
filesystems up to the point where we give up and try to just remount
filesystems read-only. We do not escalate how forcible we are until we stop 
making
progress in umounting filesystems.

This patch does not print anything when tearing down crypt devices, deactivating
volume groups, or tearing down loopback devices.  It does this because root on 
lvm
and root on dm_crypt are fairly common cases, and figuring out which of these
is the case and avoiding that volume group or dm_crypt mapping is tricky.

We also no longer rely on /etc/crypttab at all for shutdown to tear down 
dm_crypt mappings.

---
 rc.shutdown |  112 +++---
 1 files changed, 90 insertions(+), 22 deletions(-)

diff --git a/rc.shutdown b/rc.shutdown
index 2a561e4..d430dce 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -64,30 +64,98 @@ stat_busy Deactivating Swap
 /sbin/swapoff -a
 stat_done
 
-stat_busy Unmounting Filesystems
-/bin/umount -a -r -t noramfs,notmpfs,nosysfs,noproc,nodevtmpfs -O no_netdev
-stat_done
+# reverse an array
+reverse() {
+res=()
+[[ $1 ]] || return 0
+local i=($@) j=0
+for ((j=${...@]}-1; j=0; j--)); do
+res+=(${i[j]})
+done
+}
 
-# Kill non-root encrypted partition mappings
-if [[ -f /etc/crypttab  $CS ]]; then
-   stat_busy Deactivating encrypted volumes:
-   do_lock() {
-stat_append ${1}..
-if $CS remove $1 /dev/null 21; then
-stat_append ok 
-   else
-stat_append failed 
-   fi
-}
-read_crypttab do_lock
-   stat_done
-fi
+# Get mounted filesystems
+fs=()
+ignore_re='^/(proc|sys|dev)?$'
+while read dev mntpt rest; do
+[[ $mntpt =~ $ignore_re ]]  continue
+fs+=($mntpt)
+done  /proc/self/mounts
+# reverse list of filesystems to let us umount them in reverse order
+reverse ${...@]}
+fs=(${r...@]})
+
+# get volume groups
+vg=()
+which lvm /dev/null 21  \
+vg=($(lvm vgs --unbuffered --noheadings -o vg_name))
+# reverse list of volume groups to grab more of them at once.
+reverse ${...@]}
+vg=(${r...@]})
+
+# get crypto devices
+crypt=()
+[[ $CS ]]  {
+for dev in /dev/mapper/*; do
+$CS status ${dev##*/} /dev/null 21 || continue
+crypt+=(${dev##*/})
+done
+}
+# don't bother reversing crypt, it is in no defined order anyways.
+
+# get loopback devices in use
+loops=()
+which losetup /dev/null 21  {
+while read dev rest; do
+loops+=(${dev%:})
+done  (losetup -a)
+}
+reverse ${loo...@]}
+loops=(${r...@]})
+
+do_umount() {
+local ret=0 i j pass=$1 umountopts='' last
+# do not umount anything that matches this regex
+case $pass in
+2) umountopts='-f';; #next try forcing the umount
+3) umountopts='-r'; last=true;; #next try remounting readonly
+esac
+
+# first, try umounting filesystems.
+for i in ${!...@]}; do
+if status Unmounting ${fs[i]} (pass $pass) /bin/umount -d 
$umountopts \
+${fs[i]}; then
+unset fs[$i]
+else
+((ret++))
+fi
+done
+
+# Second, deactivate any LVM groups that we can free up
+for i in ${!...@]}; do
+/sbin/lvm vgchange --sysinit -an ${vg[i]} /dev/null 21  \
+unset vg[$i]
+done
+
+# Third, tear down as many cryptsetup devices as we can.
+for i in ${!cry...@]}; do
+$CS remove ${crypt[i]} /dev/null 21  unset crypt[$i]
+done
+
+# Last, tear down as many loop devices as we can
+for i in ${!loo...@]}; do
+losetup -d ${loops[i]} /dev/null 21  unset loops[$i]
+done
+[[ $last = true ]]  return 0
+return $ret
+}
 
-if [[ $USELVM =~ yes|YES  -x /sbin/lvm  -d /sys/block ]]; then
-stat_busy Deactivating LVM2 groups
-/sbin/lvm vgchange --ignorelockingfailure -an /dev/null 21
-stat_done
-fi
+# Loop and try to umount filesystems
+for ((pass=1,fses=${#...@]}; ;fses=${#...@]})); do
+do_umount $pass  break; # if we umounted all the filesystems, break.
+# only escalate if we did not make progress unmounting filesystems.
+((fses == ${#...@]}))  ((pass++))
+done
 
 stat_busy Remounting Root Filesystem Read-only
 /bin/mount -n -o remount,ro /
-- 
1.7.1.1



Re: [arch-general] [PATCH 01/48] Bashification of initscripts

2010-07-11 Thread Victor Lowther
On Sun, Jul 11, 2010 at 1:11 PM, Thomas Bächler tho...@archlinux.org wrote:
 Am 11.07.2010 15:12, schrieb Victor Lowther:
 On Sun, 2010-07-11 at 14:26 +0200, Thomas Bächler wrote:
 Am 11.07.2010 14:20, schrieb Victor Lowther:
 Going back through and rewriting the patch series to do that will be
 jsut about as much effort as creating the original one was.  If I had
 know that was what your preference was, I would have written it that
 way to begin with.  Since the end result is going to be the same once
 the patch series is applied, though, I don't really see the point of
 making modifications beyond bugfixes.

 It is a matter of keeping the history readable. And it is simple: Just
 create a new branch based on master, cherry-pick the commits that do
 nothing but change [ to [[ and git merge --squash that branch into a new
 one.

 If that is all you wnat done, that is easy enough to do.  If you want
 all of the instances of trivial bashification split out from where I
 reworked the logic in the same patch, that is much less easy.

 No no, that wouldn't make sense. It should be this way: First all
 patches that actually change logic, then one big commit that just
 converts the _remaining_ [ to [[ with no additional logic changes involved.

OK, I flattened all the patches I considered trivial into several
large-ish patches, approx 1 or 2 per file in initscripts.  I did not
combine them all into one large patch because making all the logic
changes independent generated more conflicts than I felt like dealing
with.

The new branch is named bashification-redux, and is available at
git://fnordovax.org/~victor/arch-initscripts.  If you want me to post
them to the list again, I will, but the logic is unchanged.

 I hope to actually finish the review of the rest of the patches some
 time this week, sorry that I let so much time pass now.

No worries, the first time I did this sort of thing I ended up
maintaining the project. :)


Re: [arch-general] [PATCH 01/48] Bashification of initscripts

2010-07-07 Thread Victor Lowther
On Wed, 2010-07-07 at 14:03 +1000, Allan McRae wrote:
 Here is a quick review on all these patches.   I recommend that the lvm 
 and crypttab changes get a decent amount of testing before these go live 
 as they are the biggest changes being done.
 
 
 Tighten up the console size finding code a bit.
Add some white space in test construct:
  if ((STAT_COL==0)); then
  if (( STAT_COL == 0 )); then
and throughout these patches

Maybe when all the other bugs are fixed. :)

 Simplify the code that clears USECOLOR.
The following condition is removed with no commit message to explain why
  if [ $? = 3 ]; then
TERM_COLOURS=8

An exitval of 3 means tput has no idea what terminal type we are running
on, and I figured that it is after to default to not using colorized
output in that case.

 Replace trivial use of grep with bash regex conditional.
- if [ -n $CONSOLEMAP ]  echo $LOCALE | /bin/grep -qi utf ; then
+ [[ $CONSOLEMAP  $LOCALE =~ UTF|utf ]]  CONSOLEMAP=
 
Use ...  ${LOCALE,,} == utf ]] to accurately replicate the grep

Hmmm... I had not seen that parameter expansion before.  New to bash
4.1?

 Replace slightly too long echo staement with a here document.
^^ typo
I actually find the echo more readable

Well, then Thomas can keep it or drop it as he prefers. 

 Change the daemon runnign loop to use a case statement.
 Quote daemon names.
Merge these commits
 
 
 Both rc.single and rc.shutdown use the same code to kill everything.
  + # $1 = where we are being called from.
  + # This is used to determine which hooks to run.
-  Add separater line here...
  + # Find daemons NOT in the DAEMONS array. Shut these down first
 
Why has this been removed:
  -if [ -x /etc/rc.local.shutdown ]; then
  - /etc/rc.local.shutdown
  -fi
Ah... it has been moved to another place in another commit.  Please 
 document these sorts of changes in your commit message and preferably do 
 the entire move in one commit.

Will fix.

 Flatten LVM deactivation if block in rc.shutdown.
This change does not do the same thing and I do not see where it gets 
 replicated
  -if [ -f /etc/crypttab -a -n $(/bin/grep -v ^# /etc/crypttab | 
 /bin/grep -v ^$) ]; then
  +if [[ -f /etc/crypttab ]]; then

All the second bit of that test does is to see if there is actual
content in /etc/crypttab.  I handle that in the read loop by zapping
comments and blank lines with parameter expansion and conditional checks
instead -- the greps end up reading the whole file anyways.

Replicated via parameter expansion and conditionals:

[[ $line  ${line:0:1} != '#' ]] || continue
eval nspo=(${line%#*})

Also another:
+if [[ $USELVM =~ yes|YES
- ${USELVM,,} == yes
 
 
 bashify bringing up the loopback adaptor.
Add a commit message as that is doing a lot more than bashifing.

Already fixed in the last round of rebasing.

 Bashify locale setting.
$LOCALE =~ utf|UTF
 
 
 Allan

-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] [PATCH 01/48] Bashification of initscripts

2010-07-07 Thread Victor Lowther

On Jul 6, 2010, at 11:25 PM, Dan McGee dpmc...@gmail.com wrote:

If there was one thing I wasn't so fond of in these patches, it seemed
like there were too many.


Some people like larger patches, some like smaller ones. It is easier  
to merge smaller ones together than it is to split larger ones apart.



The beauty of git is the ability to go back
and squash and split patches in a way that makes a lot more sense to
others- it might not have been the way or order you did things in, but
you should try as hard as possible to make a commit the largest
logical unit that makes sense, but still small enough to grasp fully.


Ya, I wanted to get feedback to see if the larger Arch community was  
interested before going too much farther.




If there are ever closely-related changes strewn across multiple
patches in a patch set, you should probably think about merging those
commits.

-Dan


Re: [arch-general] Bashification of initscripts for moderate speedup

2010-07-03 Thread Victor Lowther
On Sun, 2010-06-27 at 22:10 -0500, Victor Lowther wrote: 
 I have spent some time over the last month or so rewriting the Arch
 initscripts in idiomatic bash -- since they rely on bash-specific
 features, trying to keep them fairly POSIX is rather a waste of time and
 a net performance loss -- using bash-style conditionals is about 30%
 faster when nothing needs to be touched on the filesystem and about 200%
 easier to read, and you can use bash regexps in place of most trivial
 uses of sed, grep, and awk when mangling parameters or variables -- the
 fewer short-lived processes we fork the better.
 
 You can browse changes I have made in the git repo @
 http://git.fnordovax.org/arch-initscripts/log/?h=bashification and you
 can checkout my changes to play around with from
 git://fnordovax.org/~victor/arch-initscripts 

OK, the bashification branch has been rebased and updated to fix issues
pointed out in the patch-by-patch feedback.  Thomas, if you want I will
repost the branch to the mailing list.

-- 
Victor Lowther
LPIC2 UCP RHCE 



Re: [arch-general] [PATCH 44/48] Save error messages to /dev/tty9.

2010-07-02 Thread Victor Lowther
On Jul 2, 2010, at 4:48 AM, Kurt J. Bosch kjb- 
temp-2...@alpenjodel.de wrote:



Am 2010-06-30 23:47, schrieb Victor Lowther:

---
 functions |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/functions b/functions
index 9ec8b5e..f1dce8a 100644
--- a/functions
+++ b/functions
@@ -4,6 +4,10 @@

 # width:

+grep -q initdebug  {
+exec 2/dev/tty9
+}
+


Hmm, won't this cause a read from stdin when starting/stopping  
daemons manually in a terminal?


It gets fixed in the next patch.




 STAT_COL=80
 if [[ ! -t 1 ]]; then
 USECOLOR=





Re: [arch-general] [PATCH 45/48] Sleep instead of rebooting or shutting down when debugging initscripts

2010-07-02 Thread Victor Lowther
On Fri, 2010-07-02 at 11:56 +0200, Kurt J. Bosch wrote:
 Am 2010-06-30 23:47, schrieb Victor Lowther:
  ---
functions   |2 +-
rc.shutdown |3 +++
2 files changed, 4 insertions(+), 1 deletions(-)
 
  diff --git a/functions b/functions
  index f1dce8a..2c80a59 100644
  --- a/functions
  +++ b/functions
  @@ -4,7 +4,7 @@
 
# width:
 
  -grep -q initdebug  {
  +grep -q initdebug /proc/cmdline  {
exec 2/dev/tty9
}
 
 OK that fixes the stdin problem :) - but /proc won't be mounted when 
 this is sourced in rc.sysinit if someone doesn't use an initcpio.

True, That did not occur to me. I discovered the awesomeness of lvm too
many years ago, I suppose.

 
  diff --git a/rc.shutdown b/rc.shutdown
  index 1081970..96b10f0 100755
  --- a/rc.shutdown
  +++ b/rc.shutdown
  @@ -93,6 +93,9 @@ run_hook shutdown_poweroff
 
# Power off or reboot
printsep
  +
  +grep -q initdebug /proc/cmdline  sleep 
  +
if [[ $RUNLEVEL = 0 ]]; then
  printhl ${C_H2}POWER OFF
  /sbin/poweroff -d -f -h -i
 
 

-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] Bashification of initscripts for moderate speedup

2010-07-02 Thread Victor Lowther
On Jul 2, 2010, at 10:35 AM, Kurt J. Bosch kjb-temp-2...@alpenjodel.de 
 wrote:



2010-06-28 05:10, Victor Lowther:

You can browse changes I have made in the git repo @
http://git.fnordovax.org/arch-initscripts/log/?h=bashification


The feed link appears broken to me.

link rel='alternate' title='Atom feed' href='http://git.fnordovax.orghttp://git.fnordovax.org/arch-initscripts/atom/?h=bashification' 
 type='application/atom+xml'/




Thanks. I might eventually fix it.


--
kujub (whining)



Re: [arch-general] [PATCH 14/48] Fix whitespace errors I introduced.

2010-07-01 Thread Victor Lowther
On Thu, 2010-07-01 at 23:01 -0400, Caleb Cushing wrote:
 On Wed, Jun 30, 2010 at 6:06 PM, Thomas Bächler tho...@archlinux.org wrote:
  If you introduced whitespace errors (or any errors), fix them in the
  commits that introduced them, don't do a separate commit fixing them.
 ++
 
 rebase -i  on the remote and flatten squash this patch into the patch
 the problem was introduced in.

/me nods

Just waiting for any other things Thomas wants fixed up.

-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] [PATCH 01/48] Bashification of initscripts

2010-07-01 Thread Victor Lowther
On Thu, 2010-07-01 at 22:58 -0400, Caleb Cushing wrote:
 On Wed, Jun 30, 2010 at 6:07 PM, Victor Lowther
 victor.lowt...@gmail.com wrote:
  I don't see the need for this patch. functions is not supposed to be
  executed standalone, it is only source'd from bash scripts.
 
  It is a habit I have -- including the shebang line at the top makes sure
  my text editors automatically detect the right shell syntax for syntax
  highlighting.
 
 It has the added benefit of making it quite clear that the script will
 not work on another POSIX shell.

Indeed.

-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] Bashification of initscripts for moderate speedup

2010-06-30 Thread Victor Lowther
On Jun 30, 2010, at 12:40 PM, Thomas Bächler tho...@archlinux.org  
wrote:



Am 28.06.2010 05:10, schrieb Victor Lowther:

I have spent some time over the last month or so rewriting the Arch
initscripts in idiomatic bash -- since they rely on bash-specific
features, trying to keep them fairly POSIX is rather a waste of  
time and

a net performance loss -- using bash-style conditionals is about 30%
faster when nothing needs to be touched on the filesystem and about  
200%

easier to read, and you can use bash regexps in place of most trivial
uses of sed, grep, and awk when mangling parameters or variables --  
the

fewer short-lived processes we fork the better.

You can browse changes I have made in the git repo @
http://git.fnordovax.org/arch-initscripts/log/?h=bashification and  
you

can checkout my changes to play around with from
git://fnordovax.org/~victor/arch-initscripts


Okay, those are LOTS of patches. I agree with most of them, but not  
all.
However, reviewing and commenting them like this is a bit tedious -  
can
you use git send-email to send them to this list as a patch series,  
so I

can comment properly?


Sure. I will do so tonight.




[arch-general] [PATCH 02/48] Tighten up the console size finding code a bit.

2010-06-30 Thread Victor Lowther
---
 functions |   30 +-
 1 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/functions b/functions
index 023de35..a9acf6f 100644
--- a/functions
+++ b/functions
@@ -5,26 +5,21 @@
 # width:
 
 STAT_COL=80
-if [ ! -t 1 ]; then
-  USECOLOR=
-
-# stty will fail when stdin isn't a terminal
-elif [ -t 0 ]; then
-  STAT_COL=$(/bin/stty size)
-  # stty gives rows cols; strip the rows number, we just want columns
-  STAT_COL=${STAT_COL##* }
-
-else
+if [[ ! -t 1 ]]; then
+USECOLOR=
+elif [[ -t 0 ]]; then
+# stty will fail when stdin isn't a terminal
+STAT_COL=$(/bin/stty size)
+# stty gives rows cols; strip the rows number, we just want columns
+STAT_COL=${STAT_COL##* }
+elif /bin/tput cols /dev/null; then
   # is /usr/share/terminfo already mounted, and TERM recognized?
-  /bin/tput cols /dev/null
-  if [ $? -eq 0 ]; then
 STAT_COL=$(/bin/tput cols)
-  fi
 fi
-if [ 0$STAT_COL -eq 0 ]; then
-  # if output was 0 (serial console), set default width to 80
-  STAT_COL=80
-  USECOLOR=
+if ((STAT_COL==0)); then
+# if output was 0 (serial console), set default width to 80
+STAT_COL=80
+USECOLOR=
 fi
 
 # we use 13 characters for our own stuff
@@ -54,6 +49,7 @@ unset TZ
 # colors:
 if [ $USECOLOR = YES -o $USECOLOR = yes ]; then
C_MAIN=\033[1;37;40m  # main text
+
C_OTHER=\033[1;34;40m # prefix  brackets
C_SEPARATOR=\033[1;30;40m # separator
 
-- 
1.7.1



[arch-general] [PATCH 04/48] Use [[ ]] instead of [ ] for conditional checking when running in bash.

2010-06-30 Thread Victor Lowther
It is worth 10 - 30% speedup whenever you want to compare something.
---
 functions |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/functions b/functions
index 6df8c5e..9b348b7 100644
--- a/functions
+++ b/functions
@@ -40,7 +40,7 @@ unset TERM_COLORS
 unset TZ
 
 # colors:
-if [ $USECOLOR = YES -o $USECOLOR = yes ]; then
+if [[ $USECOLOR = YES || $USECOLOR = yes ]]; then
C_MAIN=\033[1;37;40m  # main text
 
C_OTHER=\033[1;34;40m # prefix  brackets
-- 
1.7.1



[arch-general] [PATCH 01/48] Bashification of initscripts

2010-06-30 Thread Victor Lowther
Despite efforts to make the initscripts POSIX, we use bash 4.0 features.

Bashifying this framework should result in about a 30% speedup, assuming no
IO latency and that all programs we call also take zero time. :)
---
 functions |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/functions b/functions
index 672eed2..023de35 100644
--- a/functions
+++ b/functions
@@ -1,4 +1,4 @@
-#
+#!/bin/bash
 # initscripts functions
 #
 
-- 
1.7.1



[arch-general] [PATCH 06/48] Clean up status() function.

2010-06-30 Thread Victor Lowther
Calling your args with $* will do nasty things if any of your args
has a space in it.  $@ will always do The Right Thing.

Just test the command directly, don't run it and then grab its exit value.
---
 functions |8 +++-
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/functions b/functions
index 0acdbbf..9d0aec3 100644
--- a/functions
+++ b/functions
@@ -123,14 +123,12 @@ stat_die() {
 status() {
stat_busy $1
shift
-   $* /dev/null 21
-   if [ $? -eq 0 ]; then
+   if $@ /dev/null 21; then
stat_done
return 0
-   else
-   stat_fail
-   return 1
fi
+   stat_fail
+   return 1
 }
 
 #  usage : in_array( $needle, $haystack )
-- 
1.7.1



[arch-general] [PATCH 07/48] Simplify in_array.

2010-06-30 Thread Victor Lowther
All that extra checking for the first character being @ is not needed,
simple parameter expansion will trim it off if it is there.
---
 functions |   18 +++---
 1 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/functions b/functions
index 9d0aec3..8bbdfc6 100644
--- a/functions
+++ b/functions
@@ -136,17 +136,13 @@ status() {
 #  1 - not found
 # Copied from makepkg
 in_array() {
-  local needle=$1; shift
-  [ -z $1 ]  return 1 # Not Found
-  local item
-  for item in $@; do
-local c=${item:0:1}
-if [ x$c = x@ ]; then
-  item=${item:1}
-fi
-[ $item = $needle ]  return 0 # Found
-  done
-  return 1 # Not Found
+[[ $2 ]] || return 1
+local needle=$1; shift
+local item
+for item in $@; do
+   [[ ${it...@} = $needle ]]  return 0
+done
+return 1 # Not Found
 }
 
 # daemons:
-- 
1.7.1



[arch-general] [PATCH 05/48] a little creative parameter expansion simplifies stat_die()

2010-06-30 Thread Victor Lowther
---
 functions |6 ++
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/functions b/functions
index 9b348b7..0acdbbf 100644
--- a/functions
+++ b/functions
@@ -57,7 +57,7 @@ if [[ $USECOLOR = YES || $USECOLOR = yes ]]; then
C_CLEAR=\033[1;0m
 fi
 
-if [ -t 1 ]; then
+if [[ -t 1 ]]; then
SAVE_POSITION=\033[s
RESTORE_POSITION=\033[u
DEL_TEXT=\033[$(($STAT_COL+4))G
@@ -116,10 +116,8 @@ stat_fail() {
 }
 
 stat_die() {
-   retval=1
-   [ $1 =  ] || retval=$1
stat_fail
-   exit $retval
+   exit ${1:-1}
 }
 
 status() {
-- 
1.7.1



[arch-general] [PATCH 10/48] Replace trivial use of grep with bash regex conditional.

2010-06-30 Thread Victor Lowther
Bash has regex support, and it allows us to replace most trivial
uses of sed, grep, and awk.  The fewer processes we create, the faster
we go, and every little bit helps.

I also think it is more readable to use a bash regex for the trivial stuff.
---
 functions |4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/functions b/functions
index f954737..8aaee68 100644
--- a/functions
+++ b/functions
@@ -260,9 +260,7 @@ set_consolefont() {
 [[ $CONSOLEFONT ]] || return 0
 stat_busy Loading Console Font: $CONSOLEFONT
 #CONSOLEMAP in UTF-8 shouldn't be used
-if [ -n $CONSOLEMAP ]  echo $LOCALE | /bin/grep -qi utf ; then
-   CONSOLEMAP=
-fi
+[[ $CONSOLEMAP  $LOCALE =~ UTF|utf ]]  CONSOLEMAP=
 for i in /dev/tty[0-9]*; do
if [ -n $CONSOLEMAP ]; then
/usr/bin/setfont -m $CONSOLEMAP $CONSOLEFONT -C ${i} /dev/null 21
-- 
1.7.1



[arch-general] [PATCH 09/48] If $CONSOLEFONT is not declared, then just return out of set_consolefont.

2010-06-30 Thread Victor Lowther
We do this early so that the entire body of the function is not in an if block.
---
 functions |   37 ++---
 1 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/functions b/functions
index d9f55fa..f954737 100644
--- a/functions
+++ b/functions
@@ -257,27 +257,26 @@ declare -r add_hook run_hook
 
 # Function for setting console font if required
 set_consolefont() {
-if [ -n $CONSOLEFONT ]; then
-   stat_busy Loading Console Font: $CONSOLEFONT
-   #CONSOLEMAP in UTF-8 shouldn't be used
-   if [ -n $CONSOLEMAP ]  echo $LOCALE | /bin/grep -qi utf ; then
-   CONSOLEMAP=
-   fi
-   for i in /dev/tty[0-9]*; do
-   if [ -n $CONSOLEMAP ]; then
-   /usr/bin/setfont -m $CONSOLEMAP $CONSOLEFONT -C ${i} 
/dev/null 21
-   else
-   /usr/bin/setfont $CONSOLEFONT -C ${i} /dev/null 21
-   fi
-   done
-   if [ $? -ne 0 ]; then
-   stat_fail
+[[ $CONSOLEFONT ]] || return 0
+stat_busy Loading Console Font: $CONSOLEFONT
+#CONSOLEMAP in UTF-8 shouldn't be used
+if [ -n $CONSOLEMAP ]  echo $LOCALE | /bin/grep -qi utf ; then
+   CONSOLEMAP=
+fi
+for i in /dev/tty[0-9]*; do
+   if [ -n $CONSOLEMAP ]; then
+   /usr/bin/setfont -m $CONSOLEMAP $CONSOLEFONT -C ${i} /dev/null 21
else
-   if [ -n $CONSOLEMAP ]; then
-   echo 'if [ $CONSOLE =  -a $TERM = linux -a -t 1 
]; then printf \033(K; fi' /etc/profile.d/locale.sh
-   fi
-   stat_done
+   /usr/bin/setfont $CONSOLEFONT -C ${i} /dev/null 21
+   fi
+done
+if [ $? -ne 0 ]; then
+   stat_fail
+else
+   if [ -n $CONSOLEMAP ]; then
+   echo 'if [ $CONSOLE =  -a $TERM = linux -a -t 1 ]; then 
printf \033(K; fi' /etc/profile.d/locale.sh
fi
+   stat_done
 fi
 }
 
-- 
1.7.1



[arch-general] [PATCH 12/48] Replace slightly too long echo staement with a here document.

2010-06-30 Thread Victor Lowther
This adds a line, but making things more readable is worth it.
---
 functions |   11 ++-
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/functions b/functions
index 56c6a7b..9730150 100644
--- a/functions
+++ b/functions
@@ -265,12 +265,13 @@ set_consolefont() {
/usr/bin/setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \
$CONSOLEFONT -C ${i} /dev/null 21
 done
-if [ $? -ne 0 ]; then
+if (($? != 0)); then
stat_fail
-else
-   if [ -n $CONSOLEMAP ]; then
-   echo 'if [ $CONSOLE =  -a $TERM = linux -a -t 1 ]; then 
printf \033(K; fi' /etc/profile.d/locale.sh
-   fi
+elif [[ $CONSOLEMAP ]]; then
+   cat EOF /etc/profile.d/locale.sh
+if [ $CONSOLE =  -a $TERM = linux -a -t 1 ]; then printf \033(K; fi
+
+EOF
stat_done
 fi
 }
-- 
1.7.1



[arch-general] [PATCH 08/48] Slightly simplify hook-running infrastructure.

2010-06-30 Thread Victor Lowther
Go ahead and declare add_hook and run_hook as readonly functions
to prevent hooks from overwriting them.  Too bad bash does not have
lexically scoped variables -- if it does, we could do the same with
the hook_funcs associative array.
---
 functions |   49 ++---
 1 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/functions b/functions
index 8bbdfc6..d9f55fa 100644
--- a/functions
+++ b/functions
@@ -148,38 +148,39 @@ in_array() {
 # daemons:
 
 add_daemon() {
-   [ -d /var/run/daemons ] || /bin/mkdir -p /var/run/daemons
-   /bin/touch /var/run/daemons/$1
+   [[ -d /var/run/daemons ]] || /bin/mkdir -p /var/run/daemons
+/var/run/daemons/$1
 }
 
 rm_daemon() {
-   /bin/rm -f /var/run/daemons/$1
+   /bin/rm -f /var/run/daemons/$1
 }
 
 ck_daemon() {
-   [ -f /var/run/daemons/$1 ]  return 1
-   return 0
+   [[ ! -f /var/run/daemons/$1 ]]
 }
 
-ck_depends() {
-   for daemon in $@; do
-   if ck_daemon $daemon; then
-   /etc/rc.d/$daemon start
-   fi
-   done
+have_daemon() {
+[[ -x /etc/rc.d/$1 ]]
 }
 
 start_daemon() {
-   /etc/rc.d/$1 start
+have_daemon $1  /etc/rc.d/$1 start
+}
+
+ck_depends() {
+for daemon in $@; do
+   ck_daemon $daemon  start_daemon $daemon 
+done
 }
 
 start_daemon_bkgd() {
stat_bkgd Starting $1
-   (/etc/rc.d/$1 start) /dev/null 
+   have_daemon $1  (start_daemon $1) /dev/null 
 }
 
 stop_daemon() {
-   /etc/rc.d/$1 stop
+   have_daemon $1  /etc/rc.d/$1 stop
 }
 
 # Status functions
@@ -234,24 +235,26 @@ ck_status() {
 # single_postkillall: after all processes have been killed in rc.single
 # shutdown_poweroff: directly before powering off in rc.shutdown
 #
-# Make sure to never override the add_hook and run_hook functions via 
functions.d
+# Declare add_hook and run_hook as read-only to prevent overwriting them.
+# Too bad we cannot do the same thing with hook_funcs 
 
 declare -A hook_funcs
 
 add_hook() {
-   [ -z $1 -o -z $2 ]  return 1
-   hook_funcs[$1]=${hook_funcs[$1]} $2
+   [[ $1  $2 ]] || return 1
+   hook_funcs[$1]+= $2
 }
 
 run_hook() {
-   local func
-
-   [ -z $1 ]  return 1
-   for func in ${hook_funcs[$1]}; do
-   ${func}
-   done
+[[ $1 ]] || return 1
+local func
+for func in ${hook_funcs[$1]}; do
+   ${func}
+done
 }
 
+declare -r add_hook run_hook
+
 # Function for setting console font if required
 set_consolefont() {
 if [ -n $CONSOLEFONT ]; then
-- 
1.7.1



[arch-general] [PATCH 14/48] Fix whitespace errors I introduced.

2010-06-30 Thread Victor Lowther
---
 functions |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/functions b/functions
index 9c89ea1..d8e8e54 100644
--- a/functions
+++ b/functions
@@ -170,7 +170,7 @@ start_daemon() {
 
 ck_depends() {
 for daemon in $@; do
-   ck_daemon $daemon  start_daemon $daemon 
+   ck_daemon $daemon  start_daemon $daemon
 done
 }
 
@@ -200,7 +200,7 @@ ck_status() {
 status_started
   else
 status_stopped
-  fi   
+  fi
 }
 
 ###
@@ -236,7 +236,7 @@ ck_status() {
 # shutdown_poweroff: directly before powering off in rc.shutdown
 #
 # Declare add_hook and run_hook as read-only to prevent overwriting them.
-# Too bad we cannot do the same thing with hook_funcs 
+# Too bad we cannot do the same thing with hook_funcs
 
 declare -A hook_funcs
 
-- 
1.7.1



[arch-general] [PATCH 15/48] Bashify conditional checking in rc.multi

2010-06-30 Thread Victor Lowther
---
 rc.multi |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/rc.multi b/rc.multi
index a7ea703..46c18df 100755
--- a/rc.multi
+++ b/rc.multi
@@ -9,12 +9,12 @@
 run_hook multi_start
 
 # Load sysctl variables if sysctl.conf is present
-[ -r /etc/sysctl.conf ]  /sbin/sysctl -q -p /dev/null
+[[ -r /etc/sysctl.conf ]]  /sbin/sysctl -q -p /dev/null
 
 # Start daemons
 for daemon in ${daemo...@]}; do
-   if [ $daemon = ${daemon#!} ]; then
-   if [ $daemon = ${daem...@} ]; then
+   if [[ $daemon = ${daemon#!} ]]; then
+   if [[ $daemon = ${daem...@} ]]; then
start_daemon $daemon
else
start_daemon_bkgd ${daemon:1}
@@ -22,7 +22,7 @@ for daemon in ${daemo...@]}; do
fi
 done
 
-if [ -x /etc/rc.local ]; then
+if [[ -x /etc/rc.local ]]; then
/etc/rc.local
 fi
 
-- 
1.7.1



[arch-general] [PATCH 20/48] Shorten domainname and rc.local.shutdown conditional execution.

2010-06-30 Thread Victor Lowther
---
 rc.shutdown |8 ++--
 1 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/rc.shutdown b/rc.shutdown
index 4eb29cc..002a45d 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -16,13 +16,9 @@ printhl Initiating Shutdown...
 echo  
 
 # avoid NIS hanging syslog-ng on shutdown by unsetting the domainname
-if [ -x /bin/domainname ]; then
-   /bin/domainname 
-fi
+[[ -x /bin/domainname ]]  /bin/domainname 
+[[ -x /etc/rc.local.shutdown ]]  /etc/rc.local.shutdown
 
-if [ -x /etc/rc.local.shutdown ]; then
-   /etc/rc.local.shutdown
-fi
 
 # Find daemons NOT in the DAEMONS array. Shut these down first
 if [ -d /var/run/daemons ]; then
-- 
1.7.1



[arch-general] [PATCH 37/48] Bashify hostname and nisdomainnname setting.

2010-06-30 Thread Victor Lowther
---
 rc.sysinit |   10 +-
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/rc.sysinit b/rc.sysinit
index 217dacf..5842a57 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -287,14 +287,14 @@ stat_done
 
 #status Updating Shared Library Links /sbin/ldconfig
 
-if [ $HOSTNAME !=  ]; then
-   status Setting Hostname: $HOSTNAME /bin/hostname $HOSTNAME
+if [[ $HOSTNAME ]]; then
+   status Setting Hostname: $HOSTNAME /bin/hostname $HOSTNAME
 fi
 
 # Set the NIS domain name, if necessary
-[ -f /etc/conf.d/nisdomainname ]  . /etc/conf.d/nisdomainname
-if [ $NISDOMAINNAME !=  ]; then
-   status Setting NIS Domain Name: $NISDOMAINNAME /bin/nisdomainname 
$NISDOMAINNAME
+[[ -f /etc/conf.d/nisdomainname ]]  . /etc/conf.d/nisdomainname
+if [[ $NISDOMAINNAME ]]; then
+   status Setting NIS Domain Name: $NISDOMAINNAME /bin/nisdomainname 
$NISDOMAINNAME
 fi
 
 status Updating Module Dependencies /sbin/depmod -A
-- 
1.7.1



[arch-general] [PATCH 36/48] Bashify setting the random seed.

2010-06-30 Thread Victor Lowther
---
 rc.sysinit |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/rc.sysinit b/rc.sysinit
index 037a9f2..217dacf 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -265,7 +265,7 @@ fi
 stat_done
 
 RANDOM_SEED=/var/lib/misc/random-seed
-if [ -f $RANDOM_SEED ]; then
+if [[ -f $RANDOM_SEED ]]; then
stat_busy Initializing Random Seed
/bin/cat $RANDOM_SEED  /dev/urandom
stat_done
-- 
1.7.1



[arch-general] [PATCH 38/48] Bashify locale setting.

2010-06-30 Thread Victor Lowther
---
 rc.sysinit |   16 ++--
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/rc.sysinit b/rc.sysinit
index 5842a57..c6ed35f 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -303,12 +303,12 @@ status Updating Module Dependencies /sbin/depmod -A
 : | /etc/profile.d/locale.sh
 /bin/chmod 755 /etc/profile.d/locale.sh
 # Set user defined locale
-[ -z $LOCALE ]  LOCALE=en_US
+[[ $LOCALE ]] || LOCALE=en_US
 stat_busy Setting Locale: $LOCALE
 echo export LANG=$LOCALE /etc/profile.d/locale.sh
 stat_done
 
-if echo $LOCALE | /bin/grep -qi utf ; then
+if [[ $LOCALE =~ utf|UTF ]]; then
stat_busy Setting Consoles to UTF-8 mode
# UTF-8 consoles are default since 2.6.24 kernel
# this code is needed not only for older kernels,
@@ -318,9 +318,11 @@ if echo $LOCALE | /bin/grep -qi utf ; then
printf \033%%G  ${i}
done
# the $CONSOLE check helps us avoid this when running scripts from cron
-   echo 'if [ $CONSOLE =  -a $TERM = linux -a -t 1 ]; then printf 
\033%%G; fi' /etc/profile.d/locale.sh
+   cat EOF /etc/profile.d/locale.sh
+if [ $CONSOLE =  -a $TERM = linux -a -t 1 ]; then printf \033%%G; fi
+EOF
stat_done
-   [ -n $KEYMAP ]  status Loading Keyboard Map: $KEYMAP 
/bin/loadkeys -q -u $KEYMAP
+   [[ $KEYMAP ]]  status Loading Keyboard Map: $KEYMAP /bin/loadkeys 
-q -u $KEYMAP
 else
stat_busy Setting Consoles to legacy mode
# make non-UTF-8 consoles work on 2.6.24 and newer kernels
@@ -329,9 +331,11 @@ else
printf \033%%@  ${i}
done
# the $CONSOLE check helps us avoid this when running scripts from cron
-   echo 'if [ $CONSOLE =  -a $TERM = linux -a -t 1 ]; then printf 
\033%%@; fi' /etc/profile.d/locale.sh
+   cat EOF /etc/profile.d/locale.sh
+if [ $CONSOLE =  -a $TERM = linux -a -t 1 ]; then printf \033%%@; fi
+EOF
stat_done
-   [ -n $KEYMAP ]  status Loading Keyboard Map: $KEYMAP 
/bin/loadkeys -q $KEYMAP
+   [[ $KEYMAP ]]  status Loading Keyboard Map: $KEYMAP /bin/loadkeys 
-q $KEYMAP
 fi
 
 # Set console font if required
-- 
1.7.1



[arch-general] [PATCH 40/48] Bashify waiting for the clock pid.

2010-06-30 Thread Victor Lowther
---
 rc.sysinit |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/rc.sysinit b/rc.sysinit
index ac32fca..1ecfc3f 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -352,7 +352,7 @@ done
 /bin/dmesg | /var/log/dmesg.log
 
 # final hwclock setting needs to be done at this point
-if [ -n $clock_pid ]; then
+if [[ $clock_pid ]]; then
wait $clock_pid
 fi
 
-- 
1.7.1



[arch-general] [PATCH 31/48] Simplify test to see if we should assemble arrays at startup

2010-06-30 Thread Victor Lowther
---
 rc.sysinit |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/rc.sysinit b/rc.sysinit
index 31636e5..404e11a 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -123,7 +123,7 @@ if [[ -d /sys/class/net/lo ]]; then
 fi
 
 # If necessary, find md devices and manually assemble RAID arrays
-if [ -f /etc/mdadm.conf -a $(/bin/grep ^ARRAY /etc/mdadm.conf 2/dev/null) 
]; then
+if [[ -f /etc/mdadm.conf ]]  /bin/grep -q ^ARRAY /etc/mdadm.conf; then
status Activating RAID arrays /sbin/mdadm --assemble --scan
 fi
 
-- 
1.7.1



[arch-general] [PATCH 43/48] Add a PKGBUILD for building initscripts-git for testing.

2010-06-30 Thread Victor Lowther
This builds straight out of a git checkout.
---
 PKGBUILD |   23 +++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000..79b3403
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,23 @@
+pkgname=initscripts-git
+pkgver=$(date +%s)
+pkgrel=$(git log --pretty=format:%h |head -n 1)
+pkgdesc=System initialization/bootup scripts
+arch=('i686' 'x86_64')
+url=http://www.archlinux.org;
+license=('GPL')
+groups=('base')
+conflicts=('initscripts')
+provides=('initscripts=')
+backup=(etc/inittab etc/rc.conf etc/rc.local etc/rc.local.shutdown)
+depends=('glibc' 'bash' 'awk' 'grep' 'coreutils' 'sed' 'udev=139-1'
+ 'net-tools' 'ncurses' 'kbd' 'findutils' 'sysvinit')
+optdepends=('bridge-utils: Network bridging support'
+'dhcpcd: DHCP network configuration'
+'wireless_tools: Wireless networking')
+source=()
+sha256sums=()
+
+build() {
+  cd ..
+  DESTDIR=${pkgdir} ./install.sh
+}
-- 
1.7.1



[arch-general] [PATCH 42/48] Load conf files in a loop instead of one at a time.

2010-06-30 Thread Victor Lowther
---
 network |   11 +++
 1 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/network b/network
index 977e81e..242acc3 100755
--- a/network
+++ b/network
@@ -3,14 +3,9 @@
 . /etc/rc.conf
 . /etc/rc.d/functions
 
-# wireless settings
-[ -f /etc/conf.d/wireless ]  . /etc/conf.d/wireless
-# ethernet bonding settings
-[ -f /etc/conf.d/bonding ]  . /etc/conf.d/bonding
-# bridge settings
-[ -f /etc/conf.d/bridges ]  . /etc/conf.d/bridges
-# dhcpcd settings
-[ -f /etc/conf.d/dhcpcd ]  . /etc/conf.d/dhcpcd
+for s in wireless bonding bridges dhcpcd; do
+[[ -f /etc/conf.d/$s ]]  . /etc/conf.d/$s
+done
 
 ifup()
 {
-- 
1.7.1



[arch-general] [PATCH 34/48] Bashify clock and timezone handling in rc.sysinit

2010-06-30 Thread Victor Lowther
---
 rc.sysinit |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/rc.sysinit b/rc.sysinit
index 91ee03a..319ea60 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -243,13 +243,13 @@ stat_done
 status Activating Swap /sbin/swapon -a
 
 stat_busy Configuring System Clock
-if [ $TIMEZONE !=  -a -e /usr/share/zoneinfo/$TIMEZONE ]; then
+if [[ $TIMEZONE  -e /usr/share/zoneinfo/$TIMEZONE ]]; then
/bin/rm -f /etc/localtime
/bin/cp /usr/share/zoneinfo/$TIMEZONE /etc/localtime
 fi
 
 clock_pid=
-if [ -n $HWCLOCK_PARAMS ]; then
+if [[ $HWCLOCK_PARAMS ]]; then
# This time, we set the clock for real. Use the adjustment file now that
# /var will definitely be available, and then set the system clock once
# the hardware clock has been adjusted accordingly. The backgrounding 
magic
-- 
1.7.1



[arch-general] [PATCH 17/48] Quote daemon names.

2010-06-30 Thread Victor Lowther
Someday, someone may have a daemon name with a space in it.
---
 rc.multi |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/rc.multi b/rc.multi
index ec6fda6..660f649 100755
--- a/rc.multi
+++ b/rc.multi
@@ -15,8 +15,8 @@ run_hook multi_start
 for daemon in ${daemo...@]}; do
 case ${daemon:0:1} in
 '!') continue;; # Skip this daemon.
-'@') start_daemon_bkgd ${daem...@};;
-*)   start_daemon $daemon;;
+'@') start_daemon_bkgd ${daem...@};;
+*)   start_daemon $daemon;;
 esac
 done
 
-- 
1.7.1



[arch-general] [PATCH 33/48] Bashified fscking.

2010-06-30 Thread Victor Lowther
---
 rc.sysinit |   11 +--
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/rc.sysinit b/rc.sysinit
index d54b9bb..91ee03a 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -181,7 +181,7 @@ fi
 status Mounting Root Read-only /bin/mount -n -o remount,ro /
 
 FORCEFSCK=
-[ -f /forcefsck ]  FORCEFSCK=-- -f
+[[ -f /forcefsck ]]  FORCEFSCK=-- -f
 
NETFS=nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs
 
 fsck_reboot() {
@@ -192,7 +192,7 @@ fsck_reboot() {
exit 0
 }
 
-if [ -x /sbin/fsck ]; then
+if [[ -x /sbin/fsck ]]; then
stat_busy Checking Filesystems
FSCK_OUT=/dev/stdout
FSCK_ERR=/dev/stdout
@@ -200,11 +200,11 @@ if [ -x /sbin/fsck ]; then
run_hook sysinit_prefsck
/sbin/fsck -A -T -C$FSCK_FD -a -t $NETFS,noopts=_netdev $FORCEFSCK 
$FSCK_OUT 2$FSCK_ERR
fsckret=$?
-   if [ ${fsckret} -gt 1 ]; then
+   if ((fsckret  1)); then
stat_fail
fi
run_hook sysinit_postfsck
-   if [ $((${fsckret}2)) -eq 2 ]; then
+   if (( ( fsckret  2) == 2)); then
echo
echo ** REBOOT REQUIRED 
*
echo * 
 *
@@ -214,8 +214,7 @@ if [ -x /sbin/fsck ]; then
echo
/bin/sleep 15
fsck_reboot
-   fi
-   if [ ${fsckret} -gt 1 -a ${fsckret} -ne 32 ]; then
+   elif ((fsckret  1  fsckret != 32)); then
echo
echo *  FILESYSTEM CHECK FAILED  

echo * 
 *
-- 
1.7.1



[arch-general] [PATCH 24/48] Flatten LVM deactivation if block in rc.shutdown.

2010-06-30 Thread Victor Lowther
---
 rc.shutdown |   52 +++-
 1 files changed, 23 insertions(+), 29 deletions(-)

diff --git a/rc.shutdown b/rc.shutdown
index b2278b6..b7b7d45 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -65,7 +65,7 @@ stat_busy Unmounting Filesystems
 stat_done
 
 # Kill non-root encrypted partition mappings
-if [ -f /etc/crypttab -a -n $(/bin/grep -v ^# /etc/crypttab | /bin/grep -v 
^$) ]; then
+if [[ -f /etc/crypttab ]]; then
stat_busy Deactivating encrypted volumes:
# Arch cryptsetup packages traditionally contained the binaries
#  /usr/sbin/cryptsetup
@@ -73,38 +73,32 @@ if [ -f /etc/crypttab -a -n $(/bin/grep -v ^# 
/etc/crypttab | /bin/grep -v ^$)
# By default, initscripts used the /sbin/cryptsetup.static.
# Newer packages will only have /sbin/cryptsetup and no static binary
# This ensures maximal compatibility with the old and new layout
-   if [ -x /sbin/cryptsetup ]; then
-   CS=/sbin/cryptsetup
-   elif [ -x /usr/sbin/cryptsetup ]; then
-   CS=/usr/sbin/cryptsetup
+for CS in /sbin/cryptsetup /usr/sbin/cryptsetup \
+/sbin/cryptsetup.static ''; do
+[[ -x $CS ]]  break
+done
+if [[ ! $CS ]]; then
+stat_append  Failed, unable to find cryptsetup.
+stat_fail
else
-   CS=/sbin/cryptsetup.static
-   fi
-   do_uncrypt() {
-   if [ $# -ge 3 ]; then
-   if [ -b /dev/mapper/$1 ] ;then
-   stat_append ${1}..
-   $CS remove $1 /dev/null 21
-   if [ $? -ne 0 ]; then
-   stat_append failed 
-   else
-   stat_append ok 
-   fi
-   fi
+while read name src passwd opts; do
+[[ ! $name || ${name:0:1} = '#']]  continue
+[[ -b /dev/mapper/$name ]] || continue
+   stat_append ${1}..
+   if $CS remove $name /dev/null 21; then
+   stat_append ok 
+else
+   stat_append failed 
fi
-   }
-   while read line; do
-   eval do_uncrypt $line
-   done /etc/crypttab
-   stat_done
+   done /etc/crypttab
+fi
+stat_done
 fi
 
-if [ $USELVM = yes -o $USELVM = YES ]; then
-   if [ -x /sbin/lvm -a -d /sys/block ]; then
-   stat_busy Deactivating LVM2 groups
-   /sbin/lvm vgchange --ignorelockingfailure -an /dev/null 21
-   stat_done
-   fi
+if [[ $USELVM =~ yes|YES  -x /sbin/lvm  -d /sys/block ]]; then
+stat_busy Deactivating LVM2 groups
+/sbin/lvm vgchange --ignorelockingfailure -an /dev/null 21
+stat_done
 fi
 
 stat_busy Remounting Root Filesystem Read-only
-- 
1.7.1



[arch-general] [PATCH 25/48] Bashify poweroff or reboot code in rc.shutdown.

2010-06-30 Thread Victor Lowther
---
 rc.shutdown |7 +++
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/rc.shutdown b/rc.shutdown
index b7b7d45..7d5ec26 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -108,15 +108,14 @@ stat_done
 run_hook shutdown_poweroff
 
 # Power off or reboot
-if [ $RUNLEVEL = 0 ]; then
-   printsep
+printsep
+if [[ $RUNLEVEL = 0 ]]; then
printhl ${C_H2}POWER OFF
/sbin/poweroff -d -f -h -i
 else
-   printsep
printhl ${C_H2}REBOOTING
# if kexec is installed and a kernel is loaded, use it
-   [ -x /sbin/kexec ]  /sbin/kexec -e  /dev/null 21
+   [[ -x /sbin/kexec ]]  /sbin/kexec -e  /dev/null 21
/sbin/reboot -d -f -i
 fi
 
-- 
1.7.1



[arch-general] [PATCH 28/48] Use bash-style conditionals when setting up the hardware clock.

2010-06-30 Thread Victor Lowther
Trying to stick with POSIX syntax only just slows things down.
---
 rc.sysinit |   27 +++
 1 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/rc.sysinit b/rc.sysinit
index 29adeca..f3e60b7 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -44,27 +44,22 @@ fi
 
 HWCLOCK_PARAMS=--hctosys
 case $HARDWARECLOCK in
-UTC) $HWCLOCK_PARAMS --utc;;
-localtime) HWCLOCK_PARAMS=$HWCLOCK_PARAMS --localtime;;
+UTC) HWCLOCK_PARAMS+= --utc;;
+localtime) HWCLOCK_PARAMS+= --localtime;;
 *) HWCLOCK_PARAMS=;;
 esac
 
-if [ -n $HWCLOCK_PARAMS ]; then
+if [[ $HWCLOCK_PARAMS ]]; then
# enable rtc access
-   /sbin/modprobe -q rtc-cmos
-   # some custom kernels use rtc/genrtc, try to load those too
-   /sbin/modprobe -q rtc
-   /sbin/modprobe -q genrtc
+   /sbin/modprobe -q -a rtc-cmos rtc genrtc
# If devtmpfs is used, the required RTC device already exists now
# Otherwise, create whatever device is available
-   if [ ! -c /dev/rtc -a ! -c /dev/rtc0 ]; then
-   if [ -f /sys/class/rtc/rtc0/dev ]; then
-   IFS=: read -r major minor  /sys/class/rtc/rtc0/dev
-   /bin/mknod /dev/rtc0 c $major $minor
-   elif [ -f /sys/class/misc/rtc/dev ]; then
-   IFS=: read -r major minor  /sys/class/misc/rtc/dev
-   /bin/mknod /dev/rtc c $major $minor
-   fi
+   if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then
+for dev in /sys/class/rtc/rtc0/dev /sys/class/misc/rtc/dev; do
+[[ -e $dev ]] || continue
+   IFS=: read -r major minor  $dev
+   /bin/mknod /dev/rtc c $major $minor
+   done
fi
 
# Do a clock set here for a few reasons:
@@ -75,7 +70,7 @@ if [ -n $HWCLOCK_PARAMS ]; then
#a later time.
# This does *NOT* take into account a time adjustment file as /var may 
not be
# mounted yet. A second set occurs later to match rc.conf.
-   if [ -f /etc/localtime ]; then
+   if [[ -f /etc/localtime ]]; then
/sbin/hwclock $HWCLOCK_PARAMS --noadjfile
fi
 fi
-- 
1.7.1



[arch-general] [PATCH 16/48] Change the daemon running loop to use a case statement.

2010-06-30 Thread Victor Lowther
This is shorter and easier to read.
---
 rc.multi |   12 +---
 1 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/rc.multi b/rc.multi
index 46c18df..ec6fda6 100755
--- a/rc.multi
+++ b/rc.multi
@@ -13,13 +13,11 @@ run_hook multi_start
 
 # Start daemons
 for daemon in ${daemo...@]}; do
-   if [[ $daemon = ${daemon#!} ]]; then
-   if [[ $daemon = ${daem...@} ]]; then
-   start_daemon $daemon
-   else
-   start_daemon_bkgd ${daemon:1}
-   fi
-   fi
+case ${daemon:0:1} in
+'!') continue;; # Skip this daemon.
+'@') start_daemon_bkgd ${daem...@};;
+*)   start_daemon $daemon;;
+esac
 done
 
 if [[ -x /etc/rc.local ]]; then
-- 
1.7.1



[arch-general] [PATCH 23/48] Clean up entropy pool saving and system clock saving.

2010-06-30 Thread Victor Lowther
---
 rc.shutdown |   22 +-
 1 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/rc.shutdown b/rc.shutdown
index cc39030..b2278b6 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -27,8 +27,8 @@ RANDOM_SEED=/var/lib/misc/random-seed
 :  $RANDOM_SEED
 /bin/chmod 0600 $RANDOM_SEED
 POOL_FILE=/proc/sys/kernel/random/poolsize
-if [ -r $POOL_FILE ]; then
-   POOL_SIZE=$(/bin/cat $POOL_FILE)
+if [[ -r $POOL_FILE ]]; then
+   read POOL_SIZE $POOL_FILE
 else
POOL_SIZE=512
 fi
@@ -36,22 +36,18 @@ fi
 stat_done
 
 stat_busy Saving System Clock
-if [ $TIMEZONE !=  -a -e /usr/share/zoneinfo/$TIMEZONE ]; then
+if [[ $TIMEZONE  -e /usr/share/zoneinfo/$TIMEZONE ]]; then
/bin/rm -f /etc/localtime
/bin/cp /usr/share/zoneinfo/$TIMEZONE /etc/localtime
 fi
 
 HWCLOCK_PARAMS=--systohc
-if [ $HARDWARECLOCK = UTC ]; then
-   HWCLOCK_PARAMS=$HWCLOCK_PARAMS --utc
-elif [ $HARDWARECLOCK = localtime ]; then
-   HWCLOCK_PARAMS=$HWCLOCK_PARAMS --localtime
-else
-   HWCLOCK_PARAMS=
-fi
-if [ -n $HWCLOCK_PARAMS ]; then
-   /sbin/hwclock $HWCLOCK_PARAMS
-fi
+case $HARDWARECLOCK in 
+UTC) HWCLOCK_PARAMS=$HWCLOCK_PARAMS --utc;;
+localtime) HWCLOCK_PARAMS=$HWCLOCK_PARAMS --localtime;;
+*) HWCLOCK_PARAMS=;;
+esac
+[[ $HWCLOCK_PARAMS ]]  /sbin/hwclock $HWCLOCK_PARAMS
 stat_done
 
 # removing psmouse module to fix some reboot issues on newer laptops
-- 
1.7.1



[arch-general] [PATCH 26/48] Clean up whitespace errors.

2010-06-30 Thread Victor Lowther
---
 rc.shutdown |   28 ++--
 1 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/rc.shutdown b/rc.shutdown
index 7d5ec26..e823ed2 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -42,7 +42,7 @@ if [[ $TIMEZONE  -e /usr/share/zoneinfo/$TIMEZONE ]]; then
 fi
 
 HWCLOCK_PARAMS=--systohc
-case $HARDWARECLOCK in 
+case $HARDWARECLOCK in
 UTC) HWCLOCK_PARAMS=$HWCLOCK_PARAMS --utc;;
 localtime) HWCLOCK_PARAMS=$HWCLOCK_PARAMS --localtime;;
 *) HWCLOCK_PARAMS=;;
@@ -73,26 +73,26 @@ if [[ -f /etc/crypttab ]]; then
# By default, initscripts used the /sbin/cryptsetup.static.
# Newer packages will only have /sbin/cryptsetup and no static binary
# This ensures maximal compatibility with the old and new layout
-for CS in /sbin/cryptsetup /usr/sbin/cryptsetup \
-/sbin/cryptsetup.static ''; do
-[[ -x $CS ]]  break
-done
-if [[ ! $CS ]]; then
-stat_append  Failed, unable to find cryptsetup.
-stat_fail
+   for CS in /sbin/cryptsetup /usr/sbin/cryptsetup \
+   /sbin/cryptsetup.static ''; do
+   [[ -x $CS ]]  break
+   done
+   if [[ ! $CS ]]; then
+   stat_append  Failed, unable to find cryptsetup.
+   stat_fail
else
-while read name src passwd opts; do
-[[ ! $name || ${name:0:1} = '#']]  continue
-[[ -b /dev/mapper/$name ]] || continue
+   while read name src passwd opts; do
+   [[ ! $name || ${name:0:1} = '#']]  continue
+   [[ -b /dev/mapper/$name ]] || continue
stat_append ${1}..
if $CS remove $name /dev/null 21; then
stat_append ok 
-else
+   else
stat_append failed 
fi
done /etc/crypttab
-fi
-stat_done
+   fi
+   stat_done
 fi
 
 if [[ $USELVM =~ yes|YES  -x /sbin/lvm  -d /sys/block ]]; then
-- 
1.7.1



[arch-general] [PATCH 45/48] Sleep instead of rebooting or shutting down when debugging initscripts

2010-06-30 Thread Victor Lowther
---
 functions   |2 +-
 rc.shutdown |3 +++
 2 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/functions b/functions
index f1dce8a..2c80a59 100644
--- a/functions
+++ b/functions
@@ -4,7 +4,7 @@
 
 # width:
 
-grep -q initdebug  {
+grep -q initdebug /proc/cmdline  {
 exec 2/dev/tty9
 }
 
diff --git a/rc.shutdown b/rc.shutdown
index 1081970..96b10f0 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -93,6 +93,9 @@ run_hook shutdown_poweroff
 
 # Power off or reboot
 printsep
+
+grep -q initdebug /proc/cmdline  sleep 
+
 if [[ $RUNLEVEL = 0 ]]; then
printhl ${C_H2}POWER OFF
/sbin/poweroff -d -f -h -i
-- 
1.7.1



[arch-general] [PATCH 22/48] Use parameter expansion instead of dirname.

2010-06-30 Thread Victor Lowther
---
 rc.shutdown |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/rc.shutdown b/rc.shutdown
index ef9b16d..cc39030 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -23,7 +23,7 @@ kill_everything
 
 stat_busy Saving Random Seed
 RANDOM_SEED=/var/lib/misc/random-seed
-[ -d $(dirname $RANDOM_SEED) ] || mkdir -p $(dirname $RANDOM_SEED)
+[[ -d ${RANDOM_SEED%/*} ]] || mkdir -p ${RANDOM_SEED%/*}
 :  $RANDOM_SEED
 /bin/chmod 0600 $RANDOM_SEED
 POOL_FILE=/proc/sys/kernel/random/poolsize
-- 
1.7.1



[arch-general] [PATCH 27/48] Start tightening up rc.sysinit.

2010-06-30 Thread Victor Lowther
---
 rc.sysinit |   21 -
 1 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/rc.sysinit b/rc.sysinit
index c62ae8d..29adeca 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -17,12 +17,9 @@ printsep
 run_hook sysinit_start
 
 # mount /proc, /sys and our RAM /dev
-if ! /bin/mountpoint -q /proc; then
-  /bin/mount -n -t proc none /proc
-fi
-if ! /bin/mountpoint -q /sys; then
-  /bin/mount -n -t sysfs none /sys
-fi
+/bin/mountpoint -q /proc || /bin/mount -n -t proc none /proc
+/bin/mountpoint -q /sys  || /bin/mount -n -t sysfs none /sys
+
 if ! /bin/mountpoint -q /dev; then
   if grep -q devtmpfs /proc/filesystems 2/dev/null; then
 /bin/mount -n -t devtmpfs udev /dev -o mode=0755,size=10M,nosuid
@@ -46,13 +43,11 @@ else
 fi
 
 HWCLOCK_PARAMS=--hctosys
-if [ $HARDWARECLOCK = UTC ]; then
-   HWCLOCK_PARAMS=$HWCLOCK_PARAMS --utc
-elif [ $HARDWARECLOCK = localtime ]; then
-   HWCLOCK_PARAMS=$HWCLOCK_PARAMS --localtime
-else
-   HWCLOCK_PARAMS=
-fi
+case $HARDWARECLOCK in
+UTC) $HWCLOCK_PARAMS --utc;;
+localtime) HWCLOCK_PARAMS=$HWCLOCK_PARAMS --localtime;;
+*) HWCLOCK_PARAMS=;;
+esac
 
 if [ -n $HWCLOCK_PARAMS ]; then
# enable rtc access
-- 
1.7.1



[arch-general] [PATCH 44/48] Save error messages to /dev/tty9.

2010-06-30 Thread Victor Lowther
---
 functions |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/functions b/functions
index 9ec8b5e..f1dce8a 100644
--- a/functions
+++ b/functions
@@ -4,6 +4,10 @@
 
 # width:
 
+grep -q initdebug  {
+exec 2/dev/tty9
+}
+
 STAT_COL=80
 if [[ ! -t 1 ]]; then
 USECOLOR=
-- 
1.7.1



[arch-general] [PATCH 46/48] Bashify adjtime.cron

2010-06-30 Thread Victor Lowther
---
 adjtime.cron |   16 +++-
 1 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/adjtime.cron b/adjtime.cron
index b1c8950..a876506 100755
--- a/adjtime.cron
+++ b/adjtime.cron
@@ -4,14 +4,12 @@
 . /etc/rc.conf
 
 HWCLOCK_PARAMS=--adjust
-if [ $HARDWARECLOCK = UTC ]; then
-   HWCLOCK_PARAMS=$HWCLOCK_PARAMS --utc
-elif [ $HARDWARECLOCK = localtime ]; then
-   HWCLOCK_PARAMS=$HWCLOCK_PARAMS --localtime
-else
-   HWCLOCK_PARAMS=
-fi
+case $HARDWARECLOCK in
+UTC) HWCLOCK_PARAMS+= --utc;;
+localtime) HWCLOCK_PARAMS+= --localtime;;
+*) HWCLOCK_PARAMS=;;
+esac
 
-if [ -n $HWCLOCK_PARAMS ]; then
-   /sbin/hwclock $HWCLOCK_PARAMS
+if [[ $HWCLOCK_PARAMS ]]; then
+/sbin/hwclock $HWCLOCK_PARAMS
 fi
-- 
1.7.1



[arch-general] [PATCH 35/48] find has a builtin delete action. Use it instead of exec'ing rm.

2010-06-30 Thread Victor Lowther
---
 rc.sysinit |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/rc.sysinit b/rc.sysinit
index 319ea60..037a9f2 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -277,7 +277,7 @@ stat_busy Removing Leftover Files
 /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 -- {} \; )
+(cd /var/run  /usr/bin/find . \! -type d -delete  )
 : | /var/run/utmp
 /bin/chmod 0664 /var/run/utmp
 # Keep {x,k,g}dm happy with xorg
-- 
1.7.1



[arch-general] [PATCH 29/48] Bashify module loading in rc.sysinit.

2010-06-30 Thread Victor Lowther
---
 rc.sysinit |   16 +++-
 1 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/rc.sysinit b/rc.sysinit
index f3e60b7..1d16224 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -92,16 +92,14 @@ if /bin/pidof -o %PPID /sbin/udevd /dev/null; then
 fi
 
 # Load modules from the MODULES array defined in rc.conf
-if ! [ $load_modules = off ]; then
-   if [ -f /proc/modules ]; then
-   stat_busy Loading Modules
-   for mod in ${modul...@]}; do
-   if [ $mod = ${mod#!} ]; then
-   /sbin/modprobe $mod
-   fi
-   done
-   stat_done
+if [[ $load_modules != off  -f /proc/modules ]]; then
+stat_busy Loading Modules
+for mod in ${modul...@]}; do
+   if [[ $mod = ${mod#!} ]]; then
+   /sbin/modprobe $mod
fi
+done
+stat_done
 fi
 
 # Wait for udev uevents
-- 
1.7.1



[arch-general] [PATCH 39/48] Flatten adding persistent rules.

2010-06-30 Thread Victor Lowther
---
 rc.sysinit |   16 ++--
 1 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/rc.sysinit b/rc.sysinit
index c6ed35f..ac32fca 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -342,16 +342,12 @@ fi
 set_consolefont
 
 # Adding persistent network/cdrom generated rules
-if [ -f /dev/.udev/tmp-rules--70-persistent-cd.rules ]; then
-   stat_busy Adding persistent cdrom udev rules
-   /bin/cat /dev/.udev/tmp-rules--70-persistent-cd.rules  
/etc/udev/rules.d/70-persistent-cd.rules
-   stat_done
-fi
-if [ -f /dev/.udev/tmp-rules--70-persistent-net.rules ]; then
-   stat_busy Adding persistent network udev rules
-   /bin/cat /dev/.udev/tmp-rules--70-persistent-net.rules  
/etc/udev/rules.d/70-persistent-net.rules
-   stat_done
-fi
+for f in cd net; do
+[[ -f /dev/.udev/tmp-rules--70-persistent-$f.rules ]] || continue
+stat_busy Adding persistent $f udev rules
+/bin/cat /dev/.udev/tmp-rules--70-persistent-$f.rules  
/etc/udev/rules.d/70-persistent-$f.rules
+stat_done
+done
 
 /bin/dmesg | /var/log/dmesg.log
 
-- 
1.7.1



[arch-general] [PATCH 30/48] bashify bringing up the loopback adaptor.

2010-06-30 Thread Victor Lowther
---
 rc.sysinit |9 -
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/rc.sysinit b/rc.sysinit
index 1d16224..31636e5 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -113,13 +113,12 @@ fi
 run_hook sysinit_udevsettled
 
 # bring up the loopback interface
-if [ -d /sys/class/net/lo ]; then
+if [[ -d /sys/class/net/lo ]]; then
stat_busy Bringing up loopback interface
-   /sbin/ifconfig lo 127.0.0.1 up
-   if [ $? -ne 0 ]; then
-   stat_fail
+   if ! /sbin/ifconfig lo 127.0.0.1 up; then
+   stat_fail
else
-   stat_done
+   stat_done
fi
 fi
 
-- 
1.7.1



[arch-general] [PATCH 18/48] Bashify conditional checking in rc.single.

2010-06-30 Thread Victor Lowther
---
 rc.single |   16 
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/rc.single b/rc.single
index f986a2a..aa58b4c 100755
--- a/rc.single
+++ b/rc.single
@@ -8,10 +8,10 @@
 
 run_hook single_start
 
-if [ $PREVLEVEL != N ]; then
+if [[ $PREVLEVEL != N ]]; then
 
# Find daemons NOT in the DAEMONS array. Shut these down first
-   if [ -d /var/run/daemons ]; then
+   if [[ -d /var/run/daemons ]]; then
for daemon in $(/bin/ls -1t /var/run/daemons); do
  if ! in_array $daemon ${daemo...@]}; then
stop_daemon $daemon
@@ -20,8 +20,8 @@ if [ $PREVLEVEL != N ]; then
fi
# Shutdown daemons in reverse order
let i=${#daemo...@]}-1
-   while [ $i -ge 0 ]; do
-   if [ ${DAEMONS[$i]:0:1} != '!' ]; then
+   while ((i = 0)); do
+   if [[ ${DAEMONS[$i]:0:1} != '!' ]]; then
ck_daemon ${daemons[$...@} || stop_daemon 
${daemons[$...@}
fi
let i=i-1
@@ -66,17 +66,17 @@ if [ $PREVLEVEL != N ]; then
run_hook single_udevsettled
 
# try syslog-NG first, then fall back to good ol' syslogd
-   if [ -x /etc/rc.d/syslog-ng ]; then
+   if [[ -x /etc/rc.d/syslog-ng ]]; then
/etc/rc.d/syslog-ng start
-   elif [ -x /etc/rc.d/syslogd ]; then
+   elif [[ -x /etc/rc.d/syslogd ]]; then
/etc/rc.d/syslogd start
-   [ -x /etc/rc.d/klogd ]  /etc/rc.d/klogd start
+   [[ -x /etc/rc.d/klogd ]]  /etc/rc.d/klogd start
fi
 fi
 
 run_hook single_end
 
-if [ $RUNLEVEL = 1 ]; then
+if [[ $RUNLEVEL = 1 ]]; then
printsep
printhl Entering single-user mode...
# make sure /dev/initctl is in place
-- 
1.7.1



[arch-general] [PATCH 32/48] Rewrite /etc/crypttab processing.

2010-06-30 Thread Victor Lowther
Split out reading /etc/crypttab and procssing the individual lines into
their own helper functions, and bashify the resulting shorter code.

Processing this file is still ugly, though. :(
---
 functions   |   43 +--
 rc.shutdown |   36 +
 rc.sysinit  |  131 ++
 3 files changed, 90 insertions(+), 120 deletions(-)

diff --git a/functions b/functions
index bf6ed45..9ec8b5e 100644
--- a/functions
+++ b/functions
@@ -232,6 +232,40 @@ kill_everything() {
 run_hook single_postkillall
 }
 
+activate_vgs() {
+[[ $USELVM =~ yes|YES  -x /sbin/lvm  -d /sys/block ]] || return
+# Kernel 2.6.x, LVM2 groups
+/sbin/modprobe -q dm-mod 2/dev/null
+stat_busy Activating LVM2 groups
+if /sbin/lvm vgchange --ignorelockingfailure -a y /dev/null; then
+   stat_done
+else
+   stat_fail
+ fi
+}
+
+# Arch cryptsetup packages traditionally contained the binaries
+#  /usr/sbin/cryptsetup
+#  /sbin/cryptsetup.static
+# By default, initscripts used the /sbin/cryptsetup.static.
+# Newer packages will only have /sbin/cryptsetup and no static binary
+# This ensures maximal compatibility with the old and new layout
+for CS in /sbin/cryptsetup /usr/sbin/cryptsetup \
+/sbin/cryptsetup.static ''; do
+[[ -x $CS ]]  break
+done
+
+read_crypttab() {
+# $1 = function to call with the split out line from the crypttab
+local line nspo failed=0
+while read line; do
+[[ $line  ${line:0:1} != '#' ]] || continue
+eval nspo=(${line%#*})
+$1 ${ns...@]} || failed=1
+done  /etc/crypttab
+return $failed
+}
+
 ###
 # Custom hooks in initscripts #
 ###
@@ -278,7 +312,7 @@ run_hook() {
 [[ $1 ]] || return 1
 local func
 for func in ${hook_funcs[$1]}; do
-   ${func}
+   q${func}
 done
 }
 
@@ -293,13 +327,14 @@ set_consolefont() {
 for i in /dev/tty[0-9]*; do
/usr/bin/setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \
$CONSOLEFONT -C ${i} /dev/null 21
-done
+   done
 if (($? != 0)); then
stat_fail
 elif [[ $CONSOLEMAP ]]; then
cat EOF /etc/profile.d/locale.sh
-if [ $CONSOLE =  -a $TERM = linux -a -t 1 ]; then printf \033(K; fi
-
+if [ $CONSOLE =  -a $TERM = linux -a -t 1 ]
+then printf \033(K
+fi
 EOF
stat_done
 fi
diff --git a/rc.shutdown b/rc.shutdown
index e823ed2..1081970 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -65,33 +65,17 @@ stat_busy Unmounting Filesystems
 stat_done
 
 # Kill non-root encrypted partition mappings
-if [[ -f /etc/crypttab ]]; then
+if [[ -f /etc/crypttab  $CS ]]; then
stat_busy Deactivating encrypted volumes:
-   # Arch cryptsetup packages traditionally contained the binaries
-   #  /usr/sbin/cryptsetup
-   #  /sbin/cryptsetup.static
-   # By default, initscripts used the /sbin/cryptsetup.static.
-   # Newer packages will only have /sbin/cryptsetup and no static binary
-   # This ensures maximal compatibility with the old and new layout
-   for CS in /sbin/cryptsetup /usr/sbin/cryptsetup \
-   /sbin/cryptsetup.static ''; do
-   [[ -x $CS ]]  break
-   done
-   if [[ ! $CS ]]; then
-   stat_append  Failed, unable to find cryptsetup.
-   stat_fail
-   else
-   while read name src passwd opts; do
-   [[ ! $name || ${name:0:1} = '#']]  continue
-   [[ -b /dev/mapper/$name ]] || continue
-   stat_append ${1}..
-   if $CS remove $name /dev/null 21; then
-   stat_append ok 
-   else
-   stat_append failed 
-   fi
-   done /etc/crypttab
-   fi
+   do_lock() {
+stat_append ${1}..
+if $CS remove $1 /dev/null 21; then
+stat_append ok 
+   else
+stat_append failed 
+   fi
+}
+read_crypttab do_lock
stat_done
 fi
 
diff --git a/rc.sysinit b/rc.sysinit
index 404e11a..d54b9bb 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -127,104 +127,55 @@ if [[ -f /etc/mdadm.conf ]]  /bin/grep -q ^ARRAY 
/etc/mdadm.conf; then
status Activating RAID arrays /sbin/mdadm --assemble --scan
 fi
 
-if [ $USELVM = yes -o $USELVM = YES ]; then
-   if [ -x /sbin/lvm -a -d /sys/block ]; then
-   # Kernel 2.6.x, LVM2 groups
-   /sbin/modprobe -q dm-mod 2/dev/null
-   stat_busy Activating LVM2 groups
-   /sbin/lvm vgchange --ignorelockingfailure -a y /dev/null
-   if [ $? -ne 0 ]; then
-   stat_fail
-   else
-   stat_done
-   fi
-   fi
-fi
+activate_vgs
 
 # Set up non-root encrypted partition mappings
-if [ -f /etc/crypttab -a -n $(/bin/grep -v ^# /etc/crypttab | /bin/grep -v 
^$) ]; then
-   /sbin/modprobe -q dm-mod 

[arch-general] [PATCH 48/48] Trivial bashification of network

2010-06-30 Thread Victor Lowther
---
 network |   70 +++---
 1 files changed, 31 insertions(+), 39 deletions(-)

diff --git a/network b/network
index 40f1a90..20ff9c7 100755
--- a/network
+++ b/network
@@ -9,17 +9,15 @@ done
 
 ifup()
 {
-if [ $1 =  ]; then
+if [[ ! $1 ]]; then
 echo usage: $0 ifup interface_name
 return 1
 fi
-
 eval ifcfg=\$${1}
 
 # Get the name of the interface from the first token in the string
-
-if [ $ifcfg = dhcp ]; then
-ifname=$1
+if [[ $ifcfg = dhcp ]]; then
+ifname=$1
 else
 ifname=${ifcfg%% *}
 fi
@@ -28,7 +26,7 @@ ifup()
 
 wi_up $1 || return 1
 
-if [ $ifcfg = dhcp ]; then
+if [[ $ifcfg = dhcp ]]; then
 # remove the .pid file if it exists
 /bin/rm -f /var/run/dhcpcd-${1}.pid /dev/null 21
 /bin/rm -f /var/run/dhcpcd-${1}.cache /dev/null 21
@@ -36,20 +34,19 @@ ifup()
 else
 /sbin/ifconfig $ifcfg
 fi
-return $?
 }
 
 wi_up()
 {
 eval iwcfg=\$wlan_${1}
-[ $iwcfg =  ]  return 0
+[[ ! $iwcfg ]]  return 0
 
 /usr/sbin/iwconfig $iwcfg
-[[ -z $WIRELESS_TIMEOUT ]]  WIRELESS_TIMEOUT=2
+[[ $WIRELESS_TIMEOUT ]] || WIRELESS_TIMEOUT=2
 sleep $WIRELESS_TIMEOUT
 
-bssid=`iwgetid $1 -ra`
-if [[ $bssid = 00:00:00:00:00:00 ]]; then
+bssid=$(iwgetid $1 -ra)
+if [[ $bssid = 00:00:00:00:00:00 ]]; then
 printhl Could not associate $1 - try increasing WIRELESS_TIMEOUT and 
check network is WEP or has no security
 return 1
 fi
@@ -58,25 +55,22 @@ wi_up()
 
 ifdown()
 {
-if [ $1 =  ]; then
+if [[ ! $1 ]]; then
 echo usage: $0 ifdown interface_name
 return 1
 fi
 eval ifcfg=\$${1}
-if [ $ifcfg = dhcp ]; then
-if [ -f /var/run/dhcpcd-${1}.pid ]; then
-/bin/kill $(cat /var/run/dhcpcd-${1}.pid)
-fi
+if [[ $ifcfg = dhcp  -f /var/run/dhcpcd-${1}.pid ]]; then
+/bin/kill $(cat /var/run/dhcpcd-${1}.pid)
 fi
 # Always bring the interface itself down
 /sbin/ifconfig ${1} down /dev/null 21
-return $?
 }
 
 iflist()
 {
 for ifline in ${interfac...@]}; do
-if [ $ifline = ${ifline#!} ]; then
+if [[ $ifline = ${ifline#!} ]]; then
 printf  $ifline:\t
 else
 printf $ifline:\t
@@ -88,38 +82,36 @@ iflist()
 
 rtup()
 {
-if [ $1 =  ]; then
+if [[ ! $1 ]]; then
 echo usage: $0 rtup route_name
 return 1
 fi
 eval routecfg=\$${1}
-if grep -q ::  $routecfg; then
+if [[ $routecfg =~ :: ]]; then
 /sbin/route -A inet6 add $routecfg
 else
 /sbin/route add $routecfg
 fi
-return $?
 }
 
 rtdown()
 {
-if [ $1 =  ]; then
+if [[ ! $1 ]; then
 echo usage: $0 rtdown route_name
 return 1
 fi
 eval routecfg=\$${1}
-if grep -q ::  $routecfg; then
+if [[ $routecfg =~ :: ]]; then
 /sbin/route -A inet6 del $routecfg
 else
 /sbin/route del $routecfg
 fi
-return $?
 }
 
 rtlist()
 {
 for rtline in ${rout...@]}; do
-if [ $rtline = ${rtline#!} ]; then
+if [[ $rtline = ${rtline#!} ]]; then
 printf  $rtline:\t
 else
 printf $rtline:\t
@@ -132,9 +124,9 @@ rtlist()
 bond_up()
 {
 for ifline in ${bond_interfac...@]}; do
-if [ $ifline = ${ifline#!} ]; then
+if [[ $ifline = ${ifline#!} ]]; then
 eval bondcfg=\$bond_${ifline}
-if [ -n ${bondcfg} ]; then
+if [[ ${bondcfg} ]]; then
 /sbin/ifenslave $ifline $bondcfg || error=1
 fi
 fi
@@ -144,7 +136,7 @@ bond_up()
 bond_down()
 {
 for ifline in ${bond_interfac...@]}; do
-if [ $ifline = ${ifline#!} ]; then
+if [[ $ifline = ${ifline#!} ]]; then
 eval bondcfg=\$bond_${ifline}
 /sbin/ifenslave -d $ifline $bondcfg || error=1
 fi
@@ -154,18 +146,18 @@ bond_down()
 bridge_up()
 {
 for br in ${bridge_interfac...@]}; do
-if [ $br = ${br#!} ]; then
+if [[ $br = ${br#!} ]]; then
 # if the bridge already exists, remove it
-if [ $(/sbin/ifconfig $br 2/dev/null) ]; then
+if [[ $(/sbin/ifconfig $br 2/dev/null) ]]; then
 /sbin/ifconfig $br down
 /usr/sbin/brctl delbr $br
 fi
 /usr/sbin/brctl addbr $br
 eval brifs=\$bridge_${br}
 for brif in $brifs; do
-if [ $brif = ${brif#!} ]; then
+if [[ $brif = ${brif#!} ]]; then
 for ifline in ${bond_interfac...@]}; do
-if [ $brif = $ifline ]  [ $ifline = 
${ifline#!} ]; then
+if [[ $brif = $ifline  $ifline = ${ifline#!} ]]; then
 ifup $ifline
 eval bondcfg=\$bond_${ifline}
 

[arch-general] [PATCH 21/48] Both rc.single and rc.shutdown use the same code to kill everything.

2010-06-30 Thread Victor Lowther
Move that shared code into functions.
---
 functions   |   29 +
 rc.shutdown |   32 +---
 rc.single   |   27 +--
 3 files changed, 31 insertions(+), 57 deletions(-)

diff --git a/functions b/functions
index d8e8e54..bf6ed45 100644
--- a/functions
+++ b/functions
@@ -203,6 +203,35 @@ ck_status() {
   fi
 }
 
+kill_everything() {
+# Find daemons NOT in the DAEMONS array. Shut these down first
+for daemon in /var/run/daemons/*; do
+[[ -f $daemon ]] || continue
+daemon=${daemon##*/}
+   in_array $daemon ${daemo...@]} || stop_daemon $daemon
+done
+   
+# Shutdown daemons in reverse order
+for ((i=${#daemo...@]}-1; i=0; i--)); do
+   [[ ${DAEMONS[$i]:0:1} = '!' ]]  continue
+   ck_daemon ${daemons[$...@} || stop_daemon ${daemons[$...@}
+done
+
+   # Terminate all processes
+stat_busy Sending SIGTERM To Processes
+run_hook single_prekillall
+/sbin/killall5 -15  /dev/null
+/bin/sleep 5
+stat_done
+
+stat_busy Sending SIGKILL To Processes
+/sbin/killall5 -9  /dev/null
+/bin/sleep 1
+stat_done
+
+run_hook single_postkillall
+}
+
 ###
 # Custom hooks in initscripts #
 ###
diff --git a/rc.shutdown b/rc.shutdown
index 002a45d..ef9b16d 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -19,37 +19,7 @@ echo  
 [[ -x /bin/domainname ]]  /bin/domainname 
 [[ -x /etc/rc.local.shutdown ]]  /etc/rc.local.shutdown
 
-
-# Find daemons NOT in the DAEMONS array. Shut these down first
-if [ -d /var/run/daemons ]; then
-   for daemon in $(/bin/ls -1t /var/run/daemons); do
-   if ! in_array $daemon ${daemo...@]}; then
-   stop_daemon $daemon
-   fi
-   done
-fi
-# Shutdown daemons in reverse order
-let i=${#daemo...@]}-1
-while [ $i -ge 0 ]; do
-   if [ ${DAEMONS[$i]:0:1} != '!' ]; then
-   ck_daemon ${daemons[$...@} || stop_daemon ${daemons[$...@}
-   fi
-   let i=i-1
-done
-
-# Terminate all processes
-stat_busy Sending SIGTERM To Processes
-run_hook shutdown_prekillall
-/sbin/killall5 -15  /dev/null
-/bin/sleep 5
-stat_done
-
-stat_busy Sending SIGKILL To Processes
-/sbin/killall5 -9  /dev/null
-/bin/sleep 1
-stat_done
-
-run_hook shutdown_postkillall
+kill_everything
 
 stat_busy Saving Random Seed
 RANDOM_SEED=/var/lib/misc/random-seed
diff --git a/rc.single b/rc.single
index aa27be0..a84ece8 100755
--- a/rc.single
+++ b/rc.single
@@ -9,33 +9,8 @@
 run_hook single_start
 
 if [[ $PREVLEVEL != N ]]; then
-# Find daemons NOT in the DAEMONS array. Shut these down first
-for daemon in /var/run/daemons/*; do
-[[ -f $daemon ]] || continue
-daemon=${daemon##*/}
-   in_array $daemon ${daemo...@]} || stop_daemon $daemon
-done
-   
-# Shutdown daemons in reverse order
-for ((i=${#daemo...@]}-1; i=0; i--)); do
-   [[ ${DAEMONS[$i]:0:1} = '!' ]]  continue
-   ck_daemon ${daemons[$...@} || stop_daemon ${daemons[$...@}
-done
-
-   # Terminate all processes
-   stat_busy Sending SIGTERM To Processes
-   run_hook single_prekillall
-   /sbin/killall5 -15  /dev/null
-   /bin/sleep 5
-   stat_done
-
-   stat_busy Sending SIGKILL To Processes
-   /sbin/killall5 -9  /dev/null
-   /bin/sleep 1
-   stat_done
-
-   run_hook single_postkillall
 
+kill_everything
stat_busy Starting UDev Daemon
/sbin/udevd --daemon
stat_done
-- 
1.7.1



[arch-general] [PATCH 41/48] Bashify netfs

2010-06-30 Thread Victor Lowther
---
 netfs |6 ++
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/netfs b/netfs
index cdfdf98..d4a926f 100755
--- a/netfs
+++ b/netfs
@@ -12,8 +12,7 @@ case $1 in
/bin/mount -a -t 
nfs,nfs4,smbfs,codafs,ncpfs,cifs,shfs,glusterfs,fuse,fuseblk,fuse.glusterfs
rc=$?
/bin/mount -a -O _netdev
-   rc=$(($rc+$?))
-   if [ $rc -gt 0 ]; then
+   if ((rc + $?  0)); then
stat_fail
else
add_daemon netfs
@@ -25,8 +24,7 @@ case $1 in
/bin/umount -a -O _netdev
rc=$?
/bin/umount -a -t 
nfs,nfs4,smbfs,codafs,ncpfs,cifs,shfs,glusterfs,fuse,fuseblk,fuse.glusterfs
-   rc=$(($rc+$?))
-   if [ $rc -gt 0 ]; then
+   if ((rc + $?  0)); then
stat_fail
else
rm_daemon netfs
-- 
1.7.1



[arch-general] [PATCH 19/48] Simplify daemon-killing loops in rc.single.

2010-06-30 Thread Victor Lowther
Parsing the output of ls is Bad, especially when globbing works just as well
and does not get confused by odd characters in filenames.

bash has arithemetic for loops. Use them instead of while loops for iterating
over arrays.
---
 rc.single |   29 -
 1 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/rc.single b/rc.single
index aa58b4c..aa27be0 100755
--- a/rc.single
+++ b/rc.single
@@ -9,23 +9,18 @@
 run_hook single_start
 
 if [[ $PREVLEVEL != N ]]; then
-
-   # Find daemons NOT in the DAEMONS array. Shut these down first
-   if [[ -d /var/run/daemons ]]; then
-   for daemon in $(/bin/ls -1t /var/run/daemons); do
- if ! in_array $daemon ${daemo...@]}; then
-   stop_daemon $daemon
- fi
-   done
-   fi
-   # Shutdown daemons in reverse order
-   let i=${#daemo...@]}-1
-   while ((i = 0)); do
-   if [[ ${DAEMONS[$i]:0:1} != '!' ]]; then
-   ck_daemon ${daemons[$...@} || stop_daemon 
${daemons[$...@}
-   fi
-   let i=i-1
-   done
+# Find daemons NOT in the DAEMONS array. Shut these down first
+for daemon in /var/run/daemons/*; do
+[[ -f $daemon ]] || continue
+daemon=${daemon##*/}
+   in_array $daemon ${daemo...@]} || stop_daemon $daemon
+done
+   
+# Shutdown daemons in reverse order
+for ((i=${#daemo...@]}-1; i=0; i--)); do
+   [[ ${DAEMONS[$i]:0:1} = '!' ]]  continue
+   ck_daemon ${daemons[$...@} || stop_daemon ${daemons[$...@}
+done
 
# Terminate all processes
stat_busy Sending SIGTERM To Processes
-- 
1.7.1



Re: [arch-general] [PATCH 01/48] Bashification of initscripts

2010-06-30 Thread Victor Lowther
On Wed, 2010-06-30 at 23:55 +0200, Thomas Bächler wrote:
 Am 30.06.2010 23:47, schrieb Victor Lowther:
  Despite efforts to make the initscripts POSIX, we use bash 4.0 features.
  
  Bashifying this framework should result in about a 30% speedup, assuming no
  IO latency and that all programs we call also take zero time. :)
  ---
   functions |2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)
  
  diff --git a/functions b/functions
  index 672eed2..023de35 100644
  --- a/functions
  +++ b/functions
  @@ -1,4 +1,4 @@
  -#
  +#!/bin/bash
   # initscripts functions
 
 I don't see the need for this patch. functions is not supposed to be
 executed standalone, it is only source'd from bash scripts.

It is a habit I have -- including the shebang line at the top makes sure
my text editors automatically detect the right shell syntax for syntax
highlighting.

-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] [PATCH 04/48] Use [[ ]] instead of [ ] for conditional checking when running in bash.

2010-06-30 Thread Victor Lowther
On Wed, 2010-06-30 at 23:56 +0200, Thomas Bächler wrote:
 Am 30.06.2010 23:47, schrieb Victor Lowther:
  It is worth 10 - 30% speedup whenever you want to compare something.
 
 Where do you get this from? I always used [ ], and I found it
 sufficient. Why is [[ ]] faster?

[[ ]] is faster because it is bash syntax, not a builtin command like
[ is. In most programs, both are fast enough, but you an see the
difference if you run otherwise identical tests in a loop one million
times.

 
  -if [ $USECOLOR = YES -o $USECOLOR = yes ]; then
  +if [[ $USECOLOR = YES || $USECOLOR = yes ]]; then
 
 Why do you get rid of the quoting here? Quoting is nice.

Because [[ ]] is bash syntax instead if a builtin comand, it relaxes the
usual expansion rules -- inside of [[ ]], word splitting and pathname
expansion are not performed, so you only have to quote strings if they
need to be single-quoted.
http://wiki.bash-hackers.org/syntax/ccmd/conditional_expression has more
info.

-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] [PATCH 05/48] a little creative parameter expansion simplifies stat_die()

2010-06-30 Thread Victor Lowther
On Wed, 2010-06-30 at 23:57 +0200, Thomas Bächler wrote:
 Nice patch, but ...
 
  -if [ -t 1 ]; then
  +if [[ -t 1 ]]; then
  SAVE_POSITION=\033[s
  RESTORE_POSITION=\033[u
  DEL_TEXT=\033[$(($STAT_COL+4))G
  @@ -116,10 +116,8 @@ stat_fail() {
 
 Hmm, this definitely doesn't belong into this patch.


Yeah, I think it got smashed together while I was rebasing things to
clean up.

   }
   
   stat_die() {
  -   retval=1
  -   [ $1 =  ] || retval=$1
  stat_fail
  -   exit $retval
  +   exit ${1:-1}
   }
   
   status() {
 
 Okay, this is certainly nicer than before.
 

-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] [PATCH 35/48] find has a builtin delete action. Use it instead of exec'ing rm.

2010-06-30 Thread Victor Lowther
On Wed, 2010-06-30 at 17:58 -0400, Daenyth Blank wrote:
 On Wed, Jun 30, 2010 at 17:47, Victor Lowther victor.lowt...@gmail.com 
 wrote:
  ---
   rc.sysinit |2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)
 
  diff --git a/rc.sysinit b/rc.sysinit
  index 319ea60..037a9f2 100755
  --- a/rc.sysinit
  +++ b/rc.sysinit
  @@ -277,7 +277,7 @@ stat_busy Removing Leftover Files
   /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 -- {} \; )
  +(cd /var/run  /usr/bin/find . \! -type d -delete  )
   : | /var/run/utmp
   /bin/chmod 0664 /var/run/utmp
   # Keep {x,k,g}dm happy with xorg
  --
  1.7.1
 
 
 
 I don't think this is portable though.

How portable are you looking for?

-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] [PATCH 08/48] Slightly simplify hook-running infrastructure.

2010-06-30 Thread Victor Lowther
On Thu, 2010-07-01 at 00:00 +0200, Thomas Bächler wrote:
 Am 30.06.2010 23:47, schrieb Victor Lowther:
  Go ahead and declare add_hook and run_hook as readonly functions
  to prevent hooks from overwriting them.  Too bad bash does not have
  lexically scoped variables -- if it does, we could do the same with
  the hook_funcs associative array.
 
 Lots of hunks below that have nothing to do with the actual change made
 here:

Probably got smashed in.  I did alot of git rebase -i to clean things
up.  Splitting it back out will not be a problem.

  diff --git a/functions b/functions
  index 8bbdfc6..d9f55fa 100644
  --- a/functions
  +++ b/functions
  @@ -148,38 +148,39 @@ in_array() {
   # daemons:
   
   add_daemon() {
  -   [ -d /var/run/daemons ] || /bin/mkdir -p /var/run/daemons
  -   /bin/touch /var/run/daemons/$1
  +   [[ -d /var/run/daemons ]] || /bin/mkdir -p /var/run/daemons
  +/var/run/daemons/$1
   }
   
   rm_daemon() {
  -   /bin/rm -f /var/run/daemons/$1
  +   /bin/rm -f /var/run/daemons/$1
   }
   
   ck_daemon() {
  -   [ -f /var/run/daemons/$1 ]  return 1
  -   return 0
  +   [[ ! -f /var/run/daemons/$1 ]]
   }
   
  -ck_depends() {
  -   for daemon in $@; do
  -   if ck_daemon $daemon; then
  -   /etc/rc.d/$daemon start
  -   fi
  -   done
  +have_daemon() {
  +[[ -x /etc/rc.d/$1 ]]
   }
   
   start_daemon() {
  -   /etc/rc.d/$1 start
  +have_daemon $1  /etc/rc.d/$1 start
  +}
  +
  +ck_depends() {
  +for daemon in $@; do
  +   ck_daemon $daemon  start_daemon $daemon 
  +done
   }
   
   start_daemon_bkgd() {
  stat_bkgd Starting $1
  -   (/etc/rc.d/$1 start) /dev/null 
  +   have_daemon $1  (start_daemon $1) /dev/null 
   }
   
   stop_daemon() {
  -   /etc/rc.d/$1 stop
  +   have_daemon $1  /etc/rc.d/$1 stop
   }
 
 Here the actual patch starts, the above doesn't belong into this patch.
 You should _really_ check out git add -p/-i
 
   # Status functions
  @@ -234,24 +235,26 @@ ck_status() {
   # single_postkillall: after all processes have been killed in rc.single
   # shutdown_poweroff: directly before powering off in rc.shutdown
   #
  -# Make sure to never override the add_hook and run_hook functions via 
  functions.d
  +# Declare add_hook and run_hook as read-only to prevent overwriting them.
  +# Too bad we cannot do the same thing with hook_funcs 
   
   declare -A hook_funcs
   
   add_hook() {
  -   [ -z $1 -o -z $2 ]  return 1
  -   hook_funcs[$1]=${hook_funcs[$1]} $2
  +   [[ $1  $2 ]] || return 1
  +   hook_funcs[$1]+= $2
   }
 
 += in bash? Really? Didn't know that worked.
 
   run_hook() {
  -   local func
  -
  -   [ -z $1 ]  return 1
  -   for func in ${hook_funcs[$1]}; do
  -   ${func}
  -   done
  +[[ $1 ]] || return 1
  +local func
  +for func in ${hook_funcs[$1]}; do
  +   ${func}
  +done
   }
   
  +declare -r add_hook run_hook
  +
 
 Nice, I didn't know you could do that.
 
   # Function for setting console font if required
   set_consolefont() {
   if [ -n $CONSOLEFONT ]; then
 
 

-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] [PATCH 30/48] bashify bringing up the loopback adaptor.

2010-06-30 Thread Victor Lowther
On Thu, 2010-07-01 at 00:13 +0200, Thomas Bächler wrote:
 Am 30.06.2010 23:47, schrieb Victor Lowther:
  ---
   rc.sysinit |9 -
   1 files changed, 4 insertions(+), 5 deletions(-)
  
  diff --git a/rc.sysinit b/rc.sysinit
  index 1d16224..31636e5 100755
  --- a/rc.sysinit
  +++ b/rc.sysinit
  @@ -113,13 +113,12 @@ fi
   run_hook sysinit_udevsettled
   
   # bring up the loopback interface
  -if [ -d /sys/class/net/lo ]; then
  +if [[ -d /sys/class/net/lo ]]; then
  stat_busy Bringing up loopback interface
  -   /sbin/ifconfig lo 127.0.0.1 up
  -   if [ $? -ne 0 ]; then
  -   stat_fail
  +   if ! /sbin/ifconfig lo 127.0.0.1 up; then
  +   stat_fail
  else
  -   stat_done
  +   stat_done
  fi
   fi
   
 
 Hmm, this could be done with the status() function instead, right? No
 need for stat_{busy,fail,done} then.

Probably.  I was just looking for trivial bashification here -- I did
not look for further simplifications.


-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] [PATCH 32/48] Rewrite /etc/crypttab processing.

2010-06-30 Thread Victor Lowther
On Thu, 2010-07-01 at 00:16 +0200, Thomas Bächler wrote:
 Am 30.06.2010 23:47, schrieb Victor Lowther:
  Split out reading /etc/crypttab and procssing the individual lines into
  their own helper functions, and bashify the resulting shorter code.
  
  Processing this file is still ugly, though. :(
 
 I wanted to factor this out and deprecate crypttab for a long time. This
 is a good first step.

Danke.

 However, there are still things in this commit that do not belong there,
 again. While your work here is appreciated, and I am looking forward to
 applying most (all?) of it, you will probably have to re-do many of the
 commit due to these errors.

No problem, I got a little crazier with the ol' git rebase than I should
have.  

 I'll stop reviewing now and continue with 33-48 tomorrow.

I look forward to it.

-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] [PATCH 04/48] Use [[ ]] instead of [ ] for conditional checking when running in bash.

2010-06-30 Thread Victor Lowther
On Thu, 2010-07-01 at 00:24 +0200, bardo wrote:
 2010/7/1 Daenyth Blank daenyth+a...@gmail.com:
  On Wed, Jun 30, 2010 at 17:56, Thomas Bächler tho...@archlinux.org wrote:
  Am 30.06.2010 23:47, schrieb Victor Lowther:
  It is worth 10 - 30% speedup whenever you want to compare something.
 
  Where do you get this from? I always used [ ], and I found it
  sufficient. Why is [[ ]] faster?
 
  -if [ $USECOLOR = YES -o $USECOLOR = yes ]; then
  +if [[ $USECOLOR = YES || $USECOLOR = yes ]]; then
 
  Why do you get rid of the quoting here? Quoting is nice.
 
 
 
  Quoting is not needed in [[ and it makes the code uglier.
 
 
 Ditto. May I also suggest a link[1] to those that do not know all the
 beauties of double square brackets? By the way, the whole BashFAQ in
 there is really interesting, it has lots of advanced tips 'n tricks.
 
 Corrado
 
 
 [1] http://mywiki.wooledge.org/BashFAQ/031

greycat and friends are awesome, it is true.  I learned alot reading
gregs wiki and hanging out on #bash.

-- 
Victor Lowther
LPIC2 UCP RHCE 


Re: [arch-general] [PATCH 35/48] find has a builtin delete action. Use it instead of exec'ing rm.

2010-06-30 Thread Victor Lowther
On Wed, Jun 30, 2010 at 5:32 PM, Thomas Bächler tho...@archlinux.org wrote:
 Am 30.06.2010 23:58, schrieb Daenyth Blank:
 On Wed, Jun 30, 2010 at 17:47, Victor Lowther victor.lowt...@gmail.com 
 wrote:
 ---
  rc.sysinit |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

 diff --git a/rc.sysinit b/rc.sysinit
 index 319ea60..037a9f2 100755
 --- a/rc.sysinit
 +++ b/rc.sysinit
 @@ -277,7 +277,7 @@ stat_busy Removing Leftover Files
  /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 -- {} \; )
 +(cd /var/run  /usr/bin/find . \! -type d -delete  )
  : | /var/run/utmp
  /bin/chmod 0664 /var/run/utmp
  # Keep {x,k,g}dm happy with xorg
 --
 1.7.1



 I don't think this is portable though.


 Portability is not an issue. The beauty about this is that we can simply
 assume we have GNU tools and we do use Linux ... because that is what
 Arch is based on.

Exactly.

 I have no problem having GNU-specific features in there, as we can rely
 on GNU find (or GNU whatever) being present. The only exception is
 initramfs - however, no shell script is used in both the system and
 initramfs

That is one reason I helped write and use dracut (the new initramfs
generation framework that Fedora 12 and 13 use, and that RHEL6 will
use) -- instead of using busybox/klobc/whatever, it trades a slightly
larger initramfs for the convienence of using exactly the same
binaries the installed system uses for everything.  I will happily
trade a few hundred K larger initramfs for not having to maintain
another toolchain and userspace just for the initramfs.


Re: [arch-general] Bashification of initscripts for moderate speedup

2010-06-29 Thread Victor Lowther
On Jun 29, 2010, at 5:55 AM, solsTiCe d'Hiver  
solstice.dhi...@gmail.com wrote:



Le lundi 28 juin 2010 à 17:55 +0200, Lukáš Jirkovský a écrit :

Actually I see the point of doing this. Arch is a modern distribution
with the newest software around so why stuck with shell constructs
which are probably dozens of years old?

Lukas


Yes. I definitely agree. We have to pray that a dev is interested in  
the

patch now ;-)


Thomas seemed moderatly interested.


@Victor:
You last commit that is supposed to fix whitespace mess in fact  
create a

mess with whitespace. Also it changes all the modelines for vim:
for example from
# vim: set ft=sh sw=2 ts=2 et:
to
# vim: set ft=sh sw=4 ts=4 et:


When it comes to whitespace, I do whatever indent-region and  
whitespace-cleanup tell me to.




in fact, I would suggest that you revert your commit
59c7059e78491988c5d8d495c731fb66fe8f7224. It does not fix anything.

check for yourself with
git checkout bashification
git diff master
but
git diff master HEAD~1
is clearly better



Re: [arch-general] Bashification of initscripts for moderate speedup

2010-06-29 Thread Victor Lowther
I have uploaded some shiny bootchart runs from booting with and  
without bashification on my laptop to http://bugs.archlinux.org/20006




Re: [arch-general] Bashification of initscripts for moderate speedup

2010-06-29 Thread Victor Lowther

On Jun 29, 2010, at 9:27 AM, Dan McGee dpmc...@gmail.com wrote:


On Tue, Jun 29, 2010 at 8:20 AM, Victor Lowther
victor.lowt...@gmail.com wrote:
On Jun 29, 2010, at 5:55 AM, solsTiCe d'Hiver solstice.dhi...@gmail.com 


wrote:


Le lundi 28 juin 2010 à 17:55 +0200, Lukáš Jirkovský a écrit :


Actually I see the point of doing this. Arch is a modern  
distribution

with the newest software around so why stuck with shell constructs
which are probably dozens of years old?

Lukas


Yes. I definitely agree. We have to pray that a dev is interested  
in the

patch now ;-)


Thomas seemed moderatly interested.


@Victor:
You last commit that is supposed to fix whitespace mess in fact  
create a

mess with whitespace. Also it changes all the modelines for vim:
for example from
# vim: set ft=sh sw=2 ts=2 et:
to
# vim: set ft=sh sw=4 ts=4 et:


When it comes to whitespace, I do whatever indent-region and
whitespace-cleanup tell me to.


Which is change the modelines? No thanks.

http://wiki.archlinux.org/index.php/DeveloperWiki:Bash_Coding_Style


I know we are getting into holy war territory here, but:

Overall, they are sane, except for using tabs vs. spaces (at least  
with spaces it is never ambiguous how far you wanted a given indent to  
be in a world where tab does not always map to a set number of  
spaces), and 8 character indentation (leads to excessive horizontal  
scrolling in any moderatly complex nested flow control situation. I  
prefer 4 space indentation, it tends to align nicely with most flow  
control statements), and using the source keyword instead of . to  
source files (personal preference from also maintaining a package  
written in posix sh).


We might want to steal some content from http://mywiki.wooledge.org/BashGuide/Practices 
 to update the Arch bash coding page.




-Dan


Re: [arch-general] Bashification of initscripts for moderate speedup

2010-06-29 Thread Victor Lowther
On Jun 28, 2010, at 11:36 AM, Isaac Dupree m...@isaac.cedarswampstudios.org 
 wrote:



On 06/28/10 09:35, Victor Lowther wrote:
On Jun 28, 2010, at 7:42 AM, Caleb Cushing  
xenoterrac...@gmail.com wrote:



On Sun, Jun 27, 2010 at 11:10 PM, Victor Lowther
victor.lowt...@gmail.com wrote:

Questions, comments, flames, etc. welcome.


why go this way instead of the other? (clarification why go deeper
into bash instead of trying to posix-ify the scripts)


...and the main
source of slowdowns in the boot sequence is I/O based -- mounting
filesystems and launching programs.


IIRC, Busybox shell can get notable speed boost by incorporating  
versions of tools like sed into the same busybox executable, such  
that it often doesn't have to fork and load other short-lived  
programs.


You can eliminate a fair number of trivial uses of grep, awk, and sed  
by using all of the parameter expansion modifiers that bash offers,  
and by using the native regex support from bash 3 and above. I made  
these changes wherever it seemed appropriate in my changes.




(I believe it doesn't do bash-array-syntax.)

-Isaac


Re: [arch-general] Bashification of initscripts for moderate speedup

2010-06-28 Thread Victor Lowther
On Jun 28, 2010, at 7:42 AM, Caleb Cushing xenoterrac...@gmail.com  
wrote:



On Sun, Jun 27, 2010 at 11:10 PM, Victor Lowther
victor.lowt...@gmail.com wrote:

Questions, comments, flames, etc. welcome.


why go this way instead of the other? (clarification why go deeper
into bash instead of trying to posix-ify the scripts)


Because arrays and associative arrays are very useful, using native  
bash costructs instead of posix gives you a decent speed boost, and  
the main source of slowdowns in the boot sequence is I/O based --  
mounting filesystems and launching programs. Serious boot speed  
optimization is a matter of optimizing I/O.




--
Caleb Cushing

http://xenoterracide.blogspot.com


Re: [arch-general] Bashification of initscripts for moderate speedup

2010-06-28 Thread Victor Lowther

On Jun 28, 2010, at 8:59 AM, Loui Chang louipc@gmail.com wrote:


On Mon 28 Jun 2010 08:04 -0500, Dan McGee wrote:
On Mon, Jun 28, 2010 at 7:42 AM, Caleb Cushing xenoterrac...@gmail.com 
 wrote:

On Sun, Jun 27, 2010 at 11:10 PM, Victor Lowther
victor.lowt...@gmail.com wrote:

Questions, comments, flames, etc. welcome.


why go this way instead of the other? (clarification why go deeper
into bash instead of trying to posix-ify the scripts)


Because we are never going to eliminate arrays from rc.conf.


Well, it may still be beneficial to some. The scripts could be used  
with

a different style rc.conf in other environments.


Then it will not be Arch.




Re: [arch-general] Bashification of initscripts for moderate speedup

2010-06-28 Thread Victor Lowther

On Jun 28, 2010, at 9:49 AM, Loui Chang louipc@gmail.com wrote:


On Mon 28 Jun 2010 09:13 -0500, Victor Lowther wrote:

On Jun 28, 2010, at 8:59 AM, Loui Chang louipc@gmail.com wrote:


On Mon 28 Jun 2010 08:04 -0500, Dan McGee wrote:

On Mon, Jun 28, 2010 at 7:42 AM, Caleb Cushing
xenoterrac...@gmail.com wrote:

On Sun, Jun 27, 2010 at 11:10 PM, Victor Lowther
victor.lowt...@gmail.com wrote:

Questions, comments, flames, etc. welcome.


why go this way instead of the other? (clarification why go deeper
into bash instead of trying to posix-ify the scripts)


Because we are never going to eliminate arrays from rc.conf.


Well, it may still be beneficial to some. The scripts could be used
with a different style rc.conf in other environments.


Then it will not be Arch.


Depends on what you define as Arch.
I've heard that Arch is what you make of it. Hehe.
I don't know if you could disqualify it from a difference of one file.


For me, part of it is that bash is used pretty ubiquitously as the  
configuration and scripting language of choice. Changing that to posix  
sh in one of the main config files would be a big shift.






[arch-general] Bashification of initscripts for moderate speedup

2010-06-27 Thread Victor Lowther
I have spent some time over the last month or so rewriting the Arch
initscripts in idiomatic bash -- since they rely on bash-specific
features, trying to keep them fairly POSIX is rather a waste of time and
a net performance loss -- using bash-style conditionals is about 30%
faster when nothing needs to be touched on the filesystem and about 200%
easier to read, and you can use bash regexps in place of most trivial
uses of sed, grep, and awk when mangling parameters or variables -- the
fewer short-lived processes we fork the better.

You can browse changes I have made in the git repo @
http://git.fnordovax.org/arch-initscripts/log/?h=bashification and you
can checkout my changes to play around with from
git://fnordovax.org/~victor/arch-initscripts 

There is a gigantic whitespace fixup patch at the end, all it does is
fix all the whitespace errors I introduced while hacking and reformat
everything to a consistent indentation style (emacs shell-script mode,
if you are interested).

I have tested these changes on a VM and on my local laptop.  I inlcuded
a PKGBUILD that will build an initscripts-git package, but be sure to
backup and restore your rc.*local, inittab, and rc.conf files because
they will get nuked the first time you install it.

Questions, comments, flames, etc. welcome. I can also spam the list with
patches if y'all really want.
-- 
Victor Lowther
LPIC2 UCP RHCE