Skip to content

Commit

Permalink
go on a quoting spree.
Browse files Browse the repository at this point in the history
better safe than sorry.
  • Loading branch information
falconindy committed May 12, 2011
1 parent aedbf72 commit 58c9f9f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
74 changes: 37 additions & 37 deletions geninit
Expand Up @@ -93,14 +93,14 @@ in_array() { # {{{
[[ -z $1 ]] && return 1 # Not Found [[ -z $1 ]] && return 1 # Not Found


for item; do for item; do
[[ $item == $needle ]] && return 0 # Found [[ "$item" == $needle ]] && return 0 # Found
done done
return 1 # Not Found return 1 # Not Found
} # }}} } # }}}


cleanup() { # {{{ cleanup() { # {{{
(( SHLVL == 2 )) && [[ $2 ]] && error "$2" (( SHLVL == 2 )) && [[ "$2" ]] && error "$2"
if (( savebuildroot )) && [[ -d $buildroot ]]; then if (( savebuildroot )) && [[ -d "$buildroot" ]]; then
msg "buildroot preserved at: $buildroot" msg "buildroot preserved at: $buildroot"
else else
rm -rf "$tmpdir" rm -rf "$tmpdir"
Expand Down Expand Up @@ -143,7 +143,7 @@ builderlist() { # {{{
builderhelp() { # {{{ builderhelp() { # {{{
local builder=$1 local builder=$1


[[ -f $_sharedir/builders/$builder ]] || die "no such builder: $builder" [[ -f "$_sharedir/builders/$builder" ]] || die "no such builder: $builder"
. "$_sharedir/builders/$builder" . "$_sharedir/builders/$builder"
type -t helpmsg >/dev/null || die "no help for builder: $builder" type -t helpmsg >/dev/null || die "no help for builder: $builder"
msg "$builder" msg "$builder"
Expand All @@ -158,15 +158,15 @@ builderhelp() { # {{{
__get_kernver() { # {{{ __get_kernver() { # {{{
local kernel=$1 local kernel=$1


if [[ ${kernel:0:1} != / ]]; then if [[ "${kernel:0:1}" != / ]]; then
echo "$kernel" echo "$kernel"
return 0 return 0
fi fi


[[ -r $kernel ]] || return $ENOENT [[ -r "$kernel" ]] || return $ENOENT


read _ kernver < <(file -b $basedir$kernel | grep -o 'version [^ ]\+') read _ kernver < <(file -b "$basedir$kernel" | grep -o 'version [^ ]\+')
if [[ $kernver ]]; then if [[ "$kernver" ]]; then
echo "$kernver" echo "$kernver"
return 0 return 0
fi fi
Expand All @@ -181,7 +181,7 @@ __add_file() { # {{{
# $3: mode # $3: mode


(( $# == 3 )) || return $EINVAL (( $# == 3 )) || return $EINVAL
[[ -e $buildroot$1 ]] && return $EEXIST [[ -e "$buildroot$1" ]] && return $EEXIST


(( verbose )) && plain "adding file: %s" "$1" (( verbose )) && plain "adding file: %s" "$1"
install -Dm$3 "$2" "$buildroot$1" install -Dm$3 "$2" "$buildroot$1"
Expand All @@ -192,8 +192,8 @@ __add_dir() { # {{{
# $1: pathname on initcpio # $1: pathname on initcpio
# $2: mode # $2: mode


(( $# == 2 )) || [[ $1 == /?* ]] || return $EINVAL (( $# == 2 )) || [[ "$1" == /?* ]] || return $EINVAL
[[ -e $buildroot$1 ]] && return $EEXIST [[ -e "$buildroot$1" ]] && return $EEXIST


(( verbose )) && plain "adding dir: %s" "$1" (( verbose )) && plain "adding dir: %s" "$1"
install -dm$2 "$buildroot$1" install -dm$2 "$buildroot$1"
Expand All @@ -205,7 +205,7 @@ __add_pipe() { # {{{
# $2: mode # $2: mode


(( $# == 2 )) || return $EINVAL (( $# == 2 )) || return $EINVAL
[[ -e $buildroot$1 ]] && return $EEXIST [[ -e "$buildroot$1" ]] && return $EEXIST


(( verbose )) && plain "adding pipe: %s" "$1" (( verbose )) && plain "adding pipe: %s" "$1"
mkfifo -m$2 "$buildroot$1" mkfifo -m$2 "$buildroot$1"
Expand All @@ -217,7 +217,7 @@ __add_slink() { # {{{
# $2: target of $1 # $2: target of $1


(( $# == 2 )) || return $EINVAL (( $# == 2 )) || return $EINVAL
[[ -L $buildroot$1 ]] && return $EEXIST [[ -L "$buildroot$1" ]] && return $EEXIST


(( verbose )) && plain "adding symlink: %s -> %s" "$2" "$1" (( verbose )) && plain "adding symlink: %s -> %s" "$2" "$1"
ln -s "$2" "$buildroot$1" ln -s "$2" "$buildroot$1"
Expand All @@ -229,12 +229,12 @@ __build_image() { # {{{
local builder= module= line= mod= file= errmsg= local builder= module= line= mod= file= errmsg=


# check our kernel version # check our kernel version
[[ -d $basedir/lib/modules/$kernver ]] || die "kernel \`$kernver' not found" [[ -d "$basedir/lib/modules/$kernver" ]] || die "kernel \`$kernver' not found"


# this must be resolved to an absolute path # this must be resolved to an absolute path
if [[ $imagename && ${imagename:0:1} != / ]]; then if [[ "$imagename" && "${imagename:0:1}" != / ]]; then
imagename=$(readlink -f "$imagename") imagename=$(readlink -f "$imagename")
[[ $imagename ]] || die "Failed to resolve path to imagename" [[ "$imagename" ]] || die "Failed to resolve path to imagename"
fi fi


(( dryrun )) && msg "Starting dry run: %s" "$kernver" || msg "Starting build: %s" "$kernver" (( dryrun )) && msg "Starting dry run: %s" "$kernver" || msg "Starting build: %s" "$kernver"
Expand All @@ -254,15 +254,15 @@ __build_image() { # {{{
for file in "${files[@]}"; do for file in "${files[@]}"; do
local src=${file%%::*} local src=${file%%::*}
local dest=${file##*::} local dest=${file##*::}
[[ $dest ]] || dest=$src [[ "$dest" ]] || dest=$src
add_binary "$src" "$dest" || { (( ++errors)); error "File not found: $file"; } add_binary "$src" "$dest" || { (( ++errors)); error "File not found: $file"; }
done done


# parse builder array # parse builder array
for builder in "${builders[@]}"; do for builder in "${builders[@]}"; do
in_array "$builder" "${skipbuilders[@]}" && continue in_array "$builder" "${skipbuilders[@]}" && continue


if [[ ! -f $builderdir/$builder ]]; then if [[ ! -f "$builderdir/$builder" ]]; then
error "cannot find builder '$builder': No such file" error "cannot find builder '$builder': No such file"
(( ++errors )) (( ++errors ))
continue continue
Expand All @@ -281,7 +281,7 @@ __build_image() { # {{{
done done


# only create depmod files if there's modules added # only create depmod files if there's modules added
if [[ -d $buildroot$moduledir ]]; then if [[ -d "$buildroot$moduledir" ]]; then
msg "Generating module dependencies" msg "Generating module dependencies"
depmod -b "$buildroot" "$kernver" || (( ++errors )) depmod -b "$buildroot" "$kernver" || (( ++errors ))
# trim excess depmod files # trim excess depmod files
Expand All @@ -303,12 +303,12 @@ __build_image() { # {{{
return return
fi fi


if [[ $compress != cat ]]; then if [[ "$compress" != cat ]]; then
zopts=('-9') zopts=('-9')
[[ $compress == xz ]] && zopts+=('--check=crc32') [[ "$compress" == xz ]] && zopts+=('--check=crc32')
fi fi


msg "Creating$([[ $compress == cat ]] || printf " $compress") initramfs: $imagename" msg "Creating$([[ "$compress" == cat ]] || printf " $compress") initramfs: $imagename"


pushd "$buildroot" &>/dev/null pushd "$buildroot" &>/dev/null
find . -print0 | bsdcpio -0oH newc | "$compress" "${zopts[@]}" > "$imagename.tmp" find . -print0 | bsdcpio -0oH newc | "$compress" "${zopts[@]}" > "$imagename.tmp"
Expand All @@ -320,7 +320,7 @@ __build_image() { # {{{
(( pipesave[2] )) && errmsg="$compress reported error compressing image" (( pipesave[2] )) && errmsg="$compress reported error compressing image"


# check for fatal errors # check for fatal errors
[[ $errmsg ]] && { rm "$imagename.tmp"; die "$errmsg"; } [[ "$errmsg" ]] && { rm "$imagename.tmp"; die "$errmsg"; }


# less than fatal errors # less than fatal errors
if (( !errors )); then if (( !errors )); then
Expand All @@ -339,7 +339,7 @@ __build_preset() { # {{{
local var= cfg= opts= imagename= local var= cfg= opts= imagename=
local -a presets local -a presets


if [[ ! -f $basedir$presetfile ]]; then if [[ ! -f "$basedir$presetfile" ]]; then
error "preset not found: $1" error "preset not found: $1"
return $ENOENT return $ENOENT
fi fi
Expand All @@ -356,15 +356,15 @@ __build_preset() { # {{{
fi fi


# resolve kernel version # resolve kernel version
if [[ -z $ALL_kver ]]; then if [[ -z "$ALL_kver" ]]; then
error "No kernel version defined for preset \`$1'" error "No kernel version defined for preset \`$1'"
return $EINVAL return $EINVAL
fi fi


# resolve image name # resolve image name
var=${preset}_image var=${preset}_image
imagename=${!var} imagename=${!var}
if [[ -z $imagename ]]; then if [[ -z "$imagename" ]]; then
error "No imagename defined for preset \`$1'" error "No imagename defined for preset \`$1'"
return $EINVAL return $EINVAL
fi fi
Expand All @@ -378,7 +378,7 @@ __build_preset() { # {{{
opts=${!var} opts=${!var}


# this should always resolve to something (i hope) # this should always resolve to something (i hope)
if [[ ! -f $basedir$cfg ]]; then if [[ ! -f "$basedir$cfg" ]]; then
error "preset config file not found: \`$basedir$cfg'" error "preset config file not found: \`$basedir$cfg'"
return $ENOENT return $ENOENT
fi fi
Expand Down Expand Up @@ -463,7 +463,7 @@ if [[ -t 2 ]] && (( color )); then
fi fi
readonly NC BOLD BLUE GREEN RED YELLOW readonly NC BOLD BLUE GREEN RED YELLOW


if [[ $preset ]]; then if [[ "$preset" ]]; then
__build_preset "$preset" __build_preset "$preset"
exit $? exit $?
fi fi
Expand All @@ -473,17 +473,17 @@ fi
# ----------------- # # ----------------- #


# if specified, does the basedir exist? trim any trailing slash # if specified, does the basedir exist? trim any trailing slash
if [[ $basedir ]]; then if [[ "$basedir" ]]; then
basedir=${basedir%/} basedir=${basedir%/}


# if $basedir still exists (some noodle noggin might use -b /), make sure the # if $basedir still exists (some noodle noggin might use -b /), make sure the
# dir can be resolved # dir can be resolved
[[ $basedir && ! -d $basedir ]] && die "basedir \`$basedir' not found" [[ "$basedir" && ! -d $basedir ]] && die "basedir \`$basedir' not found"
fi fi


# make sure our config exists, and source it # make sure our config exists, and source it
config=${config:-$baseconfig} config=${config:-$baseconfig}
[[ ! -f $basedir$config ]] && die "failed to find config file: \`$basedir$config'" || . "$basedir$config" [[ ! -f "$basedir$config" ]] && die "failed to find config file: \`$basedir$config'" || . "$basedir$config"


# declared as an array to force expansion. we have to be careful that the wrong # declared as an array to force expansion. we have to be careful that the wrong
# linker isn't picked for mulitlib systems, so we branch on $carch. # linker isn't picked for mulitlib systems, so we branch on $carch.
Expand All @@ -501,22 +501,22 @@ fi
tmpdir=$(readlink -e "$(mktemp -d "${otmpdir:-/tmp}"/${0##*/}.XXXXXX)") || cleanup 1 tmpdir=$(readlink -e "$(mktemp -d "${otmpdir:-/tmp}"/${0##*/}.XXXXXX)") || cleanup 1


# does the kernel exist inside the basedir? we may need to resolve it... # does the kernel exist inside the basedir? we may need to resolve it...
[[ $kern ]] && kernver=$(__get_kernver "$kern") [[ "$kern" ]] && kernver=$(__get_kernver "$kern")
[[ $kernver ]] || die "Invalid kernel specifier: $kern" [[ "$kernver" ]] || die "Invalid kernel specifier: $kern"


# is our supplied compression method (if supplied) valid? # is our supplied compression method (if supplied) valid?
compress=${ocompress:-$compress} compress=${ocompress:-$compress}
if [[ -z $compress || $compress == none ]]; then if [[ -z $compress || $compress == none ]]; then
compress=cat # NOOP compressor compress=cat # NOOP compressor
else else
[[ $compress == @(gzip|bzip2|lzma|xz) ]] || die "unknown compression method: $compress" [[ "$compress" == @(gzip|bzip2|lzma|xz) ]] || die "unknown compression method: $compress"
type -P "$compress" >/dev/null || die "failed to find \`$compress' binary in PATH" type -P "$compress" >/dev/null || die "failed to find \`$compress' binary in PATH"
fi fi


# if $imagename is provided, its path needs to be valid # if $imagename is provided, its path needs to be valid
if [[ $imagename ]]; then if [[ "$imagename" ]]; then
imagepath=$(readlink -f "$imagename") imagepath=$(readlink -f "$imagename")
[[ $imagepath ]] || die "invalid path to imagename: $imagename" [[ "$imagepath" ]] || die "invalid path to imagename: $imagename"
[[ -w ${imagepath%/*} ]] || die "no permission to write to specified path: \`${imagepath%/*}'" [[ -w ${imagepath%/*} ]] || die "no permission to write to specified path: \`${imagepath%/*}'"
else # no $imagename, so we're doing a dry run else # no $imagename, so we're doing a dry run
dryrun=1 dryrun=1
Expand All @@ -535,7 +535,7 @@ if (( automods )); then
. "$_sharedir/builders/autodetect" || die "unable to source autodetect builder" . "$_sharedir/builders/autodetect" || die "unable to source autodetect builder"
build build
msg "Autodetected modules" msg "Autodetected modules"
[[ -s $autodetect_cache ]] && cat "$autodetect_cache" [[ -s "$autodetect_cache" ]] && cat "$autodetect_cache"
cleanup 0 cleanup 0
fi fi


Expand Down
22 changes: 11 additions & 11 deletions geninit.api
Expand Up @@ -31,16 +31,16 @@ add_file() { # {{{
# determine source and destination # determine source and destination
local src= dest=${2:-$1} mode= local src= dest=${2:-$1} mode=


if [[ ${1:0:1} == @ ]]; then # assert an absolute path if [[ "${1:0:1}" == @ ]]; then # assert an absolute path
src=${1:1} src=${1:1}
else else
src=$basedir$1 src=$basedir$1
fi fi


[[ -f $src ]] || { error "$src: No such file"; return 1; } [[ -f "$src" ]] || { error "$src: No such file"; return 1; }


mode=$(stat -c %a "$src") mode=$(stat -c %a "$src")
if [[ -z $mode ]]; then if [[ -z "$mode" ]]; then
error "failed to stat file: \`$src'" error "failed to stat file: \`$src'"
return 1 return 1
fi fi
Expand Down Expand Up @@ -79,14 +79,14 @@ add_module() { # {{{


module=${1%.ko?(.gz)} module=${1%.ko?(.gz)}


if [[ -z $basedir ]]; then # fast path =) if [[ -z "$basedir" ]]; then # fast path =)
read -rd '' modpath < <(__kmodinfo -n "$module" 2>/dev/null) read -rd '' modpath < <(__kmodinfo -n "$module" 2>/dev/null)
else # slow path =( else # slow path =(
read -rd '' modpath < <(find "$basedir$moduledir/kernel" -type f \ read -rd '' modpath < <(find "$basedir$moduledir/kernel" -type f \
-name "$module.ko" -o -name "$module.ko.gz" -print0) -name "$module.ko" -o -name "$module.ko.gz" -print0)
fi fi


[[ -z $modpath ]] && return 1 [[ -z "$modpath" ]] && return 1


__add_file "${modpath#$basedir}" "$modpath" 644 || return 1 __add_file "${modpath#$basedir}" "$modpath" 644 || return 1


Expand Down Expand Up @@ -122,13 +122,13 @@ add_binary() { # {{{
local -a sodeps local -a sodeps
local regex= binary= dest= mode= sodep= resolved= dirname= local regex= binary= dest= mode= sodep= resolved= dirname=


if [[ ${1:0:1} == @ ]]; then # assert an absolute path if [[ "${1:0:1}" == @ ]]; then # assert an absolute path
binary=${1:1} binary=${1:1}
else else
binary=$basedir$1 binary=$basedir$1
fi fi


[[ -f $binary ]] || { error "$binary not found"; return 1; } [[ -f "$binary" ]] || { error "$binary not found"; return 1; }


dest=${2:-$binary} dest=${2:-$binary}
mode=$(stat -c %a "$binary") mode=$(stat -c %a "$binary")
Expand All @@ -145,9 +145,9 @@ add_binary() { # {{{
# resolve sodeps # resolve sodeps
regex='^[[:space:]]*[^/].+ => (.*) \(.*\)' regex='^[[:space:]]*[^/].+ => (.*) \(.*\)'
while read line; do while read line; do
[[ $line =~ $regex ]] && sodep="${BASH_REMATCH[1]}" || continue [[ "$line" =~ $regex ]] && sodep="${BASH_REMATCH[1]}" || continue


if [[ -f $sodep ]]; then # -f follows symlinks, don't believe it! if [[ -f "$sodep" ]]; then # -f follows symlinks, don't believe it!
if [[ ! -L $sodep ]]; then if [[ ! -L $sodep ]]; then
__add_file "$sodep" "$basedir$sodep" "$(stat -c %a "$sodep")" __add_file "$sodep" "$basedir$sodep" "$(stat -c %a "$sodep")"
else else
Expand Down Expand Up @@ -207,13 +207,13 @@ add_driver_classes() { # {{{
popd &>/dev/null popd &>/dev/null


# only add what autodetect found if we have a module cache # only add what autodetect found if we have a module cache
[[ -s $autodetect_cache && -z $NOAUTO ]] && [[ -s "$autodetect_cache" && -z "$NOAUTO" ]] &&
IFS=$'\n' read -rd '' -a mods < <(grep -xFf <(printf '%s\n' "${mods[@]//-/_}") "$autodetect_cache") IFS=$'\n' read -rd '' -a mods < <(grep -xFf <(printf '%s\n' "${mods[@]//-/_}") "$autodetect_cache")


for mod in "${mods[@]}"; do for mod in "${mods[@]}"; do
# check for filter match # check for filter match
for filter in "${MODFILTER[@]}"; do for filter in "${MODFILTER[@]}"; do
[[ $mod == $filter ]] && continue 2 [[ "$mod" == $filter ]] && continue 2
done done


add_module "$mod" && (( ++ret )) add_module "$mod" && (( ++ret ))
Expand Down

0 comments on commit 58c9f9f

Please sign in to comment.