#!/bin/bash
. $include_modpatch
if ! grep -q "mount -t proc proc /proc" "${1}/etc/init.d/rc.S" ;then
echo "********************************************************************************"
echo "enforce urlader settings"
mv "${1}/etc/init.d/rc.S" "${1}/etc/init.d/rc.S.orig"
cat > "${1}/etc/init.d/rc.S" << EOF
#!/bin/sh
mount -t proc proc /proc
EOF
CONFIG_ENVIRONMENT_PATH="$(grep --max-count=1 "export CONFIG_ENVIRONMENT_PATH=" "${1}/etc/init.d/rc.S.orig")"
echo ''$CONFIG_ENVIRONMENT_PATH'' >> "${1}/etc/init.d/rc.S"
echo 'echo firmware_version '$OEM' > $CONFIG_ENVIRONMENT_PATH/environment' >> "${1}/etc/init.d/rc.S"
[ "${ANNEX}"  == "A" ] && echo 'echo kernel_args annex='${ANNEX}' console=ttyS0,38400 > $CONFIG_ENVIRONMENT_PATH/environment' >> "${1}/etc/init.d/rc.S"
[ "${ANNEX}"  != "A" ] && echo 'echo kernel_args console=ttyS0,38400 > $CONFIG_ENVIRONMENT_PATH/environment' >> "${1}/etc/init.d/rc.S"
echo 'echo wlan_key '${WLANKEY}' > $CONFIG_ENVIRONMENT_PATH/environment' >> "${1}/etc/init.d/rc.S"
echo 'echo my_ipaddress 192.168.178.1 > $CONFIG_ENVIRONMENT_PATH/environment' >> "${1}/etc/init.d/rc.S"
echo 'echo ProductID '$CONFIG_PRODUKT' > $CONFIG_ENVIRONMENT_PATH/environment' >> "${1}/etc/init.d/rc.S"
[ "${ENFORCE_HWREVISION}" == "y" ] && echo 'echo HWRevision '$HWRevision' > $CONFIG_ENVIRONMENT_PATH/environment' >> "${1}/etc/init.d/rc.S"
if [ "${PROD}" == "7570_HN" ]; then
### 7570_HN: set mtd1 to max size and unset mtd5 
echo 'mtd5 > $CONFIG_ENVIRONMENT_PATH/environment' >> "${1}/etc/init.d/rc.S"
echo 'mtd1 0x90040000,0x90F80000 > $CONFIG_ENVIRONMENT_PATH/environment' >> "${1}/etc/init.d/rc.S"
fi

cat >> "${1}/etc/init.d/rc.S" << EOF
umount /proc
EOF
cat "${1}/etc/init.d/rc.S.orig" >> "${1}/etc/init.d/rc.S"
rm -f "${1}/etc/init.d/rc.S.orig"
chmod 755 "${1}/etc/init.d/rc.S"
fi
grep -q "echo firmware_version ${OEM} >" "${1}/etc/init.d/rc.S" && echo -e " OEM (Branding) set via firmware to:${ECHO_TUERKIS} $OEM $ECHO_END"
grep -q "echo wlan_key ${WLANKEY} >" "${1}/etc/init.d/rc.S" && echo -e " default WLAN Key set via firmware to:${ECHO_TUERKIS} $WLANKEY $ECHO_END"
grep -q "echo my_ipaddress 192.168.178.1 >" "${1}/etc/init.d/rc.S" && echo -e " my_ipaddress set via firmware to:${ECHO_TUERKIS} 192.168.178.1$ECHO_END"
grep -q "echo ProductID $CONFIG_PRODUKT >" "${1}/etc/init.d/rc.S" && echo -e " ProductID set via firmware to:${ECHO_TUERKIS} $CONFIG_PRODUKT$ECHO_END"
grep -q "echo HWRevision $HWRevision >" "${1}/etc/init.d/rc.S" && echo -e " HWRevision set via firmware to:${ECHO_TUERKIS} $HWRevision$ECHO_END"
grep -q "kernel_args annex=A console" "${1}/etc/init.d/rc.S" && echo -e " ANNEX set via firmware to:${ECHO_TUERKIS} A$ECHO_END"
grep -q "mtd1 0x90040000,0x90F80000" "${1}/etc/init.d/rc.S" && echo -e " mtd1 size set to:${ECHO_TUERKIS}0x90040000,0x90F80000$ECHO_END"
exit 0