From 8f0fdfef74a7942060db4ba2f024504762ce5993 Mon Sep 17 00:00:00 2001 From: Alex Derbenev Date: Sun, 26 Mar 2023 22:18:22 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9E=D0=B1=D0=B5=D1=80=D0=BD=D1=83=D0=BB?= =?UTF-8?q?=20=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82=20=D0=B2=20init.d=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=D0=B5=20=D0=B2=20=D1=84=D1=83=D0=BD?= =?UTF-8?q?=D0=BA=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/openwrt-hirkn.j2 | 192 ++++++++++++++++++++----------------- 1 file changed, 103 insertions(+), 89 deletions(-) diff --git a/templates/openwrt-hirkn.j2 b/templates/openwrt-hirkn.j2 index e7b956f..6915072 100644 --- a/templates/openwrt-hirkn.j2 +++ b/templates/openwrt-hirkn.j2 @@ -2,99 +2,113 @@ START=99 -dir=/tmp/lst -SUBNET=https://antifilter.download/list/subnet.lst -IP=https://antifilter.download/list/ip.lst -COMMUNITY=https://community.antifilter.download/list/community.lst -DOMAINS=https://community.antifilter.download/list/domains.lst +script () { + dir=/tmp/lst + SUBNET=https://antifilter.download/list/subnet.lst + IP=https://antifilter.download/list/ip.lst + COMMUNITY=https://community.antifilter.download/list/community.lst + DOMAINS=https://community.antifilter.download/list/domains.lst -{% if download_utility == "curl" %} -download () { - count=0 - while [ ! -f $dir/$1 ]; do - if [ $count -gt 10 ]; then - echo Exit - exit 1 - else - echo "Try $count" - curl -f -z $dir/$1 $2 --output $dir/$1 - count=$((count+1)) - sleep 5 - fi - done + {% if download_utility == "curl" %} + download () { + count=0 + while [ ! -f $dir/$1 ]; do + if [ $count -gt 10 ]; then + echo Exit + exit 1 + else + echo "Try $count" + curl -f -z $dir/$1 $2 --output $dir/$1 + count=$((count+1)) + sleep 5 + fi + done + } + + {% elif download_utility == "wget" %} + download () { + count=0 + while [ ! -f $dir/$1 ]; do + if [ $count -gt 10 ]; then + echo Exit + exit 1 + else + echo "Try $count" + wget -P $dir $2 + count=$((count+1)) + sleep 5 + fi + done + } + {% endif %} + + mkdir -p $dir + + echo "Run download lists" + {% if download_utility == "curl" %} + + {% if list_subnet %} + curl -f -z $dir/subnet.lst $SUBNET --output $dir/subnet.lst + download subnet.lst $SUBNET + {% endif %} + {% if list_ip %} + curl -f -z $dir/ip.lst $IP --output $dir/ip.lst + download ip.lst $IP + {% endif %} + {% if list_community %} + curl -f -z $dir/community.lst $COMMUNITY --output $dir/community.lst + download community.lst $COMMUNITY + {% endif %} + {% if list_domains and (ansible_distribution_major_version < "22" and dnsmasqfull_version.stdout) or ( ansible_distribution_major_version == "22" and dnsmasqfull_version.stdout >= "2.87") %} + curl -f -z $dir/domains.lst $DOMAINS --output $dir/domains.lst + download domains.lst $DOMAINS + {% endif %} + + {% elif download_utility == "wget" %} + + {% if list_subnet %} + rm -f /$dir/subnet.lst && wget -P $dir $SUBNET + download subnet.lst $SUBNET + {% endif %} + {% if list_ip %} + rm -f /$dir/ip.lst && wget -P $dir $IP + download ip.lst $IP + {% endif %} + {% if list_community %} + rm -f /$dir/community.lst && wget -P $dir $COMMUNITY + download community.lst $COMMUNITY + {% endif %} + {% if list_domains and (ansible_distribution_major_version < "22" and dnsmasqfull_version.stdout) or ( ansible_distribution_major_version == "22" and dnsmasqfull_version.stdout >= "2.87") %} + rm -f /$dir/domains.lst && wget -P $dir $DOMAINS + download domains.lst $DOMAINS + {% endif %} + {% endif %} + + {% if list_domains %} + {% if ansible_distribution_major_version == "22" and dnsmasqfull_version.stdout >= "2.87" %} + sed "s/.*/nftset=\/&\/4#inet#fw4#vpn_domains/" $dir/domains.lst > /tmp/dnsmasq.d/domains + + {% elif ansible_distribution_major_version < "22" and dnsmasqfull_version.stdout %} + sed "s/.*/ipset=\/&\/vpn_domains/" $dir/domains.lst > /tmp/dnsmasq.d/domains + {% endif %} + + echo "Dnsmasq restart" + /etc/init.d/dnsmasq restart + {% endif %} + + echo "Firewall restart" + /etc/init.d/firewall restart } -{% elif download_utility == "wget" %} -download () { - count=0 - while [ ! -f $dir/$1 ]; do - if [ $count -gt 10 ]; then - echo Exit - exit 1 - else - echo "Try $count" - wget -P $dir $2 - count=$((count+1)) - sleep 5 - fi - done +start () { + script } -{% endif %} -mkdir -p $dir +restart () { + script +} -echo "Run download lists" -{% if download_utility == "curl" %} - -{% if list_subnet %} -curl -f -z $dir/subnet.lst $SUBNET --output $dir/subnet.lst -download subnet.lst $SUBNET -{% endif %} -{% if list_ip %} -curl -f -z $dir/ip.lst $IP --output $dir/ip.lst -download ip.lst $IP -{% endif %} -{% if list_community %} -curl -f -z $dir/community.lst $COMMUNITY --output $dir/community.lst -download community.lst $COMMUNITY -{% endif %} -{% if list_domains and (ansible_distribution_major_version < "22" and dnsmasqfull_version.stdout) or ( ansible_distribution_major_version == "22" and dnsmasqfull_version.stdout >= "2.87") %} -curl -f -z $dir/domains.lst $DOMAINS --output $dir/domains.lst -download domains.lst $DOMAINS -{% endif %} - -{% elif download_utility == "wget" %} - -{% if list_subnet %} -rm -f /$dir/subnet.lst && wget -P $dir $SUBNET -download subnet.lst $SUBNET -{% endif %} -{% if list_ip %} -rm -f /$dir/ip.lst && wget -P $dir $IP -download ip.lst $IP -{% endif %} -{% if list_community %} -rm -f /$dir/community.lst && wget -P $dir $COMMUNITY -download community.lst $COMMUNITY -{% endif %} -{% if list_domains and (ansible_distribution_major_version < "22" and dnsmasqfull_version.stdout) or ( ansible_distribution_major_version == "22" and dnsmasqfull_version.stdout >= "2.87") %} -rm -f /$dir/domains.lst && wget -P $dir $DOMAINS -download domains.lst $DOMAINS -{% endif %} -{% endif %} - -{% if list_domains %} -{% if ansible_distribution_major_version == "22" and dnsmasqfull_version.stdout >= "2.87" %} -sed "s/.*/nftset=\/&\/4#inet#fw4#vpn_domains/" $dir/domains.lst > /tmp/dnsmasq.d/domains - -{% elif ansible_distribution_major_version < "22" and dnsmasqfull_version.stdout %} -sed "s/.*/ipset=\/&\/vpn_domains/" $dir/domains.lst > /tmp/dnsmasq.d/domains -{% endif %} - -echo "Dnsmasq restart" -/etc/init.d/dnsmasq restart -{% endif %} - -echo "Firewall restart" -/etc/init.d/firewall restart \ No newline at end of file +reload () { + script +} \ No newline at end of file From 671c1c91091055e18d84ea03deee5b8ceba72684 Mon Sep 17 00:00:00 2001 From: Alex Derbenev Date: Sun, 26 Mar 2023 22:24:48 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9F=D0=BE=D1=84=D0=B8=D0=BA=D1=81=D0=B8?= =?UTF-8?q?=D0=BB=20cron?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playbooks/hirkn.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playbooks/hirkn.yml b/playbooks/hirkn.yml index 53e047f..c1f49dc 100644 --- a/playbooks/hirkn.yml +++ b/playbooks/hirkn.yml @@ -79,7 +79,7 @@ lineinfile: path: /etc/crontabs/root create: yes - line: "0 4 * * * /etc/init.d/hirkn" + line: "0 4 * * * /etc/init.d/hirkn reload" when: check_cron.stdout == "" - name: enable and start crontab