#!/bin/sh

source /etc/utils/shell-utils.sh
DEBUG=0

TARGET_DESC="AUX filesystems and folders"

log "[IM][system init][+][${TARGET_DESC}] Start..."

mkdir -p /sys /proc /dev /ram

grep -q debugfs /proc/mounts || mount -t debugfs debugfs /sys/kernel/debug
grep -q proc /proc/mounts    || mount -t proc proc /proc
grep -q sysfs /proc/mounts   || mount -t sysfs sys /sys

mkdir -p /dev/shm
mount -t tmpfs -o noexec,nosuid,nodev,mode=1777 shm /dev/shm
mount -t ramfs none /ram

mkdir -p /ram/tmp /ram/db /ram/ntp /ram/run/dbus /ram/media /ram/data /ram/mnt /ram/mnt/smb /ram/mnt/nfs /ram/lock/subsys/ /ram/run/lirc/ /ram/drm
mkdir /ram/wifi /ram/wifi/configs /ram/wifi/logs /ram/logs

mkdir /ram/etc_shadow
mkdir -p /ram/etc_shadow/ppp/peers

# languages
ln -s /etc/languages_utf8.txt /ram/data/languages_utf8.txt
ln -s /etc/timezone_list.conf /ram/data/timezone_list.conf

# create shell simple IPC (does not support return values)
mkfifo /ram/ipc-simple-pipe

# CIFS security fix
if [ -f /proc/fs/cifs/SecurityFlags ]; then
    echo 0x23 > /proc/fs/cifs/SecurityFlags
fi

# Don't let SCHED_FIFO / SCHED_RR realtime threads get preempted
echo -1 > /proc/sys/kernel/sched_rt_runtime_us

# network fix
echo 1000000 > /proc/sys/net/core/rmem_max

log "[IM][system init][+][${TARGET_DESC}] DONE."
