#!/bin/sh
#
# /etc/init.d/minircS
# (C)2007 Hans J. Koch <hjk@linutronix.de>
#

PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin"

export TSLIB_TSDEVICE=/dev/input/event1
export TSLIB_PLUGINDIR=/usr/lib/ts
export TSLIB_CONFFILE=/etc/ts.conf
export TSLIB_CALIBFILE=/etc/pointercal
export POINTERCAL_FILE=/etc/pointercal

# Mount /sys and /proc
/bin/mount -t proc proc /proc
/bin/mount -t sysfs sysfs /sys

# We're not using /sbin/hotplug
echo > /proc/sys/kernel/hotplug

# Mount tmpfs on /dev
/bin/mount -n -o size=5M,mode=0755 -t tmpfs tmpfs /dev
/bin/mkdir -p /dev/.udev/db/
/bin/mknod /dev/null c 1 3

# mount devpts on /dev/pts
/bin/mkdir /dev/pts
/bin/mount -t devpts devpts /dev/pts

# prepare directory for the mounting of the sd-card
/bin/mount -o size=1M -t tmpfs tmpfs /media
mkdir /media/sd-card0
mkdir /media/imglog-ramdisk
# moeved to /home/sick/apps/lector65x/bin/start-app.sh
#/bin/mount -o size=384M -t tmpfs tmpfs /media/imglog-ramdisk  

# Start udev daemon
/sbin/udevd --daemon
/sbin/udevtrigger
/sbin/udevsettle --timeout=5

# attach ubi
/bin/attach-persist-part.sh &> /dev/null

# mount other filesystems from /etc/fstab
/bin/mount -a

# remounting / rw
/bin/mount -o remount,rw,noatime,sync /

# Starting the logging daemons
syslogd
klogd

# Disable screen blanking
#echo "Disabling screen blanking..."
echo -e "\033[9;0]" > /dev/tty0
echo -e "\033[9;0]" > /dev/tty1
echo -e "\033[9;0]" > /dev/tty2

# change the send buffer size of sockets.
# So that the task wakeup latencies caused by Ethernet are reduced.
echo 1 >  /proc/sys/net/ipv4/tcp_window_scaling
echo 10240 87380 12582912 >  /proc/sys/net/ipv4/tcp_wmem
echo 87380 > /proc/sys/net/core/wmem_default
echo 12582912 > /proc/sys/net/core/wmem_max

# change socket time out.
echo 5 > /proc/sys/net/ipv4/tcp_fin_timeout
echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse

# Create OS release dependent folder
if [ ! -d /lib/modules/$(uname -r) ] ; then
  mkdir /lib/modules/$(uname -r)
fi

#change memory over commit settings
echo 2 > /proc/sys/vm/overcommit_memory

#set overcommit ratio to 100 percent
echo 100 > /proc/sys/vm/overcommit_ratio 

# Starting ssh server
/etc/init.d/sshd start

# Start inetd: Possibility to activale telnet and ftp (additional changes at inet.d.conf needed)
#/usr/sbin/inetd

# Start sdcard script
# if the sdcard script returns 0 start application
if /etc/init.d/start-sdcard-script &> /dev/null ; then

  # Set host name
  /etc/init.d/sethost

  # Start WDT Reset script
  #/bin/wdt-reset-task.sh &> /dev/null &

  # Start affinity script for multitasking option
  /etc/init.d/affinity.sh

  # Resize appfs and datafs partitions if the update_partitions.sh script exists
  if [ -e /root/update_partitions.sh ]; then
    if ( set -o pipefail; /root/update_partitions.sh 2>&1 | tee -a /root/update_partitions.log ) ; then
      rm /root/update_partitions.sh
      mv /root/update_partitions.log /etc/sick/
    fi
  fi

  # Start application
  /home/sick/apps/lector65x/bin/start-app.sh &

  # Start net script to configure ethernet
  /etc/init.d/net 30 &


fi

# Ready
exit 0

