From b058f9f128d081c8d96345238a5075846f30e108 Mon Sep 17 00:00:00 2001 From: bol-van Date: Mon, 21 Oct 2024 17:43:29 +0300 Subject: [PATCH] init.d: openwrt min disk space startup --- docs/readme.txt | 23 +++++++++++++ init.d/openwrt-minimal/readme.txt | 20 +++++++++++ init.d/openwrt-minimal/tpws/etc/init.d/tpws | 34 +++++++++++++++++++ .../tpws/etc/nftables.d/90-tpws.nft | 8 +++++ install_easy.sh | 1 + 5 files changed, 86 insertions(+) create mode 100644 init.d/openwrt-minimal/readme.txt create mode 100755 init.d/openwrt-minimal/tpws/etc/init.d/tpws create mode 100644 init.d/openwrt-minimal/tpws/etc/nftables.d/90-tpws.nft diff --git a/docs/readme.txt b/docs/readme.txt index a773bf8..4f52a30 100644 --- a/docs/readme.txt +++ b/docs/readme.txt @@ -1716,6 +1716,29 @@ install_easy.sh автоматизирует ручные варианты пр Система простой инсталяции заточена на любое умышленное или неумышленное изменение прав доступа на файлы. Устойчива к репаку под windows. После копирования в /opt права будут принудительно восстановлены. + +Установка на openwrt в режиме острой нехватки места на диске +------------------------------------------------------------ + +Инструкция только для openwrt 22 и выше с nftables. Требуется около 120 кб на диске. +Придется отказаться от всего, кроме tpws. +Никаких зависимостей устанавливать не нужно. + +Скопируйте все из init.d/openwrt-minimal/tpws/* в корень openwrt. +Установите права на файлы : chmod 755 /etc/init.d/tpws /usr/bin/tpws +Отредактируйте /etc/config/tpws +/etc/init.d/tpws enable +/etc/init.d/tpws start +fw4 reload + +Полное удаление : + +/etc/init.d/tpws disable +/etc/init.d/tpws stop +rm -f /etc/nftables.d/90-tpws.nft /etc/init.d/tpws +fw4 restart + + Android ------- diff --git a/init.d/openwrt-minimal/readme.txt b/init.d/openwrt-minimal/readme.txt new file mode 100644 index 0000000..f2f7d02 --- /dev/null +++ b/init.d/openwrt-minimal/readme.txt @@ -0,0 +1,20 @@ +Minimal tpws startup script for low storage openwrt with nftables. +No opkg dependencies required ! + +* install : + +Make sure you are running openwrt with nftables, not iptables. +Copy everything from tpws directory to the root of the router. +Copy tpws binary for your architecture to /usr/bin/tpws +Set proper access rights : chmod 755 /etc/init.d/tpws /usr/bin/tpws +EDIT /etc/config/tpws +/etc/init.d/tpws enable +/etc/init.d/tpws start +fw4 reload + +* full uninstall : + +/etc/init.d/tpws disable +/etc/init.d/tpws stop +rm -f /etc/nftables.d/90-tpws.nft /etc/init.d/tpws +fw4 restart diff --git a/init.d/openwrt-minimal/tpws/etc/init.d/tpws b/init.d/openwrt-minimal/tpws/etc/init.d/tpws new file mode 100755 index 0000000..65d3f1d --- /dev/null +++ b/init.d/openwrt-minimal/tpws/etc/init.d/tpws @@ -0,0 +1,34 @@ +#!/bin/sh /etc/rc.common + +TPWS_DEFAULT=/usr/bin/tpws +TPWS_USER_DEFAULT=daemon + +START=99 +STOP=01 +USE_PROCD=1 + +tpws_instance() +{ + config_get "$@" + + local enabled port opt + + config_get_bool enabled "$1" enabled 0 + [ "$enabled" -eq 1 ] || return 1 + + config_get port "$1" port + config_get opt "$1" opt + + local COMMAND="$TPWS --user=$TPWS_USER --port=$port $opt" + procd_open_instance + procd_set_param command $COMMAND + procd_close_instance +} + +start_service() +{ + config_load tpws + config_get TPWS_USER defaults user $TPWS_USER_DEFAULT + config_get TPWS defaults tpws $TPWS_DEFAULT + config_foreach tpws_instance tpws +} diff --git a/init.d/openwrt-minimal/tpws/etc/nftables.d/90-tpws.nft b/init.d/openwrt-minimal/tpws/etc/nftables.d/90-tpws.nft new file mode 100644 index 0000000..7ec3b82 --- /dev/null +++ b/init.d/openwrt-minimal/tpws/etc/nftables.d/90-tpws.nft @@ -0,0 +1,8 @@ +chain tpws_re { + type nat hook prerouting priority dstnat; policy accept; + tcp dport {80,443} redirect to :900 +} +chain tpws_out { + type nat hook output priority -100; policy accept; + tcp dport {80,443} skuid != daemon redirect to :900 +} diff --git a/install_easy.sh b/install_easy.sh index c95ed61..5e1085f 100755 --- a/install_easy.sh +++ b/install_easy.sh @@ -486,6 +486,7 @@ init.d/runit/zapret/finish \ init.d/openrc/zapret \ init.d/sysv/zapret \ init.d/openwrt/zapret \ +init.d/openwrt-minimal/tpws/etc/init.d/tpws \ uninstall_easy.sh \ ; do chmod 755 "$1/$f" 2>/dev/null ; done }