diff options
author | Dave Reisner <d@falconindy.com> | 2011-06-07 02:02:32 +0200 |
---|---|---|
committer | Dave Reisner <d@falconindy.com> | 2011-06-19 23:33:34 +0200 |
commit | 7592c32bda5dc3bc45a98b1ddd91be52963b5be2 (patch) | |
tree | e21fce73e0f6da5be4391fd91d2f766f0d3a1650 | |
parent | f2988f2bea65e345fd58e0e413b9eef4359d196b (diff) | |
download | mkinitcpio-7592c32bda5dc3bc45a98b1ddd91be52963b5be2.tar.gz mkinitcpio-7592c32bda5dc3bc45a98b1ddd91be52963b5be2.tar.xz |
mkinitcpio: bashification, part 1/2
Always use bash's [[ ]], and apply (( )) where arithmetic calculations
are made. We also take a few other bash shortcuts to simplify code where
possible.
We also touch the Makefile here to adjust the sed'ing for directory
names.
Signed-off-by: Dave Reisner <d@falconindy.com>
-rw-r--r-- | Makefile | 10 | ||||
-rw-r--r-- | functions | 6 | ||||
-rwxr-xr-x | mkinitcpio | 15 |
3 files changed, 15 insertions, 16 deletions
@@ -19,11 +19,11 @@ all: doc install: all $(foreach dir,${DIRS},install -dm755 ${DESTDIR}${dir};) - sed -e 's|CONFIG="mkinitcpio.conf"|CONFIG="/etc/mkinitcpio.conf"|g' \ - -e 's|FUNCTIONS="functions"|FUNCTIONS="/lib/initcpio/functions"|g' \ - -e 's|HOOKDIR="hooks"|HOOKDIR="/lib/initcpio/hooks"|g' \ - -e 's|INSTDIR="install"|INSTDIR="/lib/initcpio/install"|g' \ - -e 's|PRESETDIR="mkinitcpio.d"|PRESETDIR="/etc/mkinitcpio.d"|g' \ + sed -e 's|^CONFIG=.*|CONFIG=/etc/mkinitcpio.conf|' \ + -e 's|^FUNCTIONS=.*|FUNCTIONS=/lib/initcpio/functions|' \ + -e 's|^HOOKDIR=.*|HOOKDIR=/lib/initcpio/hooks|' \ + -e 's|^INSTDIR=.*|INSTDIR=/lib/initcpio/install|' \ + -e 's|^PRESETDIR=.*|PRESETDIR=/etc/mkinitcpio.d|' \ < mkinitcpio > ${DESTDIR}/sbin/mkinitcpio sed "s|%VERSION%|${VERSION}|g" < lsinitcpio > ${DESTDIR}/bin/lsinitcpio @@ -188,8 +188,8 @@ add_module() { local module path fw dep deps module=${1%.ko*} - #skip expensive stuff if this module has already been added - in_array $module ${ADDED_MODULES[@]} && return + # skip expensive stuff if this module has already been added + in_array "${module//-/_}" "${ADDED_MODULES[@]}" && return path=$(kmodinfo -0F filename "$module") if [[ $path ]]; then @@ -206,7 +206,7 @@ add_module() { add_module "$dep" done - ADDED_MODULES+=("$module") + ADDED_MODULES+=("${module//-/_}") add_file "$path" || return else error "module '$module' not found" @@ -118,9 +118,8 @@ while getopts ':c:k:sb:g:p:m:nvH:LMhS:' arg; do cleanup exit 0 ;; L) msg "Available hooks" - for h in ${INSTDIR}/*; do - echo " ${h##*/}" - done + cd "$INSTDIR" >/dev/null + printf ' %s\n' * | column -c$(tput cols) cleanup exit 0 ;; M) SHOW_AUTOMODS=1 ;; @@ -128,7 +127,7 @@ while getopts ':c:k:sb:g:p:m:nvH:LMhS:' arg; do :) echo "${OPTARG} requires a value..."; usage ;; esac done -shift $((${OPTIND} - 1)) +shift $((OPTIND - 1)) if [[ -t 2 ]] && (( COLOR )); then # prefer terminal safe colored and bold text when tput is supported @@ -245,7 +244,7 @@ if (( SHOW_AUTOMODS )); then exit 0 fi -if [ -z "${GENIMG}" ]; then +if [[ -z $GENIMG ]]; then msg "Starting dry run: %s" "$KERNELVERSION" else msg "Starting build: %s" "$KERNELVERSION" @@ -260,7 +259,7 @@ for hook in ${HOOKS}; do # Deprecation check # A hook is considered deprecated if it is a symlink # within $INSTDIR. - if [ -h "${INSTDIR}/${hook}" ]; then + if [[ -h "${INSTDIR}/${hook}" ]]; then newhook="$(readlink -ne "${INSTDIR}/${hook}")" if [ -n "${newhook}" -a "${INSTDIR}/$(get_basename ${newhook})" -ef "${newhook}" ]; then newhook="$(get_basename ${newhook})" @@ -292,9 +291,9 @@ fi declare -i status=0 declare -a pipesave -if [ -n "${GENIMG}" ]; then +if [[ "${GENIMG}" ]]; then msg "Creating $COMPRESSION initcpio image: %s" "$GENIMG" - [ ${COMPRESSION} = "xz" ] && COMPRESSION_OPTIONS="${COMPRESSION_OPTIONS} --check=crc32" + [[ "$COMPRESSION" = xz ]] && COMPRESSION_OPTIONS+=" --check=crc32" pushd "$TMPDIR/root" >/dev/null find . -print0 | bsdcpio -0oH newc | $COMPRESSION $COMPRESSION_OPTIONS > "$IMGPATH" |