[arch-projects] [mkinitcpio] [PATCH 0/6] Bashify and simplify install/consolefont
I stumbled over this today and as always couldn't resist to fix it regardless the fact it was only slightly broken. ;-) https://github.com/kujub/mkinitcpio Kurt J. Bosch (6): install/consolefont: Correct whitespace install/consolefont: Bashify install script install/consolefont: Get rid of grep and eval install/consolefont: Fix quoting install/consolefont: Refactor for simplification install/consolefont: Use error() instead of echo install/consolefont | 42 +++++++++++++++++++----------------------- 1 files changed, 19 insertions(+), 23 deletions(-)
--- install/consolefont | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/install/consolefont b/install/consolefont index 395387b..8c1fa8c 100644 --- a/install/consolefont +++ b/install/consolefont @@ -26,7 +26,7 @@ build() help () { -cat<<HELPEOF - This hook loads consolefont specified in rc.conf during early userspace. + cat<<HELPEOF +This hook loads consolefont specified in rc.conf during early userspace. HELPEOF } -- 1.7.1
mkinitcpio itself is in BASH, so use it. Also add BASH shebang and move the vim line to the end to ease looking into this with other editors. --- install/consolefont | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-) diff --git a/install/consolefont b/install/consolefont index 8c1fa8c..e12cc4f 100644 --- a/install/consolefont +++ b/install/consolefont @@ -1,19 +1,18 @@ -# vim: set ft=sh: +#!/bin/bash -build() -{ +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 + if [[ $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 + 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} @@ -24,9 +23,10 @@ build() fi } -help () -{ +help () { cat<<HELPEOF This hook loads consolefont specified in rc.conf during early userspace. HELPEOF } + +# vim: set ft=sh: -- 1.7.1
Since mkinitcpio is in BASH, there is no need for using grep and eval for parsing rc.conf. --- install/consolefont | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/install/consolefont b/install/consolefont index e12cc4f..9337d49 100644 --- a/install/consolefont +++ b/install/consolefont @@ -5,7 +5,7 @@ build() { BINARIES="" FILES="" SCRIPT="consolefont" - eval "$(grep -e "^CONSOLEFONT=" /etc/rc.conf)" + CONSOLEFONT=$( . /etc/rc.conf; echo "$CONSOLEFONT" ) if [[ $CONSOLEFONT ]]; then if [[ -e /usr/share/kbd/consolefonts/$CONSOLEFONT.psfu.gz ]]; then CONSOLEFONT_FILE_GZ="/usr/share/kbd/consolefonts/$CONSOLEFONT.psfu.gz" -- 1.7.1
Quoting is not needed in assignments, so use the same style as with [[ ]]. Quoting might be needed for postional parameters because $CONSOLEFONT and $TEMDIR are configuration/command-line parameters. fix --- install/consolefont | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-) diff --git a/install/consolefont b/install/consolefont index 9337d49..f0512bb 100644 --- a/install/consolefont +++ b/install/consolefont @@ -8,15 +8,15 @@ build() { CONSOLEFONT=$( . /etc/rc.conf; echo "$CONSOLEFONT" ) if [[ $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 + 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 + 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 -- 1.7.1
--- install/consolefont | 26 +++++++++++--------------- 1 files changed, 11 insertions(+), 15 deletions(-) diff --git a/install/consolefont b/install/consolefont index f0512bb..b11bf0d 100644 --- a/install/consolefont +++ b/install/consolefont @@ -6,21 +6,17 @@ build() { FILES="" SCRIPT="consolefont" CONSOLEFONT=$( . /etc/rc.conf; echo "$CONSOLEFONT" ) - if [[ $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 - fi + [[ $CONSOLEFONT ]] || return 0 + local e + for e in psfu psf; do + CONSOLEFONT_FILE_GZ=/usr/share/kbd/consolefonts/$CONSOLEFONT.$e.gz + [[ -e $CONSOLEFONT_FILE_GZ ]] || continue + CONSOLEFONT_FILE=$(mktemp ${TMPDIR}/consolefont.$e.XXXXXX) + zcat "${CONSOLEFONT_FILE_GZ}" > "${CONSOLEFONT_FILE}" + add_file "${CONSOLEFONT_FILE}" /consolefont.$e + return + done + echo "consolefont: Font file does not exist or does not end with .psf.gz or .psfu.gz." } help () { -- 1.7.1
Make the error message more prominent by using error() to add the 'ERROR' prefix and also use colored and bold text where possible. --- install/consolefont | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/install/consolefont b/install/consolefont index b11bf0d..7ed1978 100644 --- a/install/consolefont +++ b/install/consolefont @@ -16,7 +16,7 @@ build() { add_file "${CONSOLEFONT_FILE}" /consolefont.$e return done - echo "consolefont: Font file does not exist or does not end with .psf.gz or .psfu.gz." + error "consolefont: Font file does not exist or does not end with .psf.gz or .psfu.gz." } help () { -- 1.7.1
Kurt J. Bosch, 2011-07-23 13:21:
I stumbled over this today and as always couldn't resist to fix it regardless the fact it was only slightly broken. ;-)
https://github.com/kujub/mkinitcpio
Kurt J. Bosch (6): install/consolefont: Correct whitespace install/consolefont: Bashify install script install/consolefont: Get rid of grep and eval install/consolefont: Fix quoting install/consolefont: Refactor for simplification install/consolefont: Use error() instead of echo
install/consolefont | 42 +++++++++++++++++++----------------------- 1 files changed, 19 insertions(+), 23 deletions(-)
Oops! I guess i should better look into the list next time to avoid conflicts. -- Kurt
participants (1)
-
Kurt J. Bosch