diff --git a/README.md b/README.md index be7218b..49f4c56 100644 --- a/README.md +++ b/README.md @@ -26,26 +26,42 @@ export url='https://blog.sunbk201.site/cdn' && sh -c "$(curl -kfsSl $url/install 安装脚本执行成功后可通过以下命令启动 UA3F: ```sh # 启动 UA3F +uci set ua3f.enabled.enabled=1 +uci commit ua3f service ua3f.service start ``` 关闭或重启 UA3F 命令: -```bash +```sh # 关闭 UA3F service ua3f.service stop # 重启 UA3F 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 ``` shellclash 用户建议使用以下命令启动: -```bash +```sh sudo -u shellclash /root/ua3f ``` diff --git a/install.sh b/install.sh index ca3dc8f..ae3c51d 100755 --- a/install.sh +++ b/install.sh @@ -60,7 +60,13 @@ fi mv ua3f.service /etc/init.d/ && chmod +x /etc/init.d/ua3f.service /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 echo "Install UA3F Success." - echo "Use /etc/init.d/ua3f.service {start|stop|restart|enable} to control UA3F." fi \ No newline at end of file diff --git a/ua3f.service b/ua3f.service index ea06dd4..2a0d1af 100755 --- a/ua3f.service +++ b/ua3f.service @@ -8,22 +8,45 @@ NAME="ua3f" PROG="/root/$NAME" 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 procd_open_instance "$NAME" procd_set_param command "$PROG" - procd_append_param command -b "127.0.0.1" - procd_append_param command -p 1080 - procd_append_param command -f "FFF" - procd_append_param command -l info + procd_append_param command -b "$bind" + procd_append_param command -p $port + procd_append_param command -f "$ua" + procd_append_param command -l $log_level procd_set_param respawn procd_set_param stdout 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 - elif id -u nobody &> /dev/null; then + elif + id -u nobody & + >/dev/null + then procd_set_param user nobody fi @@ -31,6 +54,10 @@ start_service() { } reload_service() { - stop - start -} \ No newline at end of file + stop + start +} + +service_triggers() { + procd_add_reload_trigger "$NAME" +} diff --git a/ua3f.uci b/ua3f.uci new file mode 100644 index 0000000..36aff34 --- /dev/null +++ b/ua3f.uci @@ -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' \ No newline at end of file