summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 9d83bfa98e80879ecf0770054dc7110e328de3bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Maintainer: Ahmad Hasan Mubashshir <ahmubashshir@gmail.com>
# from: git

pkgname=(
   zapret-{nfqws,tpws,common,docs}-git
)
pkgbase=zapret-git
pkgver=48.r13.8ae38be
pkgrel=1
pkgdesc="Bypass deep packet inspection."
arch=('x86_64')
url="https://github.com/bol-van/zapret"
license=('MIT')
depends=('systemd' 'ipset' 'curl' 'iptables')
makedepends=('libnetfilter_queue' 'git')
provides=("zapret=$pkgver" "zapret-git=$pkgver")
conflicts=('zapret')
source=(
   "zapret::git+https://github.com/bol-van/zapret.git"
   "sysusers.conf"
)
sha256sums=('SKIP'
            '25c309e2ec545c9ee53759e23961c8a3f02708a7ba8dcbabab6eb681a36c03c0')
pkgver()
{
   cd "$srcdir/${pkgbase%-git}"
   (  set -o pipefail
      read -r sha ver < <(
         NL=$(awk '/^v[[:digit:]]+/{n=NR}END{print n}' docs/changes.txt)

         git blame master docs/changes.txt \
            | awk -v NL=$NL 'NR == NL {print $1" "$NF }' \
            | sed -E 's/ v([[:digit:]]+)/ \1/'
      )
      git describe --tags --long 2>/dev/null | sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
      printf "%s.%s" \
         "${ver:+$ver.}r$(git rev-list --count ${sha:+$sha~..}HEAD)" \
         "$(git rev-parse --short HEAD)"
   ) | tr -s '[:space:]:\\-' '.'
   pkgrel=$(git diff --shortstat|cut -d' ' -f2)
}

build()
{
    cd "$srcdir/${pkgbase%-git}"
    make
}

_symlink() {
   mkdir -pm755 "$pkgdir/usr/bin"
   ln -s "/opt/zapret/$1" "$pkgdir/usr/bin/${1##*/}"
}

_set_config() {
   local _cfg="$pkgdir/opt/zapret/config.${1%/*}" _key="${1##*/}" _val="$2"
   if grep -q "^#$_key=" "$_cfg";then
      sed -i "/^#$_key/s/#//" "$_cfg"
   fi
   sed -i "/^$_key=/c\\$_key=$(printf '%q' "$_val")" "$_cfg"
}

package_zapret-common-git()
{
   depends=('systemd' 'ipset' 'curl' 'iptables' "zapret-git=$pkgver")
   provides=("zapret-common=$pkgver")
   conflicts=('zapret-common')

   cd "$srcdir/${pkgbase%-git}"

   for n in ip2net mdig;do
      install -Dm755 "binaries/my/$n" "$pkgdir/opt/zapret/$n/$n"
   done
   install -Dm644 init.d/systemd/*  -t "$pkgdir/usr/lib/systemd/system"
   install -Dm755 init.d/sysv/*     -t "$pkgdir/opt/zapret/init.d/sysv"
   install -Dm755 ipset/*           -t "$pkgdir/opt/zapret/ipset"
   install -Dm644 common/*          -t "$pkgdir/opt/zapret/common"
   install -Dm644 "$srcdir/sysusers.conf" "$pkgdir/usr/lib/sysusers.d/zapret.conf"
   install -Dm644 docs/LICENSE.txt        "$pkgdir/usr/share/licenses/${pkgbase%-git}/LICENSE"
   install -Dm644 docs/LICENSE.txt        "$pkgdir/usr/share/doc/${pkgbase%-git}/LICENSE"
   install -Dm644 docs/changes.txt        "$pkgdir/usr/share/doc/${pkgbase%-git}/CHANGELOG"

   sed -i '1s/$/\n\nWS_USER=zapret/' "$pkgdir/opt/zapret/init.d/sysv/functions"
   _symlink init.d/sysv/zapret
}

package_zapret-nfqws-git() {

   depends=('libnetfilter_queue' "zapret-common-git=$pkgver")
   provides+=("zapret-nfqws=$pkgver")
   conflicts+=('zapret-nfqws')
   backup=("${makepkg_program_name+/}opt/zapret/config.nfqws")


   cd "$srcdir/${pkgbase%-git}"

   install -Dm644 config              "$pkgdir/opt/zapret/config.nfqws"
   install -Dm755 "binaries/my/nfqws" "$pkgdir/opt/zapret/nfq/nfqws"
   install -Dm644 docs/LICENSE.txt    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
   ln -s config.nfqws "$pkgdir/opt/zapret/config"

   _symlink nfq/nfqws

   _set_config nfqws/FWTYPE iptables
   _set_config nfqws/MODE nfqws
   _set_config nfqws/MODE_HTTP_KEEPALIVE 1
   _set_config nfqws/MODE_HTTPS 1
   _set_config nfqws/MODE_HTTP 1
}

package_zapret-tpws-git() {
   depends=("zapret-common-git=$pkgver")
   provides+=("zapret-tpws=$pkgver")
   conflicts+=('zapret-tpws')
   backup=("${makepkg_program_name+/}opt/zapret/config.tpws")

   cd "$srcdir/${pkgbase%-git}"

   install -Dm644 config             "$pkgdir/opt/zapret/config.tpws"
   install -Dm755 "binaries/my/tpws" "$pkgdir/opt/zapret/tpws/tpws"
   install -Dm644 docs/LICENSE.txt    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
   ln -s config.tpws "$pkgdir/opt/zapret/config"

   _symlink tpws/tpws

   _set_config tpws/FWTYPE iptables
   _set_config tpws/MODE tpws
   _set_config tpws/MODE_HTTP_KEEPALIVE 1
   _set_config tpws/MODE_HTTPS 1
   _set_config tpws/MODE_HTTP 1
}

package_zapret-docs-git() {
   unset depends
   provides=("zapret-docs=$pkgver")
   conflicts=('zapret-docs')

   cd "$srcdir/${pkgbase%-git}"
   install -Dm644 docs/*.*          -t "$pkgdir/usr/share/docs/${pkgbase%-git}"
   install -Dm644 docs/LICENSE.txt     "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

   _rm() {
      rm -rf "$pkgdir/usr/share/docs/${pkgbase%-git}/$1"
   }
   _rm LICENSE.txt
   _rm changes.txt
}