2 # Copyright (C) Martin Schlemmer <azarah@nosferatu.za.org>
3 # Released under the terms of the GNU GPL
5 # Generate a newline separated list of entries from the file/directory pointed
6 # out by the environment variable: CONFIG_INITRAMFS_SOURCE
8 # If CONFIG_INITRAMFS_SOURCE is non-existing then generate a small dummy file.
10 # The output is suitable for gen_init_cpio as found in usr/Makefile.
12 # TODO: Add support for symlinks, sockets and pipes when gen_init_cpio
17 # This is a very simple initramfs
20 nod /dev/console 0600 0 0 c 5 1
28 if [ -f "${argv1}" ]; then
30 elif [ -d "${argv1}" ]; then
32 elif [ -b "${argv1}" -o -c "${argv1}" ]; then
44 if [ -e "${argv1}" ]; then
45 my_mtime=$(find "${argv1}" -printf "%T@\n" | sort -r | head -n 1)
48 echo "# Last modified: ${my_mtime}"
54 local name="${location/${srcdir}//}"
58 local ftype=$(filetype "${location}")
59 local str="${mode} ${uid} ${gid}"
61 [ "${ftype}" == "invalid" ] && return 0
62 [ "${location}" == "${srcdir}" ] && return 0
66 str="${ftype} ${name} ${location} ${str}"
70 local maj=$(LC_ALL=C ls -l "${location}" | \
71 gawk '{sub(/,/, "", $5); print $5}')
72 local min=$(LC_ALL=C ls -l "${location}" | \
75 if [ -b "${location}" ]; then
80 str="${ftype} ${name} ${str} ${dev_type} ${maj} ${min}"
83 str="${ftype} ${name} ${str}"
94 elif [ -f "$1" ]; then
97 elif [ -d "$1" ]; then
98 srcdir=$(echo "$1" | sed -e 's://*:/:g')
99 dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n" 2>/dev/null)
101 # If $dirlist is only one line, then the directory is empty
102 if [ "$(echo "${dirlist}" | wc -l)" -gt 1 ]; then
105 echo "${dirlist}" | \
110 # Failsafe in case directory is empty
114 echo " $0: Cannot open '$1' (CONFIG_INITRAMFS_SOURCE)" >&2