#!/bin/bash

# for J1800, J1900, apl kernel modules
CPU_1800=$(cat /proc/cpuinfo | awk '/J1900|J1800/')
KERNEL=$(uname -r)
#/lib/modules/$KERNEL/kernel/syscall_interception.ko
MODULES="
/lib/modules/$KERNEL/kernel/rtl8812au.ko
/lib/modules/$KERNEL/kernel/rtl8822bu.ko
/lib/modules/$KERNEL/kernel/lib/crc-itu-t.ko
/lib/modules/$KERNEL/kernel/drivers/net/ethernet/aquantia/AQtion/aqc113.ko
"

for mod in $MODULES; do
    [ -e $mod ] && insmod $mod
done

#reboot device raid0 assembly failure
echo 2 >/sys/module/raid0/parameters/default_layout

#modify the sort for netcard
[ "X$CPU_1800" != "X" ] && /bin/chnet

sleep 1
# for active all net devices
cat /proc/net/dev | awk -F"[:/ ]+" '/eth[0-9]+:/ {sub(/^[ \t]+/,"");print $1}' | while read line; do
    ret=$(ifconfig | grep $line)
    if [ -z "$ret" ]; then
        ifconfig $line up
        sleep 2
    fi
done
sleep 2
[ -f /etc/resolv.conf ] && mv /etc/resolv.conf /tmp/resolv.conf -f
[ ! -f /tmp/resolv.conf ] && touch /tmp/resolv.conf
rm -f /etc/resolv.conf 2>/dev/null
ln -fsn /tmp/resolv.conf /etc/resolv.conf
[ ! -d /tmp/session ] && mkdir /tmp/session
#absolute safe mode
absolute_safe=$(awk -F= '/absolute_safe_mode/ {print $2}' /etc/absolute_safe/absolute_safe.conf 2>/dev/null)
if [ "$absolute_safe" != "1" ]; then
    /usr/sbin/absolute_safe_unlocker
fi
#fix db incorrect permission(only root read&write)
chmod 0666 /dev/null
chmod 0644 /etc/passwd /etc/group /etc/shadow
chmod 4755 /usr/bin/sudo /bin/busybox

if [ ! -e /etc/profile ]; then
    cp /etc.default/profile /etc/ -a
fi
