feat: support uci

This commit is contained in:
SunBK201 2023-12-21 21:47:34 +08:00
parent 9dd83966db
commit 5b2bcb20b8
4 changed files with 72 additions and 15 deletions

View File

@ -26,26 +26,42 @@ export url='https://blog.sunbk201.site/cdn' && sh -c "$(curl -kfsSl $url/install
安装脚本执行成功后可通过以下命令启动 UA3F 安装脚本执行成功后可通过以下命令启动 UA3F
```sh ```sh
# 启动 UA3F # 启动 UA3F
uci set ua3f.enabled.enabled=1
uci commit ua3f
service ua3f.service start service ua3f.service start
``` ```
关闭或重启 UA3F 命令: 关闭或重启 UA3F 命令:
```bash ```sh
# 关闭 UA3F # 关闭 UA3F
service ua3f.service stop service ua3f.service stop
# 重启 UA3F # 重启 UA3F
service ua3f.service restart service ua3f.service restart
# 开机自启 ```
service ua3f.service enable
配置 UA3
```sh
# 自定义 UA
uci set ua3f.main.ua="FFF"
# 监听端口号
uci set ua3f.main.port="1080"
# 绑定地址
uci set ua3f.main.bind="127.0.0.1"
# 日志等级
uci set ua3f.main.log_level="info"
# 应用配置
uci commit ua3f
reload_config
``` ```
### 手动启动 ### 手动启动
```bash ```sh
sudo -u nobody /root/ua3f sudo -u nobody /root/ua3f
``` ```
shellclash 用户建议使用以下命令启动: shellclash 用户建议使用以下命令启动:
```bash ```sh
sudo -u shellclash /root/ua3f sudo -u shellclash /root/ua3f
``` ```

View File

@ -60,7 +60,13 @@ fi
mv ua3f.service /etc/init.d/ && chmod +x /etc/init.d/ua3f.service mv ua3f.service /etc/init.d/ && chmod +x /etc/init.d/ua3f.service
/etc/init.d/ua3f.service enable /etc/init.d/ua3f.service enable
wget https://blog.sunbk201.site/cdn/ua3f.uci
if [ $? -ne 0 ]; then
echo "Download ua3f.uci Failed, Please Retry."
exit 1
fi
mv ua3f.uci /etc/config/ua3f
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Install UA3F Success." echo "Install UA3F Success."
echo "Use /etc/init.d/ua3f.service {start|stop|restart|enable} to control UA3F."
fi fi

View File

@ -8,22 +8,45 @@ NAME="ua3f"
PROG="/root/$NAME" PROG="/root/$NAME"
start_service() { start_service() {
config_load "$NAME"
local enabled
config_get_bool enabled "enabled" "enabled" "0"
if [ "$enabled" -ne "1" ]; then
return 1
fi
local port
local bind
local ua
local log_level
config_get port "main" "port" "1080"
config_get bind "main" "bind" "127.0.0.1"
config_get ua "main" "ua" "FFF"
config_get log_level "main" "log_level" "info"
chmod o+w /var/log chmod o+w /var/log
procd_open_instance "$NAME" procd_open_instance "$NAME"
procd_set_param command "$PROG" procd_set_param command "$PROG"
procd_append_param command -b "127.0.0.1" procd_append_param command -b "$bind"
procd_append_param command -p 1080 procd_append_param command -p $port
procd_append_param command -f "FFF" procd_append_param command -f "$ua"
procd_append_param command -l info procd_append_param command -l $log_level
procd_set_param respawn procd_set_param respawn
procd_set_param stdout 1 procd_set_param stdout 1
procd_set_param stderr 1 procd_set_param stderr 1
if id -u shellclash &> /dev/null; then if
id -u shellclash &
>/dev/null
then
procd_set_param user shellclash procd_set_param user shellclash
elif id -u nobody &> /dev/null; then elif
id -u nobody &
>/dev/null
then
procd_set_param user nobody procd_set_param user nobody
fi fi
@ -31,6 +54,10 @@ start_service() {
} }
reload_service() { reload_service() {
stop stop
start start
}
service_triggers() {
procd_add_reload_trigger "$NAME"
} }

8
ua3f.uci Normal file
View File

@ -0,0 +1,8 @@
config 'ua3f' 'enabled'
option enabled '0'
config 'ua3f' 'main'
option port '1080'
option bind '127.0.0.1'
option ua 'FFF'
option log_level 'info'