Skip to content

Commit

Permalink
Merge pull request #31 from Anonym-tsk/ipk
Browse files Browse the repository at this point in the history
opkg packages build system
  • Loading branch information
Anonym-tsk authored Sep 5, 2024
2 parents d5bf76e + 243727b commit 05c77e9
Show file tree
Hide file tree
Showing 11 changed files with 325 additions and 12 deletions.
5 changes: 0 additions & 5 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ assignees: ''
Укажите вашего провайдера и тип подключения (ppp/ethernet/...)

**Выполните команды и приложите их вывод**
`/opt/etc/init.d/S51nfqws version`
```
<ВСТАВИТЬ СЮДА>
```

`/opt/etc/init.d/S51nfqws restart`
```
<ВСТАВИТЬ СЮДА>
Expand Down
84 changes: 84 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Build and publish release

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: write

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Bump version
id: bump_version
uses: remorses/bump-version@v8
with:
version_file: ./VERSION
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build packages
run: make all

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: true
prerelease: false

- name: Upload Release mips
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./out/nfqws-keenetic_${{ steps.bump_version.outputs.version }}_mips-3.4.ipk
asset_name: nfqws-keenetic_${{ steps.bump_version.outputs.version }}_mips-3.4.ipk
asset_content_type: application/octet-stream

- name: Upload Release mipsel
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./out/nfqws-keenetic_${{ steps.bump_version.outputs.version }}_mipsel-3.4.ipk
asset_name: nfqws-keenetic_${{ steps.bump_version.outputs.version }}_mipsel-3.4.ipk
asset_content_type: application/octet-stream

- name: Upload Release aarch64
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./out/nfqws-keenetic_${{ steps.bump_version.outputs.version }}_aarch64-3.10.ipk
asset_name: nfqws-keenetic_${{ steps.bump_version.outputs.version }}_aarch64-3.10.ipk
asset_content_type: application/octet-stream

- name: Upload Release armv7
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./out/nfqws-keenetic_${{ steps.bump_version.outputs.version }}_armv7-3.2.ipk
asset_name: nfqws-keenetic_${{ steps.bump_version.outputs.version }}_armv7-3.2.ipk
asset_content_type: application/octet-stream
82 changes: 82 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
VERSION := $(shell cat VERSION)

.DEFAULT_GOAL := all

_clean:
rm -rf out/$(ARCH)
mkdir -p out/$(ARCH)/control
mkdir -p out/$(ARCH)/data

_conffiles:
echo "/opt/etc/nfqws/nfqws.conf" > out/$(ARCH)/control/conffiles
echo "/opt/etc/nfqws/user.list" >> out/$(ARCH)/control/conffiles
echo "/opt/etc/nfqws/auto.list" >> out/$(ARCH)/control/conffiles
echo "/opt/etc/nfqws/exclude.list" >> out/$(ARCH)/control/conffiles

_control:
echo "Package: nfqws-keenetic" > out/$(ARCH)/control/control
echo "Version: $(VERSION)" >> out/$(ARCH)/control/control
echo "Depends: busybox, iptables" >> out/$(ARCH)/control/control
echo "License: MIT" >> out/$(ARCH)/control/control
echo "Section: net" >> out/$(ARCH)/control/control
echo "URL: https://github.com/Anonym-tsk/nfqws-keenetic" >> out/$(ARCH)/control/control
echo "Architecture: $(ARCH)-$(KERNEL)" >> out/$(ARCH)/control/control
echo "Description: NFQWS service" >> out/$(ARCH)/control/control

_scripts:
cp common/ipk/preinst out/$(ARCH)/control/preinst
cp common/ipk/postinst out/$(ARCH)/control/postinst
cp common/ipk/prerm out/$(ARCH)/control/prerm
cp common/ipk/postrm out/$(ARCH)/control/postrm

_debian-binary:
echo 2.0 > out/$(ARCH)/debian-binary

_binary:
mkdir -p out/$(ARCH)/data/opt/usr/bin
curl -sSL $(URL) -o out/$(ARCH)/data/opt/usr/bin/nfqws
chmod +x out/$(ARCH)/data/opt/usr/bin/nfqws

_version:
sed -i "s#VERSION=\"0.0.0\"#VERSION=\"$(VERSION)\"#" out/$(ARCH)/data/opt/etc/init.d/S51nfqws

_ipk:
# cleanup
make _clean

# control.tar.gz
make _conffiles
make _control
make _scripts
cd out/$(ARCH)/control; tar czvf ../control.tar.gz .; cd ../../..

# data.tar.gz
make _binary
cp -r etc out/$(ARCH)/data/opt/etc
make _version
cd out/$(ARCH)/data; tar czvf ../data.tar.gz .; cd ../../..

# ipk
make _debian-binary
#ar -r out/nfqws-keenetic_$(VERSION)_$(ARCH)-3.10.ipk out/$(ARCH)/control.tar.gz out/$(ARCH)/data.tar.gz out/$(ARCH)/debian-binary
cd out/$(ARCH); tar czvf ../nfqws-keenetic_$(VERSION)_$(ARCH)-$(KERNEL).ipk control.tar.gz data.tar.gz debian-binary; cd ../..

mipsel:
make ARCH=mipsel KERNEL=3.4 URL="https://raw.githubusercontent.com/bol-van/zapret/master/binaries/mips32r1-lsb/nfqws" _ipk

mips:
make ARCH=mips KERNEL=3.4 URL="https://raw.githubusercontent.com/bol-van/zapret/master/binaries/mips32r1-msb/nfqws" _ipk

aarch64:
make ARCH=aarch64 KERNEL=3.10 URL="https://raw.githubusercontent.com/bol-van/zapret/master/binaries/aarch64/nfqws" _ipk

armv7:
make ARCH=armv7 KERNEL=3.2 URL="https://raw.githubusercontent.com/bol-van/zapret/master/binaries/arm/nfqws" _ipk

all: mipsel mips aarch64 armv7

clean:
rm -rf out/mipsel
rm -rf out/mips
rm -rf out/aarch64
rm -rf out/armv7
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ git pull --depth=1
### Полезное

1. Конфиг-файл `/opt/etc/nfqws/nfqws.conf`
2. Скрипт запуска/остановки `/opt/etc/init.d/S51nfqws {start|stop|restart|reload|status|version}`
2. Скрипт запуска/остановки `/opt/etc/init.d/S51nfqws {start|stop|restart|reload|status}`
3. Вручную добавить домены в список можно в файле `/opt/etc/nfqws/user.list` (один домен на строке, поддомены учитываются автоматически)
4. Автоматически добавленные домены `/opt/etc/nfqws/auto.list`
5. Лог автоматически добавленных доменов `/opt/var/log/nfqws.log`
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.0.0
1 change: 1 addition & 0 deletions common/install_func.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ remove_list_func() {
rm -f $LISTFILE
rm -f $LISTAUTOFILE
rm -f $LISTEXCLUDEFILE
rm -rf $CONFDIR
;;
esac
}
Expand Down
106 changes: 106 additions & 0 deletions common/ipk/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/bin/sh

CONFDIR=/opt/etc/nfqws
CONFFILE=$CONFDIR/nfqws.conf
LISTFILE=$CONFDIR/user.list
LISTAUTOFILE=$CONFDIR/auto.list
LISTEXCLUDEFILE=$CONFDIR/exclude.list
LISTLOG=/opt/var/log/nfqws.log
INIT_SCRIPT=/opt/etc/init.d/S51nfqws

stop_func() {
if [ -f "$INIT_SCRIPT" ]; then
$INIT_SCRIPT stop
fi
}

start_func() {
if [ -f "$INIT_SCRIPT" ]; then
$INIT_SCRIPT start
fi
}

show_interfaces_func() {
echo -e "\n----------------------"
ip addr show | awk -F" |/" '{gsub(/^ +/,"")}/inet /{print $(NF), $2}'
}

config_interface_func() {
if [ -z "$BIND_IFACE" ]; then
echo -e "\nEnter the provider interface name from the list above, e.g. eth3 (default) or nwg1"
echo "You can specify multiple interfaces separated by space, e.g. eth3 nwg1"
read BIND_IFACE
fi
if [ -z "$BIND_IFACE" ]; then
BIND_IFACE="eth3"
fi
echo "Selected interface: $BIND_IFACE"

sed -i "s#INPUT_ISP_INTERFACE#$BIND_IFACE#" $CONFFILE
}

config_select_mode_func() {
if [ -z "$MODE" ]; then
echo -e "\nSelect working mode: auto (default), list, all"
echo " auto - automatically detects blocked resources and adds them to the list"
echo " list - applies rules only to domains in the list $LISTFILE"
echo " all - applies rules to all traffic except domains from list $LISTEXCLUDEFILE"
read MODE
fi

if [ "$MODE" == "list" ]; then
EXTRA_ARGS="--hostlist=$LISTFILE"
elif [ "$MODE" == "all" ]; then
EXTRA_ARGS="--hostlist-exclude=$LISTEXCLUDEFILE"
else
MODE="auto"
EXTRA_ARGS="--hostlist=$LISTFILE --hostlist-auto=$LISTAUTOFILE --hostlist-auto-debug=$LISTLOG --hostlist-exclude=$LISTEXCLUDEFILE"
fi
echo "Selected mode: $MODE"

sed -i "s#INPUT_EXTRA_ARGS#$EXTRA_ARGS#" $CONFFILE
}

config_ipv6_func() {
echo -e "\nDisable IPv6 support (enabled by default)? y/N"
read yn
case $yn in
[Yy]* )
sed -i "s#IPV6_ENABLED=1#IPV6_ENABLED=0#" $CONFFILE
;;
esac
}

# Stop service if exist
stop_func

NFQWS_INSTALL_TYPE="install"
if [ -f "/tmp/nfqws_install_type" ]; then
# Set in preinst script
NFQWS_INSTALL_TYPE=$(cat "/tmp/nfqws_install_type")
rm -f /tmp/nfqws_install_type
fi

case "$NFQWS_INSTALL_TYPE" in
install)
# Setup ISP interface
show_interfaces_func
config_interface_func

# Setup working mode
config_select_mode_func

# Setup IPv6 support
config_ipv6_func

echo "Installation successful"
;;
*)
# Do nothing
;;
esac

# Starting Services
start_func

exit 0
29 changes: 29 additions & 0 deletions common/ipk/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

CONFDIR=/opt/etc/nfqws
LISTLOG=/opt/var/log/nfqws.log

remove_all_files_func() {
rm -f $LISTLOG
echo -e "\nRemove lists and config? y/N"
read yn
case $yn in
[Yy]* )
rm -rf $CONFDIR
;;
esac
}

case "$1" in
upgrade)
# Do nothing
;;
*)
# Remove all data
remove_all_files_func

echo "Unnstallation successful"
;;
esac

exit 0
6 changes: 6 additions & 0 deletions common/ipk/preinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

# Set `install` or `upgrade` for postinst script
echo "$1" > /tmp/nfqws_install_type

exit 0
14 changes: 14 additions & 0 deletions common/ipk/prerm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

INIT_SCRIPT=/opt/etc/init.d/S51nfqws

stop_func() {
if [ -f "$INIT_SCRIPT" ]; then
$INIT_SCRIPT stop
fi
}

# Stop service if exist
stop_func

exit 0
7 changes: 1 addition & 6 deletions etc/init.d/S51nfqws
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/sh

VERSION="1.2.1"

. /opt/etc/nfqws/nfqws.conf

NFQWS_BIN=/opt/usr/bin/nfqws
Expand Down Expand Up @@ -205,9 +203,6 @@ case "$1" in
kernel-modules)
kernel_modules_load
;;
version|-v|--version)
echo "nfqws-keenetic version: $VERSION"
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status|version}"
echo "Usage: $0 {start|stop|restart|reload|status}"
esac

0 comments on commit 05c77e9

Please sign in to comment.