#!/bin/sh

root=$(cd $(dirname $0); pwd)

# Create service files for running and logging
mkdir -p /service/vanlogger/log
cat >/service/vanlogger/run <<EOF
#!/bin/sh
exec 2>&1
exec /usr/bin/python $root/vanlogger.py
EOF
cat <<EOF >/service/vanlogger/log/run
#!/bin/sh
exec 2>&1
exec multilog t s25000 n4 /var/log/vanlogger
EOF
chmod 755 /service/vanlogger/run /service/vanlogger/log/run

# Create rc.local hooks for reinstallation
mkdir /data/rc.local.d /data/rcS.local.d
cat >/data/rc.local.d/vanlogger <<EOF
#!/bin/sh
sh $root/install.sh
EOF

cat >/data/rc.local <<EOF
#!/bin/sh
for s in /data/rc.local.d/*; do
  \$s
done
EOF

cat >/data/rcS.local <<EOF
#!/bin/sh
for s in /data/rcS.local.d/*; do
  \$s
done
EOF

chmod 755 /data/rc.local.d/vanlogger /data/rc.local /data/rcS.local
