45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
from jinja2 import Environment, FileSystemLoader
|
||
|
||
# 1. 定义你的客制化参数字典
|
||
config_vars = {
|
||
# 全局变量
|
||
"gateway_lan_ip": "192.168.2.1",
|
||
"gateway_lan_cidr": "192.168.2.0/24",
|
||
"wan_interface": "eno1", # 网关主机外网网卡
|
||
"lan_interface": "enx00e04c6800ae", # 网关主机内网网卡
|
||
"client_lan_interface": "eth0", # 内网主机网卡
|
||
|
||
# 网关主机独有变量
|
||
"dhcp_start_ip": "192.168.2.100",
|
||
"dhcp_end_ip": "192.168.2.200",
|
||
"dhcp_lease_time": "7200",
|
||
"remote_ssh_user": "kww",
|
||
"remote_ssh_ip": "8.222.165.87", # !!! 替换为你的远程SSH服务器IP
|
||
"remote_ssh_name": "atvoe.com", # !!! 替换为你的远程SSH服务器域名
|
||
"remote_ssh_port": "22",
|
||
"local_socks5_port": "1080",
|
||
"redsocks_port": "55555",
|
||
"domestic_dns1": "223.5.5.5",
|
||
"domestic_dns2": "114.114.114.114",
|
||
"foreign_dns1": "8.8.8.8",
|
||
"foreign_dns2": "1.1.1.1",
|
||
"gfwlist2new_repo": "https://github.com/cokebar/gfwlist2dnsmasq_python.git",
|
||
"gfwlist2new_dir": "/opt/gfwlist2new",
|
||
|
||
}
|
||
|
||
# 2. 设置 Jinja2 环境
|
||
# 假设你的 .j2 模板文件与这个 Python 脚本在同一目录下
|
||
env = Environment(loader=FileSystemLoader('.'))
|
||
|
||
# 3. 渲染 gateway_config.sh
|
||
gateway_template = env.get_template('gateway.sh.j2')
|
||
rendered_gateway_script = gateway_template.render(config_vars)
|
||
|
||
with open('gateway.sh', 'w') as f:
|
||
f.write(rendered_gateway_script)
|
||
print("Generated gateway_config.sh")
|
||
|
||
print("\n!!! 请务必检查生成的 .sh 文件,特别是 SSH 代理和网卡名称等配置。")
|
||
print("在执行前,给它们添加可执行权限:chmod +x gateway_config.sh client_config.sh")
|