#!/bin/ash

#
#CMD:
#

#
#ARGS
#

#
#DEFS
#
me_root="/mnt"
me_dir="/storage/application"
me_dir_cfg=$me_dir"/wlc/cfg"
me_dir_ha=$me_dir"/wlc/ha"
me_dir_xml=$me_dir"/wlc/xml"
me_dir_nim=$me_dir"/wlc/nim"
me_dir_ap_images="/storage/ap-images"

wlc_dir="/mnt/application"
wlc_dir_cfg=$wlc_dir"/cfg"
wlc_dir_ha=$wlc_dir"/ha"
wlc_dir_xml=$wlc_dir"/xml"
wlc_dir_nim=$wlc_dir"/nim"
wlc_dir_www="/var/www"
wlc_dir_lua="/var/www/lua"
wlc_dir_dx="/dx"

output="/dev/null 2 >&1"


#
#CMD EXEC
#
# This maps the storage of none flexexpress directories to the appropiate
# flexexpress directory. New symlinks can be added here.
#

mkdir -p $me_root

if [ ! -d $wlc_dir ]

then
    ln -fs $me_dir $wlc_dir > $output
fi
if [ ! -d $wlc_dir_cfg ]
then
    ln -fs $me_dir_cfg $wlc_dir_cfg > $output
fi
if [ ! -d $wlc_dir_ha ]
then
    ln -fs $me_dir_ha $wlc_dir_ha > $output
fi
if [ ! -d $wlc_dir_xml ]
then
    ln -fs $me_dir_xml $wlc_dir_xml > $output
fi
if [ ! -d $wlc_dir_nim ]
then
    ln -fs $me_dir_nim $wlc_dir_nim > $output
fi

if [ ! -d $me_dir_ap_images ]
then
    mkdir $me_dir_ap_images > $output
fi

if [ ! -d $wlc_dir_www ]
then
    mkdir $wlc_dir_www > $output
fi

if [ ! -d $wlc_dir_lua ]
then
    mkdir $wlc_dir_lua > $output
fi

if [ ! -d $wlc_dir_dx ]
then
    mkdir $wlc_dir_dx > $output
fi

# Start SSHD
printf "Starting SSHD: "
/usr/bin/start_sshd start
printf "ok\n"

# Start Redis-Server 
printf "Starting Redis-Server: "
/etc/init.d/redis start
printf "ok\n"

# Start naconnector
printf "Starting naconnector: "
/etc/init.d/nac start
printf "ok\n"

# Start nginx
printf "Starting nginx: "
/etc/init.d/nginx start
printf "ok\n"

mkfifo /tmp/charon.log -m 0666

exit 1
