#! /bin/sh
mkdir -p /app/data
if [ -f "/app/file.fs" ]; then
    mount /app/file.fs /app/data
fi
mkdir -p /app/data/home
mkdir -p /app/data/database
mkdir -p /app/data/tmp
ln -sf /app/data/tmp /opt/www/tmp
if [ ! -z "$ANTOS_USER" ]; then
    [ ! -e "/home/$ANTOS_USER" ] && ln -sf /app/data/home "/home/$ANTOS_USER"
    adduser --home "/home/$ANTOS_USER" --disabled-password --gecos "" "$ANTOS_USER"
    echo "$ANTOS_USER:$ANTOS_PASSWORD" | /bin/chpasswd
fi

unset ANTOS_USER
unset ANTOS_PASSWORD

# start antd-tunnel service
[ ! -f "/app/antd-config.ini" ] && cp /opt/www/antd-config.ini /app/antd-config.ini
[ ! -f "/app/runner.ini" ] && cp /opt/www/runner.ini /app/runner.ini

# start syslog
syslogd -O /tmp/messages

usr/bin/antd /app/antd-config.ini >/dev/null 2>&1 | \
    ( sleep 2 && /opt/www/bin/runner /app/runner.ini >/dev/null 2>&1 &)
# /bin/sh