summaryrefslogtreecommitdiffstats
path: root/modules.d/busybox/hooks/s3-install-busybox-stage4.sh
blob: f5c0aae9169a26df9b4a7ba5935ba9db9da4843a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/ash

# copy busybox to NEWROOT unless one exists at the expected path.
bb_target_path="/opt/openslx/bin/busybox"
bb_source_path="$( type -p busybox )"
[ -x "$bb_source_path" ] || bb_source_path="$( command -v busybox )"

if ! [ -x "$bb_source_path" ]; then
	echo "Busybox binary not found in initrd!?"
	exit 1
fi

if [ -x "${NEWROOT}${bb_target_path}" ]; then
	echo "Not installing busybox in stage 4 - already exists"
	exit 1
fi

mkdir -p -- "${NEWROOT}/opt/openslx/bin" "${NEWROOT}/opt/openslx/sbin"
cp -f -- "$bb_source_path" "${NEWROOT}${bb_target_path}"
# --list-full gives {s,}bin prefixes
for app in $( busybox --list-full ); do
	# No -f, so we skip any tools that might already exist
	ln -ns -- "$bb_target_path" "${NEWROOT}/opt/openslx/$app"
done
# compat: /bin/ash if not exists
# also accept dead symlinks as it might be relative and just look dead
# to us from outside NEWROOT
if ! [ -e "${NEWROOT}/bin/ash" ] && ! [ -L "${NEWROOT}/bin/ash" ]; then
	ln -nsf -- "$bb_target_path" "${NEWROOT}/bin/ash"
else
	# either valid symlink or binary, log it and ignore.
	echo "'/bin/ash' is a symlink or binary, leaving it alone."
fi

exit 0