[arch-projects] [PATCH 00/13] minor features and bugfixes
This is a bunch of nitpicks, but there are a few new features thrown in. Annotations along the way... Dave Reisner (13): install/consolefont: cleanup and refactor keymap/consolefont: source rc.conf properly from $BASEDIR keymap: simplify unicode detection cleanup and bashify install hooks functions: allow ignoring errors on module addition ensure local scoping of variables base: remove superfluous leading / functions: refactor get_{base,dir}name init: support breaks before and after mounting root mkinitcpio: simplify setting of SKIPHOOKS mkinitcpio: remove extra newline in errmsg init: allow /run to be mounted with exec perms add -A option for adding hooks during build functions | 47 +++++++++---- hooks/keymap | 11 +-- init | 11 ++- install/base | 4 +- install/btrfs | 15 ++-- install/consolefont | 56 ++++++++------- install/dsdt | 21 ++---- install/filesystems | 2 +- install/fw | 29 +++----- install/ide | 30 +++----- install/keymap | 24 ++++--- install/memdisk | 19 +++--- install/net | 195 +++++++++++++++++++++++++-------------------------- install/pata | 4 +- install/pcmcia | 29 ++++---- install/resume | 19 ++--- install/sata | 4 +- install/scsi | 4 +- install/sleep | 27 +++---- install/udev | 33 ++++----- install/usb | 32 ++++----- install/usbinput | 30 +++----- mkinitcpio | 21 +++--- mkinitcpio.5.txt | 5 ++ 24 files changed, 327 insertions(+), 345 deletions(-) -- 1.7.6
* Provide support for uncompressed font files as well as compressed * Avoiding using an unnecessary temp file * Support $BASEDIR * Warn when no font is found * Only add the runtime hook if a font is added Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- install/consolefont | 52 ++++++++++++++++++++++++++------------------------ 1 files changed, 27 insertions(+), 25 deletions(-) diff --git a/install/consolefont b/install/consolefont index 395387b..a0a5088 100644 --- a/install/consolefont +++ b/install/consolefont @@ -1,32 +1,34 @@ -# vim: set ft=sh: +#!/bin/bash + +build() { + local file ext -build() -{ - MODULES="" - BINARIES="" - FILES="" - SCRIPT="consolefont" eval "$(grep -e "^CONSOLEFONT=" /etc/rc.conf)" - if [ -n "$CONSOLEFONT" ]; then - if [ -e /usr/share/kbd/consolefonts/$CONSOLEFONT.psfu.gz ]; then - CONSOLEFONT_FILE_GZ="/usr/share/kbd/consolefonts/$CONSOLEFONT.psfu.gz" - CONSOLEFONT_FILE="$(mktemp ${TMPDIR}/consolefont.psfu.XXXXXX)" - zcat ${CONSOLEFONT_FILE_GZ} > ${CONSOLEFONT_FILE} - add_file ${CONSOLEFONT_FILE} /consolefont.psfu - elif [ -e /usr/share/kbd/consolefonts/$CONSOLEFONT.psf.gz ]; then - CONSOLEFONT_FILE_GZ="/usr/share/kbd/consolefonts/$CONSOLEFONT.psf.gz" - CONSOLEFONT_FILE="$(mktemp ${TMPDIR}/consolefont.psf.XXXXXX)" - zcat ${CONSOLEFONT_FILE_GZ} > ${CONSOLEFONT_FILE} - add_file ${CONSOLEFONT_FILE} /consolefont.psf - else - echo "consolefont: Font file does not exist or does not end with .psf.gz or .psfu.gz." - fi + if [[ -n "$CONSOLEFONT" ]]; then + for file in "$BASEDIR/usr/share/kbd/consolefonts/$CONSOLEFONT".psf?(u)?(.gz); do + if [[ -e $file ]]; then + [[ $file =~ psfu? ]] && ext=${BASH_REMATCH[0]} + if [[ $file = *.gz ]]; then + gzip -cd "$file" > "$BUILDROOT/consolefont.$ext" + else + add_file "${file#$BASEDIR}" "/consolefont.$ext" + fi + SCRIPT=consolefont + return 0 + fi + done + error "consolefont: requested font not found: \`%s'" "$CONSOLEFONT" + return 1 + else + warning "consolefont: no font found in %s/etc/rc.conf" "${BASEDIR%/}" + return 1 fi } -help () -{ -cat<<HELPEOF - This hook loads consolefont specified in rc.conf during early userspace. +help() { + cat <<HELPEOF +This hook loads consolefont specified in rc.conf during early userspace. HELPEOF } + +# vim: set ft=sh ts=4 sw=4 et: -- 1.7.6
Dave Reisner, 2011-07-23 02:21:
* Provide support for uncompressed font files as well as compressed * Avoiding using an unnecessary temp file * Support $BASEDIR * Warn when no font is found * Only add the runtime hook if a font is added
Signed-off-by: Dave Reisner<dreisner@archlinux.org> --- install/consolefont | 52 ++++++++++++++++++++++++++------------------------ 1 files changed, 27 insertions(+), 25 deletions(-)
diff --git a/install/consolefont b/install/consolefont index 395387b..a0a5088 100644 --- a/install/consolefont +++ b/install/consolefont @@ -1,32 +1,34 @@ -# vim: set ft=sh: +#!/bin/bash + +build() { + local file ext
-build() -{ - MODULES="" - BINARIES="" - FILES="" - SCRIPT="consolefont" eval "$(grep -e "^CONSOLEFONT=" /etc/rc.conf)" - if [ -n "$CONSOLEFONT" ]; then - if [ -e /usr/share/kbd/consolefonts/$CONSOLEFONT.psfu.gz ]; then - CONSOLEFONT_FILE_GZ="/usr/share/kbd/consolefonts/$CONSOLEFONT.psfu.gz" - CONSOLEFONT_FILE="$(mktemp ${TMPDIR}/consolefont.psfu.XXXXXX)" - zcat ${CONSOLEFONT_FILE_GZ}> ${CONSOLEFONT_FILE} - add_file ${CONSOLEFONT_FILE} /consolefont.psfu - elif [ -e /usr/share/kbd/consolefonts/$CONSOLEFONT.psf.gz ]; then - CONSOLEFONT_FILE_GZ="/usr/share/kbd/consolefonts/$CONSOLEFONT.psf.gz" - CONSOLEFONT_FILE="$(mktemp ${TMPDIR}/consolefont.psf.XXXXXX)" - zcat ${CONSOLEFONT_FILE_GZ}> ${CONSOLEFONT_FILE} - add_file ${CONSOLEFONT_FILE} /consolefont.psf - else - echo "consolefont: Font file does not exist or does not end with .psf.gz or .psfu.gz." - fi + if [[ -n "$CONSOLEFONT" ]]; then + for file in "$BASEDIR/usr/share/kbd/consolefonts/$CONSOLEFONT".psf?(u)?(.gz); do bash: syntax error near unexpected token `(' Fix: for file in "$BASEDIR/usr/share/kbd/consolefonts/$CONSOLEFONT".psf{,u}.gz; do
+ if [[ -e $file ]]; then + [[ $file =~ psfu? ]]&& ext=${BASH_REMATCH[0]} + if [[ $file = *.gz ]]; then + gzip -cd "$file"> "$BUILDROOT/consolefont.$ext" + else + add_file "${file#$BASEDIR}" "/consolefont.$ext" + fi + SCRIPT=consolefont + return 0 + fi + done + error "consolefont: requested font not found: \`%s'" "$CONSOLEFONT" + return 1 + else + warning "consolefont: no font found in %s/etc/rc.conf" "${BASEDIR%/}" + return 1 fi }
-help () -{ -cat<<HELPEOF - This hook loads consolefont specified in rc.conf during early userspace. +help() { + cat<<HELPEOF +This hook loads consolefont specified in rc.conf during early userspace. HELPEOF } + +# vim: set ft=sh ts=4 sw=4 et:
-- Kurt
Kurt J. Bosch, 2011-07-23 14:43:
Dave Reisner, 2011-07-23 02:21:
* Provide support for uncompressed font files as well as compressed * Avoiding using an unnecessary temp file * Support $BASEDIR * Warn when no font is found * Only add the runtime hook if a font is added
Signed-off-by: Dave Reisner<dreisner@archlinux.org> --- install/consolefont | 52 ++++++++++++++++++++++++++------------------------ 1 files changed, 27 insertions(+), 25 deletions(-)
diff --git a/install/consolefont b/install/consolefont index 395387b..a0a5088 100644 --- a/install/consolefont +++ b/install/consolefont @@ -1,32 +1,34 @@ -# vim: set ft=sh: +#!/bin/bash + +build() { + local file ext
-build() -{ - MODULES="" - BINARIES="" - FILES="" - SCRIPT="consolefont" eval "$(grep -e "^CONSOLEFONT=" /etc/rc.conf)" - if [ -n "$CONSOLEFONT" ]; then - if [ -e /usr/share/kbd/consolefonts/$CONSOLEFONT.psfu.gz ]; then - CONSOLEFONT_FILE_GZ="/usr/share/kbd/consolefonts/$CONSOLEFONT.psfu.gz" - CONSOLEFONT_FILE="$(mktemp ${TMPDIR}/consolefont.psfu.XXXXXX)" - zcat ${CONSOLEFONT_FILE_GZ}> ${CONSOLEFONT_FILE} - add_file ${CONSOLEFONT_FILE} /consolefont.psfu - elif [ -e /usr/share/kbd/consolefonts/$CONSOLEFONT.psf.gz ]; then - CONSOLEFONT_FILE_GZ="/usr/share/kbd/consolefonts/$CONSOLEFONT.psf.gz" - CONSOLEFONT_FILE="$(mktemp ${TMPDIR}/consolefont.psf.XXXXXX)" - zcat ${CONSOLEFONT_FILE_GZ}> ${CONSOLEFONT_FILE} - add_file ${CONSOLEFONT_FILE} /consolefont.psf - else - echo "consolefont: Font file does not exist or does not end with .psf.gz or .psfu.gz." - fi + if [[ -n "$CONSOLEFONT" ]]; then + for file in "$BASEDIR/usr/share/kbd/consolefonts/$CONSOLEFONT".psf?(u)?(.gz); do bash: syntax error near unexpected token `(' Fix: for file in "$BASEDIR/usr/share/kbd/consolefonts/$CONSOLEFONT".psf{,u}.gz; do Or maybe even that was intended: for file in "$BASEDIR/usr/share/kbd/consolefonts/$CONSOLEFONT"{,.psf,.psfu}.gz; do
+ if [[ -e $file ]]; then + [[ $file =~ psfu? ]]&& ext=${BASH_REMATCH[0]} + if [[ $file = *.gz ]]; then + gzip -cd "$file"> "$BUILDROOT/consolefont.$ext" + else + add_file "${file#$BASEDIR}" "/consolefont.$ext" + fi + SCRIPT=consolefont + return 0 + fi + done + error "consolefont: requested font not found: \`%s'" "$CONSOLEFONT" + return 1 + else + warning "consolefont: no font found in %s/etc/rc.conf" "${BASEDIR%/}" + return 1 fi }
-help () -{ -cat<<HELPEOF - This hook loads consolefont specified in rc.conf during early userspace. +help() { + cat<<HELPEOF +This hook loads consolefont specified in rc.conf during early userspace. HELPEOF } + +# vim: set ft=sh ts=4 sw=4 et:
-- Kurt
This is partially in response to FS#24685, which should hopefully cut back on configuration duplication on non-sysvinit systems. This does, however, also fix a bug with keymap/consolefont pulling the wrong rc.conf when BASEDIR is not '/' or unset. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- install/consolefont | 42 +++++++++++++++++++++++------------------- install/keymap | 24 ++++++++++++++---------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/install/consolefont b/install/consolefont index a0a5088..49a324d 100644 --- a/install/consolefont +++ b/install/consolefont @@ -3,26 +3,30 @@ build() { local file ext - eval "$(grep -e "^CONSOLEFONT=" /etc/rc.conf)" - if [[ -n "$CONSOLEFONT" ]]; then - for file in "$BASEDIR/usr/share/kbd/consolefonts/$CONSOLEFONT".psf?(u)?(.gz); do - if [[ -e $file ]]; then - [[ $file =~ psfu? ]] && ext=${BASH_REMATCH[0]} - if [[ $file = *.gz ]]; then - gzip -cd "$file" > "$BUILDROOT/consolefont.$ext" - else - add_file "${file#$BASEDIR}" "/consolefont.$ext" + # subshell to avoid namespace pollution + ( + . "$BASEDIR/etc/rc.conf" + if [[ -n "$CONSOLEFONT" ]]; then + for file in "$BASEDIR/usr/share/kbd/consolefonts/$CONSOLEFONT".psf?(u)?(.gz); do + if [[ -e $file ]]; then + [[ $file =~ psfu? ]] && ext=${BASH_REMATCH[0]} + if [[ $file = *.gz ]]; then + gzip -cd "$file" > "$BUILDROOT/consolefont.$ext" + else + add_file "${file#$BASEDIR}" "/consolefont.$ext" + fi + exit 0 fi - SCRIPT=consolefont - return 0 - fi - done - error "consolefont: requested font not found: \`%s'" "$CONSOLEFONT" - return 1 - else - warning "consolefont: no font found in %s/etc/rc.conf" "${BASEDIR%/}" - return 1 - fi + done + error "consolefont: requested font not found: \`%s'" "$CONSOLEFONT" + exit 1 + else + warning "consolefont: no font found in %s/etc/rc.conf" "${BASEDIR%/}" + exit 1 + fi + ) + + (( $? == 0 )) && SCRIPT=consolefont } help() { diff --git a/install/keymap b/install/keymap index 34b744a..2cf4d15 100644 --- a/install/keymap +++ b/install/keymap @@ -1,18 +1,22 @@ #!/bin/bash build() { - SCRIPT=keymap - eval "$(grep -E "^(LOCALE|KEYMAP)=" /etc/rc.conf)" - if [[ $KEYMAP ]]; then - if [[ $LOCALE = *[Uu][Tt][Ff]-8 ]]; then - printf '%s\n' "UTF8=yes" > "$BUILDROOT/keymap.utf8" - /bin/loadkeys -q -u $KEYMAP -b > "$BUILDROOT/keymap.bin" - else - printf '%s\n' "UTF8=no" > "$BUILDROOT/keymap.utf8" - /bin/loadkeys -q $KEYMAP -b > "$BUILDROOT/keymap.bin" + # subshell to avoid namespace pollution + ( + . "$BASEDIR/etc/rc.conf" + if [[ $KEYMAP ]]; then + if [[ $LOCALE = *[Uu][Tt][Ff]-8 ]]; then + printf '%s\n' "UTF8=yes" > "$BUILDROOT/keymap.utf8" + /bin/loadkeys -q -u $KEYMAP -b > "$BUILDROOT/keymap.bin" + else + printf '%s\n' "UTF8=no" > "$BUILDROOT/keymap.utf8" + /bin/loadkeys -q $KEYMAP -b > "$BUILDROOT/keymap.bin" + fi fi - fi + ) + + (( $? == 0 )) && SCRIPT=keymap } help() { -- 1.7.6
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- hooks/keymap | 11 +++-------- install/keymap | 8 +++----- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/hooks/keymap b/hooks/keymap index 3593168..14f20a1 100644 --- a/hooks/keymap +++ b/hooks/keymap @@ -3,14 +3,9 @@ run_hook () { if [ -e /keymap.bin ]; then msg -n ":: Loading keymap..." - . /keymap.utf8 - if [ "${UTF8}" = "yes" ]; then - kbd_mode -u -C /dev/console - printf "\033%%G" >> /dev/console - else - kbd_mode -a -C /dev/console - printf "\033%%@" >> /dev/console - fi + [ -f /keymap.utf8 ] && mode=-u || mode=-a + kbd_mode $mode -C /dev/console + printf "\033%%G" >> /dev/console loadkmap < /keymap.bin msg "done." fi diff --git a/install/keymap b/install/keymap index 2cf4d15..2880f15 100644 --- a/install/keymap +++ b/install/keymap @@ -7,12 +7,10 @@ build() { . "$BASEDIR/etc/rc.conf" if [[ $KEYMAP ]]; then if [[ $LOCALE = *[Uu][Tt][Ff]-8 ]]; then - printf '%s\n' "UTF8=yes" > "$BUILDROOT/keymap.utf8" - /bin/loadkeys -q -u $KEYMAP -b > "$BUILDROOT/keymap.bin" - else - printf '%s\n' "UTF8=no" > "$BUILDROOT/keymap.utf8" - /bin/loadkeys -q $KEYMAP -b > "$BUILDROOT/keymap.bin" + touch "$BUILDROOT/keymap.utf8" + uc=-u fi + /bin/loadkeys -q $uc $KEYMAP -b > "$BUILDROOT/keymap.bin" fi ) -- 1.7.6
This introduces no logical code changes -- this is purely a syntactical cleanup and standardization across the build hooks. All hooks get the same treatment, adhering to the following style: build() { instructions } help() { cat <<HELPEOF This is a help message. HELPEOF } Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- Massive patch, but there's nothing horribly exciting going on. install/btrfs | 15 ++-- install/dsdt | 21 ++---- install/filesystems | 2 +- install/fw | 29 +++----- install/ide | 30 +++----- install/keymap | 2 +- install/memdisk | 19 +++--- install/net | 195 +++++++++++++++++++++++++-------------------------- install/pata | 2 +- install/pcmcia | 28 ++++---- install/resume | 19 ++--- install/sata | 2 +- install/scsi | 2 +- install/sleep | 27 +++---- install/udev | 33 ++++----- install/usb | 30 ++++----- install/usbinput | 30 +++----- 17 files changed, 220 insertions(+), 266 deletions(-) diff --git a/install/btrfs b/install/btrfs index c156bb0..60e6f5c 100644 --- a/install/btrfs +++ b/install/btrfs @@ -1,16 +1,15 @@ -# vim:set ft=sh: +#!/bin/bash -build() -{ +build() { MODULES="$(all_modules btrfs)" BINARIES="/sbin/btrfs" SCRIPT="btrfs" } -help () -{ -cat <<HELPEOF - This hook is needed to support Btrfs volumes spread - over multiple devices. +help() { + cat <<HELPEOF +This hook is needed to support Btrfs volumes spread over multiple devices. HELPEOF } + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/install/dsdt b/install/dsdt index f1345d0..b38c66c 100644 --- a/install/dsdt +++ b/install/dsdt @@ -1,19 +1,14 @@ -# vim: set ft=sh: +#!/bin/bash -build() -{ - MODULES="" - BINARIES="" - FILES="" - SCRIPT="" +build() { add_file "/lib/initcpio/custom.dsdt" "DSDT.aml" } -help () -{ -cat<<HELPEOF - This hook loads a custom acpi dsdt file during boot. - Place your custom dsdt file for inclusion here: - /lib/initcpio/custom.dsdt +help() { + cat <<HELPEOF +This hook loads a custom acpi dsdt file during boot. Place your custom dsdt +file for inclusion here: /lib/initcpio/custom.dsdt HELPEOF } + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/install/filesystems b/install/filesystems index 64227bc..9230b94 100644 --- a/install/filesystems +++ b/install/filesystems @@ -9,7 +9,7 @@ build() { } help() { - cat<<HELPEOF + cat <<HELPEOF This hook adds filesystems modules to the image. If you would like to minimize the modules installed in the image, add the autodetect hook too. HELPEOF diff --git a/install/fw b/install/fw index 7d7f06f..94e70d1 100644 --- a/install/fw +++ b/install/fw @@ -1,24 +1,17 @@ -# vim: set ft=sh: +#!/bin/bash -build() -{ - MODULES=" $(checked_modules "/drivers/firewire/") " +build() { + MODULES=$(checked_modules "/drivers/firewire/") - MODULES=$(echo ${MODULES}) #trim whitespace - if [ -n "${MODULES}" ]; then - MODULES="${MODULES} firewire-sbp2 sd_mod sr_mod" - fi - BINARIES="" - FILES="" - SCRIPT="" + [[ $MODULES ]] && MODULES+=" firewire-sbp2 sd_mod sr_mod" } -help () -{ -cat<<HELPEOF - This hook loads the necessary modules for a firewire root device. - Detection will take place at runtime. To minimize the modules - in the image, add the autodetect hook too. +help() { + cat <<HELPEOF +This hook loads the necessary modules for a firewire root device. Detection +will take place at runtime. To minimize the modules in the image, add the +autodetect hook too. HELPEOF } - + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/install/ide b/install/ide index fa0da51..9443dd3 100644 --- a/install/ide +++ b/install/ide @@ -1,25 +1,17 @@ -# vim: set ft=sh: +#!/bin/bash -build() -{ - MODULES=" $(checked_modules "/ide/" | grep -v "legacy") "; +build() { + MODULES="$(checked_modules "/ide/" | grep -v "legacy")" - MODULES=$(echo ${MODULES}) #trim whitespace - if [ -n "${MODULES}" ]; then - MODULES="${MODULES} ide-gd_mod" - fi - - BINARIES="" - FILES="" - SCRIPT="" + [[ $MODULES ]] && MODULES+=" ide-gd_mod" } -help () -{ -cat<<HELPEOF - This hook loads the necessary modules for an ide root device, - using the old ide subsystem. - Detection will take place at runtime. To minimize the modules - in the image, add the autodetect hook too. +help() { + cat <<HELPEOF +This hook loads the necessary modules for an ide root device, using the old ide +subsystem. Detection will take place at runtime. To minimize the modules in +the image, add the autodetect hook too. HELPEOF } + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/install/keymap b/install/keymap index 2880f15..1c53c4a 100644 --- a/install/keymap +++ b/install/keymap @@ -18,7 +18,7 @@ build() { } help() { - cat<<HELPEOF + cat <<HELPEOF This hook loads keymap(s) specified in rc.conf during early userspace. HELPEOF } diff --git a/install/memdisk b/install/memdisk index 69c996f..ec698fc 100644 --- a/install/memdisk +++ b/install/memdisk @@ -1,20 +1,19 @@ -# vim:set ft=sh: +#!/bin/bash -build() -{ +build() { MODULES="phram mtdblock" BINARIES="/usr/bin/memdiskfind" - FILES="" SCRIPT="memdisk" add_file /lib/initcpio/udev/01-memdisk.rules /lib/udev/rules.d/01-memdisk.rules } -help () -{ -cat <<HELPEOF - This hook detects a virtual disk created by the memdisk - tool (http://syslinux.zytor.com/wiki/index.php/MEMDISK). +help() { + cat <<HELPEOF +This hook detects a virtual disk created by the memdisk tool +(http://syslinux.zytor.com/wiki/index.php/MEMDISK). - It requires memdiskfind from syslinux 4.00 or newer. +It requires memdiskfind from syslinux 4.00 or newer. HELPEOF } + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/install/net b/install/net index 2c816ba..88d0c97 100644 --- a/install/net +++ b/install/net @@ -1,109 +1,106 @@ -# vim: set ft=sh: +#!/bin/bash -build() -{ +build() { MODULES="nfs $(checked_modules "/drivers/net/") " - - BINARIES="" - FILES="" SCRIPT="net" add_binary "/lib/initcpio/ipconfig" "/bin/ipconfig" add_binary "/lib/initcpio/nfsmount" "/bin/nfsmount" } -help () -{ -cat<<HELPEOF - This hook loads the necessary modules for a network device. - Detection will take place at runtime. To minimize the modules - in the image, add the autodetect hook too. - For pcmcia net devices please use pcmcia hook too. - - Kernel Parameters: - An interface spec can be either short form, which is just the name of - an interface (eth0 or whatever), or long form. The long form consists - of up to seven elements, separated by colons: - - ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf> - nfsaddrs= is an alias to ip= and can be used too. - - <client-ip> IP address of the client. If empty, the address will - either be determined by RARP/BOOTP/DHCP. What protocol - is used de- pends on the <autoconf> parameter. If this - parameter is not empty, autoconf will be used. - - <server-ip> IP address of the NFS server. If RARP is used to - determine the client address and this parameter is NOT - empty only replies from the specified server are - accepted. To use different RARP and NFS server, - specify your RARP server here (or leave it blank), and - specify your NFS server in the 'nfsroot' parameter - (see above). If this entry is blank the address of the - server is used which answered the RARP/BOOTP/DHCP - request. - - <gw-ip> IP address of a gateway if the server is on a different - subnet. If this entry is empty no gateway is used and the - server is assumed to be on the local network, unless a - value has been received by BOOTP/DHCP. - - <netmask> Netmask for local network interface. If this is empty, - the netmask is derived from the client IP address assuming - classful addressing, unless overridden in BOOTP/DHCP reply. - - <hostname> Name of the client. If empty, the client IP address is - used in ASCII notation, or the value received by - BOOTP/DHCP. - - <device> Name of network device to use. If this is empty, all - devices are used for RARP/BOOTP/DHCP requests, and the - first one we receive a reply on is configured. If you - have only one device, you can safely leave this blank. - - <autoconf> Method to use for autoconfiguration. If this is either - 'rarp', 'bootp', or 'dhcp' the specified protocol is - used. If the value is 'both', 'all' or empty, all - protocols are used. 'off', 'static' or 'none' means - no autoconfiguration. - Examples: - ip=127.0.0.1:::::lo:none --> Enable the loopback interface. - ip=192.168.1.1:::::eth2:none --> Enable static eth2 interface. - ip=:::::eth0:dhcp --> Enable dhcp protcol for eth0 configuration. - - nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>] - - If the 'nfsroot' parameter is NOT given on the command line, the default - "/tftpboot/%s" will be used. - - <server-ip> Specifies the IP address of the NFS server. If this field - is not given, the default address as determined by the - 'ip' variable (see below) is used. One use of this - parameter is for example to allow using different servers - for RARP and NFS. Usually you can leave this blank. - - <root-dir> Name of the directory on the server to mount as root. If - there is a "%s" token in the string, the token will be - replaced by the ASCII-representation of the client's IP - address. - - <nfs-options> Standard NFS options. All options are separated by commas. - If the options field is not given, the following defaults - will be used: - port = as given by server portmap daemon - rsize = 1024 - wsize = 1024 - timeo = 7 - retrans = 3 - acregmin = 3 - acregmax = 60 - acdirmin = 30 - acdirmax = 60 - flags = hard, nointr, noposix, cto, ac - - root=/dev/nfs - - If you don't use nfsroot= parameter you need to set root=/dev/nfs - to boot from a nfs root by autoconfiguration. +help() { + cat <<HELPEOF +This hook loads the necessary modules for a network device. +Detection will take place at runtime. To minimize the modules +in the image, add the autodetect hook too. +For pcmcia net devices please use pcmcia hook too. + +Kernel Parameters: +An interface spec can be either short form, which is just the name of +an interface (eth0 or whatever), or long form. The long form consists +of up to seven elements, separated by colons: + +ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf> +nfsaddrs= is an alias to ip= and can be used too. + +<client-ip> IP address of the client. If empty, the address will + either be determined by RARP/BOOTP/DHCP. What protocol + is used de- pends on the <autoconf> parameter. If this + parameter is not empty, autoconf will be used. + +<server-ip> IP address of the NFS server. If RARP is used to + determine the client address and this parameter is NOT + empty only replies from the specified server are + accepted. To use different RARP and NFS server, + specify your RARP server here (or leave it blank), and + specify your NFS server in the 'nfsroot' parameter + (see above). If this entry is blank the address of the + server is used which answered the RARP/BOOTP/DHCP + request. + +<gw-ip> IP address of a gateway if the server is on a different + subnet. If this entry is empty no gateway is used and the + server is assumed to be on the local network, unless a + value has been received by BOOTP/DHCP. + +<netmask> Netmask for local network interface. If this is empty, + the netmask is derived from the client IP address assuming + classful addressing, unless overridden in BOOTP/DHCP reply. + +<hostname> Name of the client. If empty, the client IP address is + used in ASCII notation, or the value received by + BOOTP/DHCP. + +<device> Name of network device to use. If this is empty, all + devices are used for RARP/BOOTP/DHCP requests, and the + first one we receive a reply on is configured. If you + have only one device, you can safely leave this blank. + +<autoconf> Method to use for autoconfiguration. If this is either + 'rarp', 'bootp', or 'dhcp' the specified protocol is + used. If the value is 'both', 'all' or empty, all + protocols are used. 'off', 'static' or 'none' means + no autoconfiguration. +Examples: +ip=127.0.0.1:::::lo:none --> Enable the loopback interface. +ip=192.168.1.1:::::eth2:none --> Enable static eth2 interface. +ip=:::::eth0:dhcp --> Enable dhcp protcol for eth0 configuration. + +nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>] + +If the 'nfsroot' parameter is NOT given on the command line, the default +"/tftpboot/%s" will be used. + +<server-ip> Specifies the IP address of the NFS server. If this field + is not given, the default address as determined by the + 'ip' variable (see below) is used. One use of this + parameter is for example to allow using different servers + for RARP and NFS. Usually you can leave this blank. + +<root-dir> Name of the directory on the server to mount as root. If + there is a "%s" token in the string, the token will be + replaced by the ASCII-representation of the client's IP + address. + +<nfs-options> Standard NFS options. All options are separated by commas. + If the options field is not given, the following defaults + will be used: + port = as given by server portmap daemon + rsize = 1024 + wsize = 1024 + timeo = 7 + retrans = 3 + acregmin = 3 + acregmax = 60 + acdirmin = 30 + acdirmax = 60 + flags = hard, nointr, noposix, cto, ac + +root=/dev/nfs + +If you don't use nfsroot= parameter you need to set root=/dev/nfs +to boot from a nfs root by autoconfiguration. HELPEOF } + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/install/pata b/install/pata index 75a75c1..c51356e 100644 --- a/install/pata +++ b/install/pata @@ -9,7 +9,7 @@ build() { } help() { - cat<<HELPEOF + cat <<HELPEOF This hook loads the necessary modules for a pata (ide) root device, using the new libata subsystem. Detection will take place at runtime. To minimize the modules in the image, add the autodetect hook too. diff --git a/install/pcmcia b/install/pcmcia index 7930d83..b390497 100644 --- a/install/pcmcia +++ b/install/pcmcia @@ -1,25 +1,23 @@ -# vim: set ft=sh: +#!/bin/bash -build() -{ +build() { + FILES="/etc/pcmcia/config.opts" MODULES=" $(checked_modules '/drivers/pcmcia/' | grep -ve 'sound' -e 'net') $(checked_modules '/ide/legacy')" - MODULES=$(echo ${MODULES}) #trim whitespace - if [ -n "${MODULES}" ]; then - MODULES="${MODULES} sd_mod" + + if [[ $MODULES ]]; then + MODULES+=" sd_mod" fi - BINARIES="" - FILES="/etc/pcmcia/config.opts" - SCRIPT="" add_binary "/lib/udev/pcmcia-socket-startup" add_binary "/lib/udev/pcmcia-check-broken-cis" add_file "/lib/udev/rules.d/60-pcmcia.rules" } -help () -{ -cat<<HELPEOF - This hook loads the necessary modules for a pcmcia root device. - Detection will take place at runtime. To minimize the modules - in the image, add the autodetect hook too. +help() { + cat <<HELPEOF +This hook loads the necessary modules for a pcmcia root device. Detection will +take place at runtime. To minimize the modules in the image, add the autodetect +hook too. HELPEOF } + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/install/resume b/install/resume index dcf6442..d261aad 100644 --- a/install/resume +++ b/install/resume @@ -1,17 +1,14 @@ -# vim:set ft=sh: +#!/bin/bash -build() -{ - MODULES="" - BINARIES="" - FILES="" +build() { SCRIPT="resume" } -help () -{ -cat<<HELPEOF - This hook initializes support for resuming from Disk. - Supports swsusp and suspend2. +help() { + cat <<HELPEOF +This hook initializes support for resuming from Disk. Supports swsusp and +suspend2. HELPEOF } + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/install/sata b/install/sata index 1b39d5f..39fe805 100644 --- a/install/sata +++ b/install/sata @@ -10,7 +10,7 @@ build() { } help() { - cat<<HELPEOF + cat <<HELPEOF This hook loads the necessary modules for an sata root device. Detection will take place at runtime. To minimize the modules in the image, add the autodetect hook too. diff --git a/install/scsi b/install/scsi index 2641255..fa9e5d9 100644 --- a/install/scsi +++ b/install/scsi @@ -10,7 +10,7 @@ build(){ } help() { - cat<<HELPEOF + cat <<HELPEOF This hook loads the necessary modules for an scsi root device. Detection will take place at runtime. To minimize the modules in the image, add the autodetect hook too. diff --git a/install/sleep b/install/sleep index c7a8902..b81e1ca 100644 --- a/install/sleep +++ b/install/sleep @@ -1,22 +1,17 @@ -# vim:set ft=sh: +#!/bin/bash -build() -{ - MODULES="" - BINARIES="" - FILES="" +build() { SCRIPT="sleep" } -help () -{ -cat <<HELPEOF - This hook causes the init process to interrupt - for a fixed time interval. The time in seconds - can be specified in the sleeptime= command line - parameter. The default is 5 seconds. - If a sleepdevice= parameter is specified, sleep - until the given device node is available, polling - at one second intervals until sleeptime is reached. +help() { + cat <<HELPEOF +This hook causes the init process to interrupt for a fixed time interval. The +time in seconds can be specified in the sleeptime= command line parameter. The +default is 5 seconds. If a sleepdevice= parameter is specified, sleep until the +given device node is available, polling at one second intervals until sleeptime +is reached. HELPEOF } + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/install/udev b/install/udev index 74c9b5e..6d0804b 100644 --- a/install/udev +++ b/install/udev @@ -1,27 +1,26 @@ -# vim:set ft=sh: +#!/bin/bash -build() -{ - MODULES="" - BINARIES="" - FILES=" /etc/udev/udev.conf" +build() { + FILES="/etc/udev/udev.conf" SCRIPT="udev" + add_binary /sbin/udevd add_binary /sbin/udevadm - for rules in 50-firmware.rules 50-udev-default.rules 60-persistent-storage.rules 80-drivers.rules; do - add_file /lib/udev/rules.d/${rules} + + for rules in 50-{firmware,udev-default}.rules 60-persistent-storage.rules 80-drivers.rules; do + add_file "/lib/udev/rules.d/$rules" done - for tool in firmware ata_id path_id scsi_id usb_id; do - add_file /lib/udev/${tool} + for tool in firmware {ata,path,scsi,usb}_id; do + add_file "/lib/udev/$tool" done } -help () -{ -cat <<HELPEOF - This hook will use udev to create your root device node - and detect the needed modules for your root device. It - is also required for firmware loading in initramfs. - It is recommended to use this hook. +help() { + cat <<HELPEOF +This hook will use udev to create your root device node and detect the needed +modules for your root device. It is also required for firmware loading in +initramfs. It is recommended to use this hook. HELPEOF } + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/install/usb b/install/usb index db2d08e..61020ab 100644 --- a/install/usb +++ b/install/usb @@ -1,24 +1,20 @@ -# vim: set ft=sh: +#!/bin/bash -build() -{ - MODULES=" $(checked_modules "/usb/host" | grep -ve "_cs" -e "sl811_hcd" -e "isp116x_hcd")" +build() { + MODULES="$(checked_modules "/usb/host" | grep -ve "_cs" -e "sl811_hcd" -e "isp116x_hcd")" - MODULES=$(echo ${MODULES}) #trim whitespace - if [ -n "${MODULES}" ]; then - MODULES="${MODULES} usb_storage sd_mod sr_mod" - MODULES="${MODULES} $(checked_modules "drivers/usb/storage/ums-*")" + if [[ $MODULES ]]; then + MODULES+=" usb_storage sd_mod sr_mod" + MODULES+=" $(checked_modules "drivers/usb/storage/ums-*")" fi - BINARIES="" - FILES="" - SCRIPT="" } -help () -{ -cat<<HELPEOF - This hook loads the necessary modules for an usb root device. - Detection will take place at runtime. To minimize the modules - in the image, add the autodetect hook too. +help() { + cat <<HELPEOF +This hook loads the necessary modules for an usb root device. Detection will +take place at runtime. To minimize the modules in the image, add the autodetect +hook too. HELPEOF } + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/install/usbinput b/install/usbinput index e4bf27e..aa4e1a6 100644 --- a/install/usbinput +++ b/install/usbinput @@ -1,24 +1,18 @@ -# vim: set ft=sh: +#!/bin/bash -build() -{ - MODULES=" $(checked_modules "/usb/host" | grep -ve "_cs" -e "sl811_hcd" -e "isp116x_hcd") " - MODULES=" $(echo ${MODULES}) $(all_modules "/hid/hid-") " +build() { + MODULES=" $(checked_modules "/usb/host" | grep -ve "_cs" -e "sl811_hcd" -e "isp116x_hcd")" + MODULES+=" $(all_modules "/hid/hid-")" - MODULES=$(echo ${MODULES}) #trim whitespace - if [ -n "${MODULES}" ]; then - MODULES="${MODULES} usbhid" - fi - BINARIES="" - FILES="" - SCRIPT="" + [[ $MODULES ]] && MODULES+=" usbhid" } -help () -{ -cat<<HELPEOF - This hook loads the necessary modules for an usb input device. - Detection will take place at runtime. To minimize the modules - in the image, add the autodetect hook too. +help() { + cat <<HELPEOF +This hook loads the necessary modules for an usb input device. Detection +will take place at runtime. To minimize the modules in the image, add the +autodetect hook too. HELPEOF } + +# vim: set ft=sh ts=4 sw=4 et: -- 1.7.6
We conditionally, but naively, add modules in some of our install hooks, but the kernel may not have these. Note that these modules can fail silently by detecting a '?' suffix on the module name. In conjunction with this, the add_module function now takes a flag, -t or --try, which will ignore module not found errors from modinfo. The config file will also support this syntax. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- This is sort of in response to FS#25096, which we closed as 'not a bug', but I think this is a low impact workaround that will make a lot of custom kernel users happy. functions | 20 ++++++++++++++++---- install/base | 2 +- install/fw | 2 +- install/ide | 2 +- install/pata | 2 +- install/pcmcia | 5 ++--- install/sata | 2 +- install/scsi | 2 +- install/usb | 6 ++++-- install/usbinput | 4 +--- 10 files changed, 29 insertions(+), 18 deletions(-) diff --git a/functions b/functions index 3c0cd89..c7e167e 100644 --- a/functions +++ b/functions @@ -137,6 +137,13 @@ add_module() { # $1: module name local module path dep deps field value + local -i ign_errors=0 + + if [[ $1 = -@(t|-try) ]]; then + ign_errors=1 + shift + fi + module=${1%.ko*} # skip expensive stuff if this module has already been added @@ -162,6 +169,7 @@ add_module() { done < <(modinfo -b "$BASEDIR" -k "$KERNELVERSION" -0 "$module" 2>/dev/null) if [[ -z $path ]]; then + (( ign_errors )) && return 0 error "module not found: \`%s'" "$module" return 1 fi @@ -173,9 +181,9 @@ add_module() { # explicit module depends case "$module" in - fat) add_module "nls_cp437" ;; - ocfs2) add_module "configfs" ;; - libcrc32c) add_module "crc32c"; add_module "crc32c_intel" ;; + fat) add_module --try "nls_cp437" ;; + ocfs2) add_module --try "configfs" ;; + libcrc32c) add_module --try "crc32c"; add_module --try "crc32c_intel" ;; esac } @@ -291,7 +299,11 @@ parse_hook() { local item for item in $MODULES; do - add_module "$item" + if [[ ${item:(-1)} = '?' ]]; then + try=--try + item=${item%\?} + fi + add_module $try "$item" done for item in $BINARIES; do diff --git a/install/base b/install/base index 64ef39a..9ff5a7b 100644 --- a/install/base +++ b/install/base @@ -24,7 +24,7 @@ build() { read -r -a hooks <<< "$HOOKS" { - (( ${#modules[*]} )) && printf 'MODULES="%s"\n' "${modules[*]}" + (( ${#modules[*]} )) && printf 'MODULES="%s"\n' "${modules[*]%\?}" (( ${#hooks[*]} )) && printf 'HOOKS="%s"\n' "${hooks[*]}" } >"$BUILDROOT/config" ) diff --git a/install/fw b/install/fw index 94e70d1..f624de0 100644 --- a/install/fw +++ b/install/fw @@ -3,7 +3,7 @@ build() { MODULES=$(checked_modules "/drivers/firewire/") - [[ $MODULES ]] && MODULES+=" firewire-sbp2 sd_mod sr_mod" + [[ $MODULES ]] && MODULES+=" firewire-sbp2? sd_mod? sr_mod?" } help() { diff --git a/install/ide b/install/ide index 9443dd3..a8d9e97 100644 --- a/install/ide +++ b/install/ide @@ -3,7 +3,7 @@ build() { MODULES="$(checked_modules "/ide/" | grep -v "legacy")" - [[ $MODULES ]] && MODULES+=" ide-gd_mod" + [[ $MODULES ]] && MODULES+=" ide-gd_mod?" } help() { diff --git a/install/pata b/install/pata index c51356e..76f268c 100644 --- a/install/pata +++ b/install/pata @@ -5,7 +5,7 @@ build() { MODULES+=" $(checked_modules "$filter")" done - [[ $MODULES ]] && MODULES+=" sd_mod" + [[ $MODULES ]] && MODULES+=" sd_mod?" } help() { diff --git a/install/pcmcia b/install/pcmcia index b390497..2e9ac9a 100644 --- a/install/pcmcia +++ b/install/pcmcia @@ -4,9 +4,8 @@ build() { FILES="/etc/pcmcia/config.opts" MODULES=" $(checked_modules '/drivers/pcmcia/' | grep -ve 'sound' -e 'net') $(checked_modules '/ide/legacy')" - if [[ $MODULES ]]; then - MODULES+=" sd_mod" - fi + [[ $MODULES ]] MODULES+=" sd_mod?" + add_binary "/lib/udev/pcmcia-socket-startup" add_binary "/lib/udev/pcmcia-check-broken-cis" add_file "/lib/udev/rules.d/60-pcmcia.rules" diff --git a/install/sata b/install/sata index 39fe805..c9b67c3 100644 --- a/install/sata +++ b/install/sata @@ -6,7 +6,7 @@ build() { MODULES+=" $(checked_modules "$filter")" done - [[ $MODULES ]] && MODULES+=" sd_mod" + [[ $MODULES ]] && MODULES+=" sd_mod?" } help() { diff --git a/install/scsi b/install/scsi index fa9e5d9..4c2abc5 100644 --- a/install/scsi +++ b/install/scsi @@ -6,7 +6,7 @@ build(){ $(checked_modules "/block/" | grep -E '(cciss|cpqarray|DAC960)') $(checked_modules "/fusion/")" - [[ $MODULES ]] && MODULES+=" sd_mod" + [[ $MODULES ]] && MODULES+=" sd_mod?" } help() { diff --git a/install/usb b/install/usb index 61020ab..5320b08 100644 --- a/install/usb +++ b/install/usb @@ -1,10 +1,12 @@ #!/bin/bash build() { + local module= + MODULES="$(checked_modules "/usb/host" | grep -ve "_cs" -e "sl811_hcd" -e "isp116x_hcd")" - if [[ $MODULES ]]; then - MODULES+=" usb_storage sd_mod sr_mod" + if [[ $MODULES ]]; then + MODULES+=" usb_storage? sd_mod? sr_mod?" MODULES+=" $(checked_modules "drivers/usb/storage/ums-*")" fi } diff --git a/install/usbinput b/install/usbinput index aa4e1a6..f89d0bd 100644 --- a/install/usbinput +++ b/install/usbinput @@ -2,9 +2,7 @@ build() { MODULES=" $(checked_modules "/usb/host" | grep -ve "_cs" -e "sl811_hcd" -e "isp116x_hcd")" - MODULES+=" $(all_modules "/hid/hid-")" - - [[ $MODULES ]] && MODULES+=" usbhid" + MODULES+=" $(all_modules "/hid/hid-") usbhid?" } help() { -- 1.7.6
Also make sure that simple variables are declared as null strings. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- functions | 12 +++++++++--- mkinitcpio | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/functions b/functions index c7e167e..69a4aad 100644 --- a/functions +++ b/functions @@ -94,6 +94,8 @@ _add_symlink() { auto_modules() { # Perform auto detection of modules via sysfs. + local mods= + IFS=$'\n' read -rd '' -a mods < \ <(find /sys/devices -name modalias -exec sort -u {} + | xargs modprobe -d "$BASEDIR" -aRS "$KERNELVERSION" | @@ -108,6 +110,8 @@ all_modules() { # $@: filter arguments to grep local -i count=0 + local mod= + while read -r -d '' mod; do (( ++count )) mod=${mod##*/} @@ -136,7 +140,7 @@ add_module() { # discovered and added. # $1: module name - local module path dep deps field value + local module= path= dep= deps= field= value= local -i ign_errors=0 if [[ $1 = -@(t|-try) ]]; then @@ -192,6 +196,8 @@ add_full_dir() { # No parsing is performed and the contents of the directory is added as is. # $1: path to directory + local f= + if [[ -n $1 && -d $1 ]]; then for f in "$1"/*; do if [[ -d "$f" ]]; then @@ -256,7 +262,7 @@ add_binary() { # $2: destination on initcpio (optional, defaults to same as source) local -a sodeps - local regex binary dest mode sodep resolved dirname + local line= regex= binary= dest= mode= sodep= resolved= dirname= binary=$BASEDIR$1 @@ -296,7 +302,7 @@ parse_hook() { # prior to the start of hook processing, and after each hook's build # function is run. - local item + local item= for item in $MODULES; do if [[ ${item:(-1)} = '?' ]]; then diff --git a/mkinitcpio b/mkinitcpio index 49dabbd..82faaaf 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -21,7 +21,7 @@ INSTDIR=install PRESETDIR=mkinitcpio.d COMPRESSION=gzip -declare TMPDIR BASEDIR MODULE_FILE GENIMG PRESET COMPRESSION_OPTIONS BUILDROOT +declare TMPDIR= BASEDIR= MODULE_FILE= GENIMG= PRESET= COMPRESSION_OPTIONS= BUILDROOT= declare NC= BOLD= BLUE= GREEN= RED= YELLOW= declare -i QUIET=1 SHOW_AUTOMODS=0 SAVELIST=0 COLOR=1 declare -a SKIPHOOKS ADDED_MODULES MODPATHS @@ -74,7 +74,7 @@ cleanup () } get_kernver() { - local kernel=$1 + local kernver= kernel=$1 if [[ "${kernel:0:1}" != / ]]; then echo $kernel -- 1.7.6
The doubled up leading slashes annoy me in the verbose output. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- install/base | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/install/base b/install/base index 9ff5a7b..e85551c 100644 --- a/install/base +++ b/install/base @@ -1,7 +1,7 @@ #!/bin/bash build() { - for dir in proc sys dev run /usr/{bin,sbin}; do + for dir in proc sys dev run usr/{bin,sbin}; do add_dir "/$dir" done -- 1.7.6
From: Dave Reisner <d@falconindy.com> Make sure these are completely safe for user input. Use the same three step process in both cases: 1) Strip any trailing slash 2) Trim the string according to base/dir request 3) Print the result, defaulting to / if step 2 yielded an empty string Signed-off-by: Dave Reisner <d@falconindy.com> --- functions | 15 ++++++++------- 1 files changed, 8 insertions(+), 7 deletions(-) diff --git a/functions b/functions index 69a4aad..db639fc 100644 --- a/functions +++ b/functions @@ -30,15 +30,16 @@ die() { cleanup 1 } -get_dirname() { - # strip any trailing slash first... - local dir="${1%/}" - # then get the directory portion - echo "${dir%/*}" +get_basename() { + local base=${1%/} + base=${base##*/} + printf '%s' "${base:-/}" } -get_basename() { - echo "${1##*/}" +get_dirname() { + local dir=${1%/} + dir=${dir%/*} + printf '%s' "${dir:-/}" } in_array() { -- 1.7.6
Add in 'premount' and 'postmount' as trigger conditions, but also leave in the old 'y' value as a synonym for premount. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- I'm not sold on the location of the post-mount break. Do we perhaps want to do this absolutely last before we exec, or is it better to provide this before the teardown, leaving the user with something resembling a "proper" environment? init | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/init b/init index 8c8709c..a0e082e 100644 --- a/init +++ b/init @@ -74,8 +74,8 @@ if [ -e "/hooks" ]; then done fi -if [ "${break}" = "y" ]; then - echo ":: Break requested, type 'exit' to resume operation" +if [ "${break}" = "y" ] || [ "${break}" = "premount" ]; then + echo ":: Pre-mount break requested, type 'exit' to resume operation" launch_interactive_shell fi @@ -100,6 +100,11 @@ elif [ ! -x "/new_root${init}" ]; then launch_interactive_shell --exec fi +if [ "${break}" = "postmount" ]; then + echo ":: Post-mount break requested, type 'exit' to resume operation" + launch_interactive_shell +fi + # Stop udevd if is running if [ "${udevd_running}" -eq 1 ]; then udevadm control --exit -- 1.7.6
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- mkinitcpio | 7 +------ 1 files changed, 1 insertions(+), 6 deletions(-) diff --git a/mkinitcpio b/mkinitcpio index 82faaaf..dd67030 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -108,12 +108,7 @@ while getopts ':c:k:sb:g:p:m:nvH:LMhS:t:z:' arg; do p) PRESET="${OPTARG}" ;; n) COLOR=0 ;; v) QUIET=0 ;; - S) OLDIFS=${IFS} - IFS=, - SKIPHOOKS=(${OPTARG}) - IFS=${OLDIFS} - unset OLDIFS - ;; + S) IFS=, read -r -a SKIPHOOKS <<< "$OPTARG" ;; H) if [[ ! -r "${INSTDIR}/${OPTARG}" ]]; then error "No hook ${OPTARG}" exit 1 -- 1.7.6
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- mkinitcpio | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/mkinitcpio b/mkinitcpio index dd67030..c5c174b 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -356,7 +356,7 @@ if [[ "${GENIMG}" ]]; then fi if [[ $errmsg ]]; then - error "Image generation FAILED: %s\n" "$errmsg" + error "Image generation FAILED: %s" "$errmsg" status=1 else msg "Image generation successful" -- 1.7.6
We'll need this to do some shutdown magic of pivoting and umounting root on shutdown. This is already done in initscripts. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- init | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/init b/init index a0e082e..ff4917a 100644 --- a/init +++ b/init @@ -22,7 +22,7 @@ else # /dev/mem is needed if we want to load uvesafb before triggering uevents mknod /dev/mem c 1 1 fi -mount -t tmpfs run /run -o nosuid,noexec,nodev,mode=755,size=10M +mount -t tmpfs run /run -o nosuid,nodev,mode=755,size=10M echo "/sbin/modprobe" > /proc/sys/kernel/modprobe -- 1.7.6
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- I can see this being useful for one-off images made outside the context of a preset, but this might also just be some oddball feature that never gets used. mkinitcpio | 8 +++++--- mkinitcpio.5.txt | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/mkinitcpio b/mkinitcpio index c5c174b..e46306c 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -24,7 +24,7 @@ COMPRESSION=gzip declare TMPDIR= BASEDIR= MODULE_FILE= GENIMG= PRESET= COMPRESSION_OPTIONS= BUILDROOT= declare NC= BOLD= BLUE= GREEN= RED= YELLOW= declare -i QUIET=1 SHOW_AUTOMODS=0 SAVELIST=0 COLOR=1 -declare -a SKIPHOOKS ADDED_MODULES MODPATHS +declare -a ADDHOOKS SKIPHOOKS ADDED_MODULES MODPATHS # Add /{,usr}/sbin to path # works around undetected problems like in #8448 @@ -40,6 +40,7 @@ mkinitcpio %VERSION% usage: ${0##*/} [options] Options: + -A ADDHOOKS Add ADDHOOKS (comma-separated) when building the image. -b BASEDIR Use BASEDIR. default: / -c CONFIG Use CONFIG file. default: /etc/mkinitcpio.conf -g IMAGE Generate a cpio image as IMAGE. default: no @@ -97,8 +98,9 @@ get_kernver() { trap 'cleanup 130' INT trap 'cleanup 143' TERM -while getopts ':c:k:sb:g:p:m:nvH:LMhS:t:z:' arg; do +while getopts ':A:c:k:sb:g:p:m:nvH:LMhS:t:z:' arg; do case "${arg}" in + A) IFS=, read -r -a ADDHOOKS <<< "$OPTARG" ;; c) CONFIG="${OPTARG}" ;; k) optkver=$OPTARG ;; s) SAVELIST=1; ;; @@ -283,7 +285,7 @@ trap '[[ $FUNCNAME = parse_hook ]] && (( ++builderrors ))' ERR #parse 'global' hook, as defined in ${CONFIG} parse_hook -for hook in ${HOOKS}; do +for hook in ${HOOKS} "${ADDHOOKS[@]}"; do in_array "$hook" "${SKIPHOOKS[@]}" && continue unset MODULES BINARIES FILES SCRIPT build () { error "$hook: no build function..."; } diff --git a/mkinitcpio.5.txt b/mkinitcpio.5.txt index f963dac..d233957 100644 --- a/mkinitcpio.5.txt +++ b/mkinitcpio.5.txt @@ -24,6 +24,11 @@ other features. Options ------- +*-A* 'hooks':: + Add 'hooks' when generating the image. Several hooks should be + comma-separated. These will be added, in order, after any other hooks + are processed from the config file. + *-b* 'basedir':: Use 'basedir' as a starting point for gathering information about the currently running system. Default: /. -- 1.7.6
participants (2)
-
Dave Reisner
-
Kurt J. Bosch