~smoser/cirros/trunk.mkcabundle-in-bash

« back to all changes in this revision

Viewing changes to bin/build-initramfs

  • Committer: Scott Moser
  • Date: 2011-09-09 22:10:39 UTC
  • Revision ID: smoser@ubuntu.com-20110909221039-l4djwt8a270hzcas
add functional initial configs for buildroot

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
 
3
 
source "${0%/*}/common-functions.sh"
4
 
 
5
 
TEMP_D=""
6
 
 
7
 
Usage() {
8
 
    cat <<EOF
9
 
Usage: ${0##*/} initramfs_dir root_dir
10
 
    create an initramfs from initramfs_dir, copying files from root_dir
11
 
 
12
 
    Example:
13
 
     ${0##*/} initramfs/ rootfs/ > my.initramfs.img
14
 
EOF
15
 
}
16
 
cleanup() {
17
 
    [ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
18
 
}
19
 
 
20
 
short_opts="hv"
21
 
long_opts="help,verbose"
22
 
getopt_out=$(getopt --name "${0##*/}" \
23
 
    --options "${short_opts}" --long "${long_opts}" -- "$@") &&
24
 
    eval set -- "${getopt_out}" ||
25
 
    bad_Usage
26
 
 
27
 
while [ $# -ne 0 ]; do
28
 
    cur=${1}; next=${2};
29
 
    case "$cur" in
30
 
        -h|--help) Usage; exit 0;;
31
 
        -v|--verbose) DEBUG=$((${DEBUG}+1));;
32
 
        --) shift; break;;
33
 
    esac
34
 
    shift;
35
 
done
36
 
 
37
 
[ $# -eq 2 ] || bad_Usage "must give initramfs_dir and root_dir"
38
 
initramfs_d=${1}
39
 
root_d=${2}
40
 
 
41
 
[ -d "$initramfs_d" ] || fail "$initramfs_d is not a dir"
42
 
[ -d "$root_d" ] || fail "$root_d is not a dir"
43
 
 
44
 
TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/.${0##*/}.XXXXXX") ||
45
 
    fail "failed to make tempd"
46
 
trap cleanup EXIT
47
 
 
48
 
work_d="${TEMP_D}/workd"
49
 
src_d="$initramfs_d/src"
50
 
needs="$initramfs_d/needs"
51
 
 
52
 
[ -f "$needs" ] || fail "$needs is not a file"
53
 
[ -d "$src_d" ] || fail "$src_d is not a dir"
54
 
 
55
 
mkdir -p "${work_d}/"{bin,sbin,usr/bin,usr/sbin}
56
 
 
57
 
while read need; do
58
 
    need=${need%%#*}; need=${need% };
59
 
    [ -n "$need" ] || continue
60
 
    [ "${need#*..}" = "${need}" ] || fail "paths cannot have ..: $need"
61
 
    if [ -e "$root_d/$need" ]; then
62
 
        mkdir -p "$work_d/${need%/*}" &&
63
 
        cp -a "$root_d/$need" "$work_d/$need" ||
64
 
        fail "failed to copy $need to working dir"
65
 
    else
66
 
        fail "$need not found in $root_d"
67
 
    fi
68
 
done < $needs
69
 
 
70
 
loaders=$(cd "$root_d" &&
71
 
    echo lib/ld-uClibc.so.0 lib/ld-uClibc-*.so \
72
 
        lib/ld64-uClibc.so.0 lib/ld64-uClibc-*.so)
73
 
 
74
 
for f in $loaders; do
75
 
    [ -f "$root_d/$f" ] || continue
76
 
    mkdir -p "${work_d}/${f%/*}" &&
77
 
    cp -a "$root_d/$f" "$work_d/$f" ||
78
 
        fail "failed to copy $f"
79
 
done
80
 
 
81
 
rsync -a "$src_d/" "$work_d" ||
82
 
    fail "failed to sync $src_d to working dir"
83
 
 
84
 
( cd "${work_d}" && find . | cpio --quiet --dereference -o -H newc | gzip -9 )
85
 
 
86
 
exit 0
87
 
 
88
 
# vi: tabstop=4 expandtab