3
source "${0%/*}/common-functions.sh"
9
Usage: ${0##*/} initramfs_dir root_dir
10
create an initramfs from initramfs_dir, copying files from root_dir
13
${0##*/} initramfs/ rootfs/ > my.initramfs.img
17
[ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
21
long_opts="help,verbose"
22
getopt_out=$(getopt --name "${0##*/}" \
23
--options "${short_opts}" --long "${long_opts}" -- "$@") &&
24
eval set -- "${getopt_out}" ||
27
while [ $# -ne 0 ]; do
30
-h|--help) Usage; exit 0;;
31
-v|--verbose) DEBUG=$((${DEBUG}+1));;
37
[ $# -eq 2 ] || bad_Usage "must give initramfs_dir and root_dir"
41
[ -d "$initramfs_d" ] || fail "$initramfs_d is not a dir"
42
[ -d "$root_d" ] || fail "$root_d is not a dir"
44
TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/.${0##*/}.XXXXXX") ||
45
fail "failed to make tempd"
48
work_d="${TEMP_D}/workd"
49
src_d="$initramfs_d/src"
50
needs="$initramfs_d/needs"
52
[ -f "$needs" ] || fail "$needs is not a file"
53
[ -d "$src_d" ] || fail "$src_d is not a dir"
55
mkdir -p "${work_d}/"{bin,sbin,usr/bin,usr/sbin}
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"
66
fail "$need not found in $root_d"
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)
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"
81
rsync -a "$src_d/" "$work_d" ||
82
fail "failed to sync $src_d to working dir"
84
( cd "${work_d}" && find . | cpio --quiet --dereference -o -H newc | gzip -9 )
88
# vi: tabstop=4 expandtab