net: wireless: bcmdhd: cleanup Kconfig/Make
[linux-2.6.git] / scripts / gen_initramfs_list.sh
index 331c079..b482f16 100644 (file)
@@ -1,11 +1,11 @@
-#!/bin/bash
+#!/bin/sh
 # Copyright (C) Martin Schlemmer <azarah@nosferatu.za.org>
-# Copyright (c) 2006           Sam Ravnborg <sam@ravnborg.org>
+# Copyright (C) 2006 Sam Ravnborg <sam@ravnborg.org>
 #
 # Released under the terms of the GNU GPL
 #
 # Generate a cpio packed initramfs. It uses gen_init_cpio to generate
-# the cpio archive, and gzip to pack it.
+# the cpio archive, and then compresses it.
 # The script may also be used to generate the inputfile used for gen_init_cpio
 # This script assumes that gen_init_cpio is located in usr/ directory
 
@@ -16,16 +16,16 @@ usage() {
 cat << EOF
 Usage:
 $0 [-o <file>] [-u <uid>] [-g <gid>] {-d | <cpio_source>} ...
-       -o <file>      Create gzipped initramfs file named <file> using
-                      gen_init_cpio and gzip
+       -o <file>      Create compressed initramfs file named <file> using
+                      gen_init_cpio and compressor depending on the extension
        -u <uid>       User ID to map to user ID 0 (root).
-                      <uid> is only meaningful if <cpio_source>
-                      is a directory.
+                      <uid> is only meaningful if <cpio_source> is a
+                      directory.  "squash" forces all files to uid 0.
        -g <gid>       Group ID to map to group ID 0 (root).
-                      <gid> is only meaningful if <cpio_source>
-                      is a directory.
+                      <gid> is only meaningful if <cpio_source> is a
+                      directory.  "squash" forces all files to gid 0.
        <cpio_source>  File list or directory for cpio archive.
-                      If <cpio_source> is a .cpio file it will be used
+                      If <cpio_source> is a .cpio file it will be used
                       as direct input to initramfs.
        -d             Output the default cpio list.
 
@@ -36,6 +36,12 @@ to reset the root/group mapping.
 EOF
 }
 
+# awk style field access
+# $1 - field number; rest is argument string
+field() {
+       shift $1 ; echo $1
+}
+
 list_default_initramfs() {
        # echo usr/kinit/kinit
        :
@@ -91,7 +97,7 @@ print_mtime() {
 }
 
 list_parse() {
-       echo "$1 \\"
+       [ ! -L "$1" ] && echo "$1 \\" || :
 }
 
 # for each file print a line in following format
@@ -99,42 +105,37 @@ list_parse() {
 # for links, devices etc the format differs. See gen_init_cpio for details
 parse() {
        local location="$1"
-       local name="${location/${srcdir}//}"
+       local name="/${location#${srcdir}}"
        # change '//' into '/'
-       name="${name//\/\///}"
+       name=$(echo "$name" | sed -e 's://*:/:g')
        local mode="$2"
        local uid="$3"
        local gid="$4"
        local ftype=$(filetype "${location}")
        # remap uid/gid to 0 if necessary
-       [ "$uid" -eq "$root_uid" ] && uid=0
-       [ "$gid" -eq "$root_gid" ] && gid=0
+       [ "$root_uid" = "squash" ] && uid=0 || [ "$uid" -eq "$root_uid" ] && uid=0
+       [ "$root_gid" = "squash" ] && gid=0 || [ "$gid" -eq "$root_gid" ] && gid=0
        local str="${mode} ${uid} ${gid}"
 
-       [ "${ftype}" == "invalid" ] && return 0
-       [ "${location}" == "${srcdir}" ] && return 0
+       [ "${ftype}" = "invalid" ] && return 0
+       [ "${location}" = "${srcdir}" ] && return 0
 
        case "${ftype}" in
                "file")
                        str="${ftype} ${name} ${location} ${str}"
                        ;;
                "nod")
-                       local dev_type=
-                       local maj=$(LC_ALL=C ls -l "${location}" | \
-                                       gawk '{sub(/,/, "", $5); print $5}')
-                       local min=$(LC_ALL=C ls -l "${location}" | \
-                                       gawk '{print $6}')
-
-                       if [ -b "${location}" ]; then
-                               dev_type="b"
-                       else
-                               dev_type="c"
-                       fi
-                       str="${ftype} ${name} ${str} ${dev_type} ${maj} ${min}"
+                       local dev=`LC_ALL=C ls -l "${location}"`
+                       local maj=`field 5 ${dev}`
+                       local min=`field 6 ${dev}`
+                       maj=${maj%,}
+
+                       [ -b "${location}" ] && dev="b" || dev="c"
+
+                       str="${ftype} ${name} ${str} ${dev} ${maj} ${min}"
                        ;;
                "slink")
-                       local target=$(LC_ALL=C ls -l "${location}" | \
-                                       gawk '{print $11}')
+                       local target=`readlink "${location}"`
                        str="${ftype} ${name} ${target} ${str}"
                        ;;
                *)
@@ -158,7 +159,7 @@ unknown_option() {
 }
 
 list_header() {
-       echo "deps_initramfs := \\"
+       :
 }
 
 header() {
@@ -170,7 +171,7 @@ dir_filelist() {
        ${dep_list}header "$1"
 
        srcdir=$(echo "$1" | sed -e 's://*:/:g')
-       dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n" 2>/dev/null)
+       dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n")
 
        # If $dirlist is only one line, then the directory is empty
        if [  "$(echo "${dirlist}" | wc -l)" -gt 1 ]; then
@@ -190,9 +191,10 @@ input_file() {
        source="$1"
        if [ -f "$1" ]; then
                ${dep_list}header "$1"
-               is_cpio="$(echo "$1" | sed 's/^.*\.cpio/cpio/')"
-               if [ $2 -eq 0 -a ${is_cpio} == "cpio" ]; then
+               is_cpio="$(echo "$1" | sed 's/^.*\.cpio\(\..*\)\?/cpio/')"
+               if [ $2 -eq 0 -a ${is_cpio} = "cpio" ]; then
                        cpio_file=$1
+                       echo "$1" | grep -q '^.*\.cpio\..*' && is_cpio_compressed="compressed"
                        [ ! -z ${dep_list} ] && echo "$1"
                        return 0
                fi
@@ -200,8 +202,9 @@ input_file() {
                        print_mtime "$1" >> ${output}
                        cat "$1"         >> ${output}
                else
+                       echo "$1 \\"
                        cat "$1" | while read type dir file perm ; do
-                               if [ "$type" == "file" ]; then
+                               if [ "$type" = "file" ]; then
                                        echo "$file \\";
                                fi
                        done
@@ -222,18 +225,28 @@ cpio_file=
 cpio_list=
 output="/dev/stdout"
 output_file=""
+is_cpio_compressed=
+compr="gzip -n -9 -f"
 
 arg="$1"
 case "$arg" in
        "-l")   # files included in initramfs - used by kbuild
                dep_list="list_"
+               echo "deps_initramfs := $0 \\"
                shift
                ;;
-       "-o")   # generate gzipped cpio image named $1
+       "-o")   # generate compressed cpio image named $1
                shift
                output_file="$1"
                cpio_list="$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)"
                output=${cpio_list}
+               echo "$output_file" | grep -q "\.gz$" && compr="gzip -n -9 -f"
+               echo "$output_file" | grep -q "\.bz2$" && compr="bzip2 -9 -f"
+               echo "$output_file" | grep -q "\.lzma$" && compr="lzma -9 -f"
+               echo "$output_file" | grep -q "\.xz$" && \
+                               compr="xz --check=crc32 --lzma2=dict=1MiB"
+               echo "$output_file" | grep -q "\.lzo$" && compr="lzop -9 -f"
+               echo "$output_file" | grep -q "\.cpio$" && compr="cat"
                shift
                ;;
 esac
@@ -270,17 +283,29 @@ while [ $# -gt 0 ]; do
        esac
 done
 
-# If output_file is set we will generate cpio archive and gzip it
-# we are carefull to delete tmp files
+# If output_file is set we will generate cpio archive and compress it
+# we are careful to delete tmp files
 if [ ! -z ${output_file} ]; then
        if [ -z ${cpio_file} ]; then
+               timestamp=
+               if test -n "$KBUILD_BUILD_TIMESTAMP"; then
+                       timestamp="$(date -d"$KBUILD_BUILD_TIMESTAMP" +%s || :)"
+                       if test -n "$timestamp"; then
+                               timestamp="-t $timestamp"
+                       fi
+               fi
                cpio_tfile="$(mktemp ${TMPDIR:-/tmp}/cpiofile.XXXXXX)"
-               usr/gen_init_cpio ${cpio_list} > ${cpio_tfile}
+               usr/gen_init_cpio $timestamp ${cpio_list} > ${cpio_tfile}
        else
                cpio_tfile=${cpio_file}
        fi
        rm ${cpio_list}
-       cat ${cpio_tfile} | gzip -f -9 - > ${output_file}
+       if [ "${is_cpio_compressed}" = "compressed" ]; then
+               cat ${cpio_tfile} > ${output_file}
+       else
+               (cat ${cpio_tfile} | ${compr}  - > ${output_file}) \
+               || (rm -f ${output_file} ; false)
+       fi
        [ -z ${cpio_file} ] && rm ${cpio_tfile}
 fi
 exit 0