]> rtime.felk.cvut.cz Git - novaboot.git/blobdiff - contrib/gen_cpio
server: Document how to use shell function for console_cmd
[novaboot.git] / contrib / gen_cpio
index ea7b5270f771fb1151bc22860377f51f2dcb4c71..8b9f1aac5abcfb319bb125e256f0e43a776452c6 100755 (executable)
@@ -21,6 +21,7 @@ usage() {
 cat >&2 << EOF
 Usage:
 $0 [--mkimage="<mkimage params>"] [-u <uid>] [-g <gid>] {<cpio_source>}...
+       --gzip         Compress the resulting image with gzip
        --mkimage=...  Pack the resulting image with U-Boot's "mkimage ..."
        -u <uid>       User ID to map to user ID 0 (root).
                       <uid> is only meaningful if <cpio_source> is a
@@ -46,9 +47,11 @@ the root/group mapping.
 EOF
 }
 
-
 while [ $# -gt 0 ]; do
     case "$1" in
+       --gzip)
+           gzip=1
+           ;;
        --mkimage=*)
            mkimage=${1#--mkimage=}
            ;;
@@ -61,7 +64,7 @@ while [ $# -gt 0 ]; do
     shift
 done
 
-if [ -n "$mkimage" ]; then
+if [ -n "$mkimage" -o -n "$gzip" ]; then
     tmp=$(mktemp)
     exec 3<&1 1>$tmp
 fi
@@ -177,7 +180,7 @@ gen_filelist() {
        echo "dir $dir 0755 0 0"
        dir=$(dirname $dir)
     done
-    echo "$(filetype $src) $dst $src $(find $src -printf '%m') 0 0"
+    echo "file $dst $src $(find $src -printf '%m') 0 0"
 }
 
 while [ $# -gt 0 ]; do
@@ -195,13 +198,13 @@ while [ $# -gt 0 ]; do
        *"->"*)
            src=${arg%%->*}
            dst=${arg#*->}
-           cpio_list="$cpio_list$(gen_filelist $src $dst)"
+           cpio_list=$(echo "$cpio_list"; gen_filelist $src $dst)
            ;;
        *)
            if [ -d "$arg" ]; then
                cpio_list="$cpio_list$(gen_dirlist $arg)"
            elif [ -f "$arg" ]; then
-               case "$(file $arg)" in
+               case "$(file -L $arg)" in
                    *"cpio archive"*)
                        gen_cpio_from_list
                        cat $arg
@@ -221,6 +224,17 @@ done
 
 gen_cpio_from_list
 
+if [ -n "$gzip" ]; then
+    if [ -n "$mkimage" ]; then
+       exec >${tmp}.gz
+    else
+       exec 1<&3
+    fi
+    gzip -n -c ${tmp}
+    rm $tmp
+    tmp=${tmp}.gz
+fi
+
 if [ -n "$mkimage" ]; then
     exec 1<&3
     tmp2=$(mktemp)