summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 16de230ada40653edc52945e5c0c54c76fb2fba8 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Maintainer:
# Contributor: Ahmad Hasan Mubashshir <ahmubashshir@gmail.com>

: ${_pkgtype=-git}

_pkgname="zapret"
pkgbase="$_pkgname${_pkgtype:-}"
pkgver=62.r3.gc532ec4
pkgrel=1
pkgdesc="Bypass deep packet inspection"
url="https://github.com/bol-van/zapret"
license=('MIT')
arch=('x86_64')

depends=(
  'curl'
  'ipset'
  'iptables'
  'systemd'
)
makedepends=(
  'git'
  'libnetfilter_queue'
)

provides=(
  "$_pkgname=$pkgver"
  "$pkgbase=$pkgver"
)
conflicts=("$_pkgname")

_pkgsrc="$_pkgname"
source=(
  "$_pkgsrc"::"git+$url.git"
  "sysusers.conf"
)
sha256sums=(
  'SKIP'
  '25c309e2ec545c9ee53759e23961c8a3f02708a7ba8dcbabab6eb681a36c03c0'
)

pkgver() {
  cd "$_pkgsrc"
  local _file _hash _ver _rev
  _file="docs/changes.txt"
  read -r _hash _ver < <(
    NL=$(awk '/^v[0-9]+/{n=NR}END{print n}' "$_file")

    git blame -L "$NL,+1" -- "$_file" \
      | awk '{print $1" "$NF }' \
      | sed -E -e 's& v([0-9]+)([^0-9].*)?$& \1&'
  )
  _rev=$(git rev-list --count --cherry-pick "$_hash"...HEAD)

  printf "%s.r%s.g%s" "${_ver:?}" "${_rev:?}" "${_hash::7}"
}

build() {
  cd "$_pkgsrc"
  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() {
  depends=(
    "$pkgbase=$pkgver"
    'curl'
    'ipset'
    'iptables'
    'systemd'
  )
  provides=("zapret-common=$pkgver")
  conflicts=('zapret-common')
  pkgdesc+=' - common files'

  cd "$_pkgsrc"
  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/$_pkgname/LICENSE"

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

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

  cd "$_pkgsrc"
  install -Dm644 config.default "$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() {
  depends=("zapret-common-git=$pkgver")
  provides+=("zapret-tpws=$pkgver")
  conflicts+=('zapret-tpws')
  backup=("${makepkg_program_name+/}opt/zapret/config.tpws")
  pkgdesc+=' - transparent proxy mode'

  cd "$_pkgsrc"
  install -Dm644 config.default "$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() {
  unset depends
  provides=("zapret-docs=$pkgver")
  conflicts=('zapret-docs')
  pkgdesc+=' - docs and manuals'

  cd "$_pkgsrc"
  install -Dm644 docs/*.* -t "$pkgdir/usr/share/doc/$_pkgname"
  install -Dm644 docs/LICENSE.txt "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  install -Dm644 docs/LICENSE.txt "$pkgdir/usr/share/doc/$_pkgname/LICENSE"
  install -Dm644 docs/changes.txt "$pkgdir/usr/share/doc/$_pkgname/CHANGELOG"

  _rm() {
    rm -rf "$pkgdir/usr/share/doc/$_pkgname/$1"
  }
  _rm LICENSE.txt
  _rm changes.txt
}

pkgname=(
  "$_pkgname-nfqws${_pkgtype:-}"
  "$_pkgname-tpws${_pkgtype:-}"
  "$_pkgname-common${_pkgtype:-}"
  "$_pkgname-docs${_pkgtype:-}"
)
for _p in "${pkgname[@]}"; do
  eval "package_$_p() {
    $(declare -f "_package_${_p%$_pkgtype}")
    _package_${_p%$_pkgtype}
  }"
done