#!/bin/sh
#***********************************************************
# BusyBox Enhanced - /var/bin/busyboxse
#
# Versions *************************************************
# V. 1.03 - 28.01.2006
#   - added mkfifo, mknod
#   - removed auto shrink of busyboxse by install script
# V. 1.02 - 23.12.2005
#   - added crond
# V. 1.01 - 18.12.2005
#   - added shrink
#   - simplified installation - thx to SnowHead
#
# V. 1.0 - 17.12.2005 - initial
#
# Currently defined functions: *****************************
# awk, basename, bunzip2, busybox, bzcat, crond, cut, gunzip,
# gzip, mkfifo, mknod, renice, sed, sort, tail, tar, top, wc,
# zcat
#
# Install: *************************************************
# - kopiere busyboxse und installbbse nach /tmp
# - oeffne eine Telnetverbindung zur DBox: telnet dbox-ip
# - gebe folgende Befehle ein:  chmod 755 /tmp/installbbse
#                               /tmp/installbbse
#***********************************************************

# declare vars *********************************************
# busyboxse-path
SEBBPATH="/var/bin"


# install **************************************************
if [ ! -d $SEBBPATH ]; then
    mkdir $SEBBPATH
fi

mv -f /tmp/busyboxse $SEBBPATH/busyboxse
chmod 755 $SEBBPATH/busyboxse

#if [ ! -x $SEBBPATH/shrink ]; then
#    mv -f /tmp/shrink $SEBBPATH/shrink
#    chmod 755 $SEBBPATH/shrink
#fi

INSTPROG=0

# create symlinks... ***************************************
cd $SEBBPATH

if [ ! -x /bin/awk ]; then
    echo "awk..."
    ln -s busyboxse awk
    INSTPROG=1
fi
if [ ! -x /bin/basename ]; then
    echo "basename..."
    ln -s busyboxse basename
    INSTPROG=1
fi
if [ ! -x /bin/bunzip2 ]; then
    echo "bunzip2..."
    ln -s busyboxse bunzip2
    INSTPROG=1
fi
if [ ! -x /bin/bzcat ]; then
    echo "bzcat..."
    ln -s busyboxse bzcat
    INSTPROG=1
fi
if [ ! -x /bin/cut ]; then
    echo "cut..."
    ln -s busyboxse cut
    INSTPROG=1
fi
if [ ! -x /bin/gunzip ]; then
    echo "gunzip..."
    ln -s busyboxse gunzip
    INSTPROG=1
fi
if [ ! -x /bin/gzip ]; then
    echo "gzip..."
    ln -s busyboxse gzip
    INSTPROG=1
fi
if [ ! -x /bin/renice ]; then
    echo "renice..."
    ln -s busyboxse renice
    INSTPROG=1
fi
if [ ! -x /bin/sed ]; then
    echo "sed..."
    ln -s busyboxse sed
    INSTPROG=1
fi
if [ ! -x /bin/sort ]; then
    echo "sort..."
    ln -s busyboxse sort
    INSTPROG=1
fi
if [ ! -x /bin/tail ]; then
    echo "tail..."
    ln -s busyboxse tail
    INSTPROG=1
fi
if [ ! -x /bin/tar ]; then
    echo "tar..."
    ln -s busyboxse tar
    INSTPROG=1
fi
if [ ! -x /bin/top ]; then
    echo "top..."
    ln -s busyboxse top
    INSTPROG=1
fi
if [ ! -x /bin/wc ]; then
    echo "wc..."
    ln -s busyboxse wc
    INSTPROG=1
fi
if [ ! -x /bin/zcat ]; then
    echo "zcat..."
    ln -s busyboxse zcat
    INSTPROG=1
fi
if [ ! -x /bin/crond ]; then
    echo "crond..."
    ln -s busyboxse crond
    INSTPROG=1
fi
if [ ! -x /bin/mkfifo ]; then
    echo "mkfifo..."
    ln -s busyboxse mkfifo
    INSTPROG=1
fi
if [ ! -x /bin/mknod ]; then
    echo "mknod..."
    ln -s busyboxse mknod
    INSTPROG=1
fi

# check ****************************************************
if [ $INSTPROG -eq 0 ]; then
    echo "busyboxse is not needed - deleting..."
    rm $SEBBPATH/busyboxse
    echo "DONE!"
else
    echo "INSTALLATION DONE! have fun with the enhanced busybox"
fi

exit 0