参考博客: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