initial commit

This commit is contained in:
pyrschtjag committed 2026-10-02 21:34:01 +04:00
commit 13eace9ce9
219 files changed
+6918

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
#!/bin/sh
set -e
state=/var/lib/xray-lists
if [ -e "$state/.reload-nft" ]; then
nft -c -f /etc/nftables.conf
nft -f /etc/nftables.conf
rm -f "$state/.reload-nft"
fi
if [ -e "$state/.reload-dnsmasq" ]; then
dnsmasq --test
systemctl restart dnsmasq
rm -f "$state/.reload-dnsmasq"
fi
+16
View File
@@ -0,0 +1,16 @@
#!/bin/sh
set -eu
state=/var/lib/xray-lists
out=$(/opt/xray-lists/venv/bin/xray-lists --config /etc/xray-lists/config.yaml)
echo "$out"
if echo "$out" | grep -A 10 "changed:" | grep -q "nftsets.conf"; then
touch "$state/.reload-dnsmasq"
fi
if echo "$out" | grep -A 10 "changed:" | grep -q "\.elements\.nft"; then
touch "$state/.reload-nft"
fi
exit 0
+23
View File
@@ -0,0 +1,23 @@
[Unit]
Description=Update Xray lists
[Service]
Type=oneshot
User=xray-lists
Group=xray-lists
WorkingDirectory=/var/lib/xray-lists
UMask=0022
ExecStart=/opt/xray-lists/update.sh
ExecStartPost=+/opt/xray-lists/apply.sh
NoNewPrivileges=yes
PrivateTmp=yes
PrivateDevices=yes
ProtectHome=yes
ProtectSystem=strict
ReadWritePaths=/var/lib/xray-lists
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectControlGroups=yes
RestrictSUIDSGID=yes
LockPersonality=yes
+10
View File
@@ -0,0 +1,10 @@
[Unit]
Description=Run xray-lists update
[Timer]
OnBootSec=5min
OnUnitActiveSec=12h
Persistent=true
[Install]
WantedBy=timers.target
+26
View File
@@ -0,0 +1,26 @@
---
- name: reload nftables
ansible.builtin.command: nft -f /etc/nftables.conf
- name: restart dnsmasq
ansible.builtin.service:
name: dnsmasq
state: restarted
- name: run xray-lists systemd timer unit
ansible.builtin.systemd_service:
name: xray-lists.timer
state: started
enabled: true
daemon_reload: true
- name: update xray-lists
ansible.builtin.systemd_service:
name: xray-lists.service
state: started
- name: restart xray-lists timer
ansible.builtin.systemd_service:
name: xray-lists.timer
state: restarted
daemon_reload: true
+147
View File
@@ -0,0 +1,147 @@
---
- name: create xray-lists group
ansible.builtin.group:
name: xray-lists
system: true
state: present
- name: create xray-lists user
ansible.builtin.user:
name: xray-lists
group: xray-lists
system: true
shell: /usr/sbin/nologin
home: /var/lib/xray-lists
create_home: true
state: present
- name: install required system packages
ansible.builtin.apt:
name:
- python3-venv
- git
- rsync
state: present
update_cache: true
- name: ensure xray-lists directory exists
ansible.builtin.file:
path: "/etc/xray-lists"
state: directory
owner: "root"
group: "root"
mode: "0755"
- name: ensure local mirror of xray-lists exists on the runner
ansible.builtin.git:
repo: "https://gitea.oyacoi.ru/pyrschtjag/xray-lists.git"
dest: "{{ xray_lists_runner_mirror | default(lookup('env','HOME') + '/.cache/xray-lists-mirror') }}"
version: main
force: true
delegate_to: localhost
run_once: true
ignore_errors: true
vars:
ansible_connection: local
- name: attempt to clone/update xray-lists repository directly on the host
block:
- name: clone xray-lists repository from gitea on the host
ansible.builtin.git:
repo: "https://gitea.oyacoi.ru/pyrschtjag/xray-lists.git"
dest: /opt/xray-lists/xray-lists-src
version: main
force: true
rescue:
- name: warn that gitea is unreachable from the host
ansible.builtin.debug:
msg: "gitea.oyacoi.ru is unreachable from this host, falling back to the local copy from the runner"
- name: check whether the runner has a usable local mirror
ansible.builtin.stat:
path: "{{ xray_lists_runner_mirror | default(lookup('env','HOME') + '/.cache/xray-lists-mirror') }}/.git"
register: runner_mirror_stat
delegate_to: localhost
vars:
ansible_connection: local
- name: abort if the runner has no local mirror either
ansible.builtin.fail:
msg: "gitea is unreachable and the runner has no local mirror of xray-lists - cannot deploy"
when: not runner_mirror_stat.stat.exists
- name: ensure xray-lists-src directory exists on the host before sync
ansible.builtin.file:
path: /opt/xray-lists/xray-lists-src
state: directory
owner: root
group: root
mode: "0755"
- name: sync xray-lists source (including .git) from the runner to the host
ansible.posix.synchronize:
src: "{{ xray_lists_runner_mirror | default(lookup('env','HOME') + '/.cache/xray-lists-mirror') }}/"
dest: "root@{{ ip }}:/opt/xray-lists/xray-lists-src/"
rsync_opts:
- "--delete"
- name: create python venv for xray-lists
ansible.builtin.command: python3 -m venv /opt/xray-lists/venv
args:
creates: /opt/xray-lists/venv/bin/pip
- name: check if xray-lists is installed
ansible.builtin.command: /opt/xray-lists/venv/bin/pip show xray-lists
register: pip_check
changed_when: false
failed_when: false
- name: install xray-lists package into venv
ansible.builtin.command: /opt/xray-lists/venv/bin/pip install -e "/opt/xray-lists/xray-lists-src[socks]"
when: pip_check.rc != 0
- name: deploy helper scripts
ansible.builtin.copy:
src: "{{ item }}"
dest: "/opt/xray-lists/{{ item }}"
owner: root
group: root
mode: "0755"
loop:
- update.sh
- apply.sh
- name: deploy systemd service and timer unit
ansible.builtin.copy:
src: "{{ item }}"
dest: "/etc/systemd/system/{{ item }}"
owner: root
group: root
mode: "0644"
loop:
- xray-lists.service
- xray-lists.timer
notify: run xray-lists systemd timer unit
- name: ensure xray-lists config directory exists
ansible.builtin.file:
path: "/etc/xray-lists"
state: directory
owner: "root"
group: "root"
mode: "0755"
- name: render xray-lists config
ansible.builtin.template:
src: xray-config.yaml.j2
dest: /etc/xray-lists/config.yaml
owner: root
group: xray-lists
mode: "0640"
register: xray_lists_config
- name: update xray-lists
ansible.builtin.systemd_service:
name: xray-lists.service
state: started
when: xray_lists_config.changed
@@ -0,0 +1,51 @@
#jinja2: trim_blocks: True, lstrip_blocks: True
global:
cache_dir: {{ xray_lists_global.cache_dir }}
output_dir: {{ xray_lists_global.output_dir }}
dnsmasq_output: {{ xray_lists_global.dnsmasq_output }}
{% if xray_lists_global.proxy is defined %}
proxy: "{{ xray_lists_global.proxy }}"
{% endif %}
{% if proxy_user is defined %}
proxy_user: "{{ proxy_user }}"
proxy_pass: "{{ proxy_pass }}"
{% endif %}
http_timeout: {{ xray_lists_global.http_timeout | default(20) }}
ip_sets:
{% for id, item in xray_ip_sets.items() %}
- id: {{ id }}
output: {{ id }}_ip.elements.nft
{% if item.static is defined %}
static:
{% for s in item.static %}
- {{ s }}
{% endfor %}
{% endif %}
{% if item.urls is defined %}
urls:
{% for u in item.urls %}
- {{ u }}
{% endfor %}
{% endif %}
{% endfor %}
domain_sets:
{% for id, item in xray_domain_sets.items() %}
- id: {{ id }}
dnsmasq_target: "4#inet#filter#{{ id }}_dom"
{% if item.static is defined %}
static:
{% for s in item.static %}
- {{ s }}
{% endfor %}
{% endif %}
{% if item.urls is defined %}
urls:
{% for u in item.urls %}
- {{ u }}
{% endfor %}
{% endif %}
{% endfor %}
output_rules:
{% for rule in output_rules %}
- {{ rule }}
{% endfor %}