#!/bin/sh

echo "running S25_mnt_data.sh mit arg 1 $1"

start() {
	#falls mountpunkt nicht existiert
	if [ ! -d "/data" ] ; then
	    mkdir /data
	fi

	my_data_num=$(fw_printenv -n my_data_num)
	#Attach MTD${my_data_num}
	if ! ubiattach /dev/ubi_ctrl -m ${my_data_num} -O 2048
	then
		echo 'ubiattach (data) fehlgeschlagen.'
		exit 2
	fi
	#Mount MTD${my_data_num} unter /data
	if ! mount -t ubifs ubi1:data /data
	then
		echo 'mount ubi1:data fehlgeschlagen.'
		exit 4
	fi

	#falls ftpUser homedir nicht existiert
	if [ ! -d "/data/user/B" ] ; then
        echo 'Set Ftp UserHomeDir '
	    mkdir -p /data/user/B
        chgrp ftpgroup /data/user/B
        chmod 755 /data/user
        chmod 775 /data/user/B

	fi
}

stop() {
	umount /data
}

restart() {
	echo "restart not supported for S25_mnt_data.sh"
}

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart|reload)
  	restart
	;;
  *)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
esac

exit $?
