[arch-releng] [RFC] [PATCH] [configs/releng] Replace rc.d/archiso with initscripts hooks.

Dave Reisner d at falconindy.com
Wed Aug 17 21:30:53 EDT 2011


On Wed, Aug 17, 2011 at 10:19:32PM -0300, Gerardo Exequiel Pozzi wrote:
> In this way:
> * Prepare locales requested by boot param mostly early possible.
> * Setup special console at end of rc.sysinit
> 
> Remove unneded include from automated_script (already included by rc.conf)
> 
> Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386 at yahoo.com.ar>
> ---
>  configs/releng/root-image/etc/rc.conf              |    2 +-
>  configs/releng/root-image/etc/rc.d/archiso         |   45 --------------------
>  .../etc/rc.d/functions.d/automated_script          |    2 -
>  .../etc/rc.d/functions.d/prepare_locale_gen        |   11 +++++
>  .../etc/rc.d/functions.d/setup_special_console     |   25 +++++++++++
>  5 files changed, 37 insertions(+), 48 deletions(-)
>  delete mode 100755 configs/releng/root-image/etc/rc.d/archiso
>  create mode 100644 configs/releng/root-image/etc/rc.d/functions.d/prepare_locale_gen
>  create mode 100644 configs/releng/root-image/etc/rc.d/functions.d/setup_special_console
> 
> diff --git a/configs/releng/root-image/etc/rc.conf b/configs/releng/root-image/etc/rc.conf
> index 42084f6..a3e3d8a 100644
> --- a/configs/releng/root-image/etc/rc.conf
> +++ b/configs/releng/root-image/etc/rc.conf
> @@ -30,4 +30,4 @@ USELVM="no"
>  
>  HOSTNAME="archiso"
>  
> -DAEMONS=(hwclock syslog-ng archiso)
> +DAEMONS=(hwclock syslog-ng)
> diff --git a/configs/releng/root-image/etc/rc.d/archiso b/configs/releng/root-image/etc/rc.d/archiso
> deleted file mode 100755
> index cc930f6..0000000
> --- a/configs/releng/root-image/etc/rc.d/archiso
> +++ /dev/null
> @@ -1,45 +0,0 @@
> -# vim: set ft=sh:
> -. /etc/rc.conf
> -. /etc/rc.d/functions
> -
> -do_locale_gen ()
> -{
> -    if [[ ${LOCALE} != "en_US.UTF-8" ]]; then
> -        stat_busy "Generating locales..."
> -            sed -i "s/#\(${LOCALE/[@.]*}\)/\1/" /etc/locale.gen
> -            /usr/sbin/locale-gen > /dev/null
> -        stat_done
> -    fi
> -}
> -
> -# If an alternate console was specified on the kernel command line,
> -# start agetty on it too.
> -do_special_console()
> -{
> -    local cmdline_console
> -    if cmdline_console=$(kernel_cmdline console); then
> -        stat_busy "Starting agetty on console: ${cmdline_console}"
> -            local port options baud rts
> -            port=${cmdline_console%%,*}
> -            options=${cmdline_console#${port}}
> -            options=${options#,}
> -            baud=${options%%[neo]*}
> -            [[ ${options} =~ r$ ]] && rts="-h"
> -            if ! grep -q "^${port}" /etc/securetty; then
> -                echo ${port} >> /etc/securetty
> -            fi
> -            if ! grep -q "^z0:" /etc/inittab; then
> -                echo "z0:2345:respawn:/sbin/agetty -8 -s ${rts} ${baud:-9600} ${port} linux" >> /etc/inittab
> -            fi
> -            /sbin/telinit q
> -        stat_done
> -    fi
> -}
> -
> -case "$1" in
> -  start)
> -    do_locale_gen
> -    do_special_console
> -    ;;
> -esac
> -exit 0
> diff --git a/configs/releng/root-image/etc/rc.d/functions.d/automated_script b/configs/releng/root-image/etc/rc.d/functions.d/automated_script
> index edb8ea3..7a35acb 100644
> --- a/configs/releng/root-image/etc/rc.d/functions.d/automated_script
> +++ b/configs/releng/root-image/etc/rc.d/functions.d/automated_script
> @@ -1,5 +1,3 @@
> -. /etc/archiso/functions
> -
>  automated_script ()
>  {
>      script="$(kernel_cmdline script)"
> diff --git a/configs/releng/root-image/etc/rc.d/functions.d/prepare_locale_gen b/configs/releng/root-image/etc/rc.d/functions.d/prepare_locale_gen
> new file mode 100644
> index 0000000..47ed79d
> --- /dev/null
> +++ b/configs/releng/root-image/etc/rc.d/functions.d/prepare_locale_gen
> @@ -0,0 +1,11 @@
> +prepare_locale_gen ()
> +{
> +    if [[ ${LOCALE} != "en_US.UTF-8" ]]; then
> +        stat_busy "Generating locales..."
> +            sed -i "s/#\(${LOCALE/[@.]*}\)/\1/" /etc/locale.gen
> +            /usr/sbin/locale-gen > /dev/null
> +        stat_done
> +    fi
> +}
> +
> +add_hook sysinit_postmount prepare_locale_gen
> diff --git a/configs/releng/root-image/etc/rc.d/functions.d/setup_special_console b/configs/releng/root-image/etc/rc.d/functions.d/setup_special_console
> new file mode 100644
> index 0000000..93553a6
> --- /dev/null
> +++ b/configs/releng/root-image/etc/rc.d/functions.d/setup_special_console
> @@ -0,0 +1,25 @@
> +# If an alternate console was specified on the kernel command line,
> +# start agetty on it too.
> +setup_special_console()
> +{
> +    local cmdline_console
> +    if cmdline_console=$(kernel_cmdline console); then

Just to point out, console can be specified multiple times. Not sure if
you want to honor all of them, or just the first. Some refactoring would
be involved to catch them all, but it doesn't seem like it'd be too
raunchy.

> +        stat_busy "Starting agetty on console: ${cmdline_console}"
> +            local port options baud rts
> +            port=${cmdline_console%%,*}
> +            options=${cmdline_console#${port}}
> +            options=${options#,}
> +            baud=${options%%[neo]*}

Hrmmm, I'd bet you could split this all with a single read:

  IFS=',' read -r -d '' port baud options <<< "$cmdline_console"

> +            [[ ${options} =~ r$ ]] && rts="-h"

No need for a regex here: [[ $options = *r ]]

> +            if ! grep -q "^${port}" /etc/securetty; then
> +                echo ${port} >> /etc/securetty
> +            fi
> +            if ! grep -q "^z0:" /etc/inittab; then
> +                echo "z0:2345:respawn:/sbin/agetty -8 -s ${rts} ${baud:-9600} ${port} linux" >> /etc/inittab
> +            fi
> +            /sbin/telinit q
> +        stat_done
> +    fi
> +}
> +
> +add_hook sysinit_end setup_special_console
> -- 
> 1.7.6
> 


More information about the arch-releng mailing list