#!/bin/sh

# write a log, in case sth goes wrong
FFP_LOG=/mnt/HD_a2/ffp.log
exec >>$FFP_LOG 2>&1

# real path to ffp
FFP_PATH=/mnt/HD_a2/ffp

# prefix used to compile ffp packages
FFP_PREFIX=/ffp

# where to search for the install tarball
FFP_TARBALL=/mnt/HD_a2/fun_plug.tgz

# rc file path
FFP_RC=$FFP_PREFIX/etc/rc

echo "**** fun_plug script for DNS-323 (2008-04-13 tp@fonz.de) ****"
date

# first, create FFP_PREFIX link
echo "ln -snf $FFP_PATH $FFP_PREFIX"
ln -snf $FFP_PATH $FFP_PREFIX

# install tarball
if [ -r $FFP_TARBALL ]; then
    echo "* Installing $FFP_TARBALL ..."
    mkdir -p $FFP_PATH && tar xzvf $FFP_TARBALL -C $FFP_PATH
    if [ $? -eq 0 ]; then
        echo "* OK"
    fi
    rm $FFP_TARBALL
fi

# suid busybox
if [ -x $FFP_PREFIX/bin/busybox ]; then
    chown root.root $FFP_PREFIX/bin/busybox
    chmod 0755 $FFP_PREFIX/bin/busybox
    chmod u+s $FFP_PREFIX/bin/busybox
fi

# run commands
if [ -x $FFP_RC ]; then
    echo "* Running $FFP_RC ..."
    $FFP_RC
    echo "*  OK"
else
    echo "$FFP_RC: Not found or not executable"
fi

