diff options
author | Dave Reisner <dreisner@archlinux.org> | 2011-07-02 03:19:11 +0200 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2011-07-02 03:19:11 +0200 |
commit | 3d42f00ecb01206e27640a40616ca51c71153624 (patch) | |
tree | 56cae0f746aaf35ac63890962cf6ae3137d42fa3 | |
parent | c46d8a260d276083092b4a46b049b6aa48a1fdbb (diff) | |
download | mkinitcpio-3d42f00ecb01206e27640a40616ca51c71153624.tar.gz mkinitcpio-3d42f00ecb01206e27640a40616ca51c71153624.tar.xz |
functions: reorg, no code changes
Mostly, this groups "private" functions together, separate from public
functions.
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
-rw-r--r-- | functions | 166 |
1 files changed, 83 insertions, 83 deletions
@@ -55,6 +55,43 @@ in_array() { return 1 # Not Found } +_add_file() { + # add a file to $BUILDROOT + # $1: pathname on initcpio + # $2: source on disk + # $3: mode + + (( $# == 3 )) || return $EINVAL + [[ -e "$BUILDROOT$1" ]] && return $EEXIST + + (( QUIET )) || plain "adding file: %s" "$1" + command install -Dm$3 "$2" "$BUILDROOT$1" +} + +_add_dir() { + # add a directory (with parents) to $BUILDROOT + # $1: pathname on initcpio + # $2: mode + + (( $# == 2 )) || [[ "$1" == /?* ]] || return 1 # bad args + [[ -e "$BUILDROOT$1" ]] && return 0 # file exists + + (( QUIET )) || plain "adding dir: %s" "$1" + command install -dm$2 "$BUILDROOT$1" +} + +_add_symlink() { + # add a symlink to $buildroot + # $1: name on initcpio + # $2: target of $1 + + (( $# == 2 )) || return $EINVAL + [[ -L "$BUILDROOT$1" ]] && return $EEXIST + + (( QUIET )) || plain "adding symlink: %s -> %s" "$2" "$1" + ln -s "$2" "$BUILDROOT$1" +} + auto_modules() { # Perform auto detection of modules via sysfs. @@ -95,6 +132,52 @@ checked_modules() { fi } +add_module() { + # Add a kernel module to the initcpio image. Dependencies will be + # discovered and added. + # $1: module name + + local module path dep deps field value + module=${1%.ko*} + + # skip expensive stuff if this module has already been added + in_array "${module//-/_}" "${ADDED_MODULES[@]}" && return + + while IFS=':= ' read -r -d '' field value; do + case "$field" in + filename) + path=$value + ;; + depends) + IFS=',' read -r -a deps <<< "$value" + for dep in "${deps[@]}"; do + add_module "$dep" + done + ;; + firmware) + if [[ -e "$BASEDIR/lib/firmware/$value" ]]; then + _add_file "/lib/firmware/$value" "$BASEDIR/lib/firmware/$value" 644 + fi + ;; + esac + done < <(modinfo -b "$BASEDIR" -k "$KERNELVERSION" -0 "$module" 2>/dev/null) + + if [[ -z $path ]]; then + error "module '$module' not found" + return 1 + fi + + _add_file "${path#$BASEDIR}" "$path" 644 + ADDED_MODULES+=("${module//-/_}") + + # explicit module depends + case "$module" in + fat) add_module "nls_cp437" ;; + ocfs2) add_module "configfs" ;; + libcrc32c) add_module "crc32c"; add_module "crc32c_intel" ;; + esac +} + add_full_dir() { # Add a directory and all its contents, recursively, to the initcpio image. # No parsing is performed and the contents of the directory is added as is. @@ -157,89 +240,6 @@ add_file() { _add_file "${dest#$BASEDIR}" "$src" "$mode" } -add_module() { - # Add a kernel module to the initcpio image. Dependencies will be - # discovered and added. - # $1: module name - - local module path dep deps field value - module=${1%.ko*} - - # skip expensive stuff if this module has already been added - in_array "${module//-/_}" "${ADDED_MODULES[@]}" && return - - while IFS=':= ' read -r -d '' field value; do - case "$field" in - filename) - path=$value - ;; - depends) - IFS=',' read -r -a deps <<< "$value" - for dep in "${deps[@]}"; do - add_module "$dep" - done - ;; - firmware) - if [[ -e "$BASEDIR/lib/firmware/$value" ]]; then - _add_file "/lib/firmware/$value" "$BASEDIR/lib/firmware/$value" 644 - fi - ;; - esac - done < <(modinfo -b "$BASEDIR" -k "$KERNELVERSION" -0 "$module" 2>/dev/null) - - if [[ -z $path ]]; then - error "module '$module' not found" - return 1 - fi - - _add_file "${path#$BASEDIR}" "$path" 644 - ADDED_MODULES+=("${module//-/_}") - - # explicit module depends - case "$module" in - fat) add_module "nls_cp437" ;; - ocfs2) add_module "configfs" ;; - libcrc32c) add_module "crc32c"; add_module "crc32c_intel" ;; - esac -} - -_add_file() { - # add a file to $BUILDROOT - # $1: pathname on initcpio - # $2: source on disk - # $3: mode - - (( $# == 3 )) || return $EINVAL - [[ -e "$BUILDROOT$1" ]] && return $EEXIST - - (( QUIET )) || plain "adding file: %s" "$1" - command install -Dm$3 "$2" "$BUILDROOT$1" -} - -_add_dir() { - # add a directory (with parents) to $BUILDROOT - # $1: pathname on initcpio - # $2: mode - - (( $# == 2 )) || [[ "$1" == /?* ]] || return 1 # bad args - [[ -e "$BUILDROOT$1" ]] && return 0 # file exists - - (( QUIET )) || plain "adding dir: %s" "$1" - command install -dm$2 "$BUILDROOT$1" -} - -_add_symlink() { - # add a symlink to $buildroot - # $1: name on initcpio - # $2: target of $1 - - (( $# == 2 )) || return $EINVAL - [[ -L "$BUILDROOT$1" ]] && return $EEXIST - - (( QUIET )) || plain "adding symlink: %s -> %s" "$2" "$1" - ln -s "$2" "$BUILDROOT$1" -} - add_binary() { # add a binary file to the initcpio image. library dependencies will # be discovered and added. |