#!/bin/sh
# Copyright © 2013-2016 Valve Corporation
# Copyright © 2017-2026 Collabora Ltd.
# SPDX-License-Identifier: MIT

set -eux

# Because our Debian-11-based SDKs are not "merged /usr",
# we need to create these in /bin, so that they will be overwritten
# correctly if we subsequently install the package that canonically provides
# the fully-featured implementation, for example iproute2.
for bin in \
    ifconfig \
    ip \
    nc \
    ping \
    ping6 \
    route \
; do
    if [ -e /bin/busybox ] && ! [ -e "/bin/$bin" ] && ! [ -e "/usr/bin/$bin" ]; then
        ln -fnsv busybox "/bin/$bin"
    fi
done

# Similarly we need to create these in /usr/bin, so that they will be
# overwritten if we subsequently install the package that canonically provides
# the fully-featured implementation, for example xxd.deb from src:vim.
for bin in \
    dos2unix \
    telnet \
    traceroute \
    traceroute6 \
    unix2dos \
    vi \
    xxd \
; do
    if [ -e /bin/busybox ] && ! [ -e "/bin/$bin" ] && ! [ -e "/usr/bin/$bin" ]; then
        ln -fnsv /bin/busybox "/usr/bin/$bin"
    fi
done
