#!/bin/sh
# version 0.1

. ./installink.sh
. ./!vda_ver

bin=/bin
chkbin=/usr/bin
STATIC=/app/$NAME$VER

applets=`./busybox 2>&1 \
| {
while read -r line; do
    if echo "$line" \
    | grep -F "Currently defined functions:" >/dev/null 2>&1; then
        break
    fi
done
if ! test "$line"; then exit; fi
while read -r line; do echo -n "$line "; done \
| sed "s/   */ /g" | sed "s/, / /g"
}
`

function foreign_link {
    if test -e "$1"; then
	if test -L "$1"; then
	    local t=`./busybox readlink "$1"`
	    t=`basename "$t"`
	    test "$t" = "busybox" && return 1
	fi
	return 0
    fi
    return 1
}

for a in $applets; do
    if foreign_link "$bin/$a"; then
	if foreign_link "$chkbin/$a"; then
	    echo "ln -sf $STATIC/busybox $bin/$a	# exists: $bin/$a and $chkbin/$a"
	else
	    echo "ln -sf $STATIC/busybox $bin/$a	# exists: $bin/$a"
	fi
    fi
done
