lix-os-utilities/mkbootstrap.sh

69 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
# populates a directory with host directories.
# modify and use as needed.
[ "$1" ] || echo "usage: mkbootstrap <target path>"
if [ ! -d "$1" ]; then
echo "$1 is not a directory!" >&2
exit 1
fi
dest="$1"
case "$dest" in
/usr/*|/lib/*|/libexec/*|/etc/*|/bin/*|/share/*)
echo "destination path cannot be a subpath of the source paths." >&2
exit 1
;;
esac
up() {
printf "$(echo "checking $1 .........." | head -c 20)"
if [ -d "/$1" ] && [ ! -d "$dest/$1" ]; then
printf " merging $1\n"
# is this a symlink to a directory?
[ -h "/$1" ] \
&& cp -a "/$1" "$dest/" \
|| mkdir "$dest/$1" && lmr "/$1" "$dest/$1"
else
printf " skipping $1\n"
fi
}
up lib
up libexec
up etc
up bin
up share
mkdir -p "$dest/boot"
# force bootstrap directory into lix os-style directory structure.
lmr -f /usr $dest \
&& echo "merged /usr into $dest" \
|| echo "did not lmr /usr into $dest"
lmr -f $dest/local $dest \
&& echo "merged $dest/local into $dest" \
|| echo "did not lmr $dest/local into $dest"
rm -fr $dest/local \
&& echo "removed $dest/local" \
|| echo "did not remove $dest/local"
lmr -f $dest/sbin $dest/bin \
&& echo "merged $dest/sbin into $dest/bin" \
|| echo "did not lmr $dest/sbin into $dest/bin"
rm -fr $dest/sbin \
&& echo "removed $dest/sbin" \
|| echo "did not remove $dest/sbin"
ln -sf . $dest/usr \
&& echo "ln'ed $dest/usr to ." \
|| echo "did not ln $dest/usr to ."
ln -sf ./bin $dest/sbin \
&& echo "ln'ed $dest/sbin to ./bin" \
|| echo "did not ln $dest/sbin to ./bin"