1
0
Fork 0
mirror of https://github.com/pygos/build.git synced 2024-11-15 07:57:11 +01:00
build/pkg/initrd/build
David Oberhollenzer fc278364e5 Cleanup package command arguments
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
2018-02-17 03:02:16 +01:00

97 lines
2 KiB
Text
Executable file

DEPENDS="bbstatic"
filetype() {
local argv1="$1"
# symlink test must come before file test
if [ -L "${argv1}" ]; then
echo "slink"
elif [ -f "${argv1}" ]; then
echo "file"
elif [ -d "${argv1}" ]; then
echo "dir"
else
echo "invalid"
fi
return 0
}
# for each file print a line in following format
# <filetype> <name> <path to file> <octal mode> <uid> <gid>
# for links, devices etc the format differs. See gen_init_cpio for details
parse() {
local location="$1"
local name="/${location#${srcdir}}"
# change '//' into '/'
name=$(echo "$name" | sed -e 's://*:/:g')
local mode="$2"
local uid="$3"
local gid="$4"
local ftype=$(filetype "${location}")
local str="${mode} 0 0 "
[ "${ftype}" = "invalid" ] && return 0
[ "${location}" = "${srcdir}" ] && return 0
case "${ftype}" in
"file")
str="${ftype} ${name} ${location} ${str}"
;;
"slink")
local target=`readlink "${location}"`
str="${ftype} ${name} ${target} ${str}"
;;
*)
str="${ftype} ${name} ${str}"
;;
esac
echo "${str}"
return 0
}
# process one directory (incl sub-directories)
dir_filelist() {
srcdir=$(echo "$1" | sed -e 's://*:/:g')
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
echo "${dirlist}" | while read x; do
parse ${x}
done
fi
}
build() {
local INPUT="$1"
local DEPLOY="$2"
# populate with default directory structure
for dir in dev proc sys bin lib newroot images; do
mkdir -p "$DEPLOY/$dir"
done
ln -s "/bin" "$DEPLOY/sbin"
# add init script
cp "$SCRIPTDIR/pkg/initrd/initrd.skel" "$DEPLOY/init"
chmod +x "$DEPLOY/init"
# 'install' packages to initrd
cp -r ${PKGDEPLOYDIR}/bbstatic/* "$DEPLOY"
}
deploy() {
local SOURCE="$1"
local DEPLOY="$2"
local LSTFILE="$PKGBUILDDIR/initrd.list"
dir_filelist "$DEPLOY" > "$LSTFILE"
echo "dir /dev 0755 0 0" >> "$LSTFILE"
echo "nod /dev/console 600 0 0 c 5 1" >> "$LSTFILE"
mv "$LSTFILE" "$DEPLOY"
}