明远智睿 Android5.1 增加开机启动设置IP + 启动web 服务器

参考博客:https://blog.csdn.net/simonjay2007/article/details/42103833

1.读取文件获取配置信息配置IP 和启动 web 服务器脚本
注意 Android 中的 shell 为阉割板的很多命令没有实现

#!/system/bin/sh
mount -o rw,remount -t auto /system   #必须重新挂载不然web  服务器没有文件读写权限导致启动失败 
line_num=0
local_ip=""
netmask=""
gateway=""
dns=""
/system/bin/busybox ifconfig eth0 up

cat /system/var/www/pages/config/local_net_onstart.conf | while read myline
do
	let line_num+=1
	#echo "LINE:""$line_num"
	if [ $line_num -eq 1 ]
	then
		local_ip=$myline	
		#ifconfig eth1    $local_ip
		echo $local_ip
		/system/bin/busybox ifconfig eth0  $local_ip   netmask 255.255.255.0  up
	fi
	
	if [ $line_num -eq 2 ]
	then
		netmask=$myline	
		#ifconfig eth1 10.0.1.135
		echo $netmask
	fi
	
	if [ $line_num -eq 3 ]
	then
		gateway=$myline	
		echo $gateway
		/system/bin/busybox route add default gw $gateway dev eth0
	fi

	if [ $line_num -eq 4 ]
	then
		dns=$myline	
		echo $dns
		setprop net.eth0.dns1 $dns
	fi
done

echo $local_ip

# 启动 web 服务器
/system/xbin/fcgiserver &
/system/bin/lighttpd  -f  /system/etc/lighttpd/lighttpd.conf
#ifconfig eth0  $local_ip 
#busybox route add default gw    $gateway   dev  eth0
#setprop net.eth0.dns1   $dns

#/system/bin/busybox ifconfig eth0 up
#/system/bin/busybox ifconfig eth0  $local_ip   netmask 255.255.255.0  up
#/system/bin/busybox route add default gw  192.168.5.1 dev eth0
#setprop net.eth0.dns1 $dns
#setprop net.eth0.dns2 $dns

echo "ok"

2.在init.rc 最后增加服务 代码如下:
lighttpd 为服务的名字 /system/var/www/config_shell/local_net_config_onstart.sh 为脚本的目录
class 等的解析可以查阅 邓凡平和罗升阳老师的博客里面有详细介绍的语法
在这里插入图片描述
3.增加 权限文件 xx.te 目录:安卓源码目录下 external/sepolicy/ 增加 lighttpd.te 文件
lighttpd.te 的内容如下:

# lighttpd
type lighttpd, domain;
type lighttpd_exec, exec_type, file_type;

init_daemon_domain(lighttpd)

allow lighttpd self:capability dac_override;

# Read OTA zip file from /data/data/com.google.android.gsf/app_download
r_dir_file(lighttpd, app_data_file)

userdebug_or_eng(`
  # For debugging, allow /data/local/tmp access
  r_dir_file(lighttpd, shell_data_file)
')

# Create tmp file /cache/recovery/command.tmp
# Read /cache/recovery/command
# Rename /cache/recovery/command.tmp to /cache/recovery/command
allow lighttpd cache_file:dir rw_dir_perms;
allow lighttpd cache_file:file create_file_perms;

# Set a property to reboot the device.
unix_socket_connect(lighttpd, property, init)
allow lighttpd powerctl_prop:property_service set;

# Raw writes to block device
allow lighttpd self:capability sys_rawio;
allow lighttpd block_device:blk_file w_file_perms;
allow lighttpd block_device:dir r_dir_perms;

4.修改文件权限参考 https://blog.csdn.net/simonjay2007/article/details/42103833

5.重新编译系统 eng 模式编译 烧写,启动成功 ,折腾了一周多时间— 注意串口log

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Nyiragongo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值