summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: fbffaa59031534764f6d7129cc041c2776071462 (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
# Maintainer: taotieren <admin@taotieren.com>

pkgname=vnt-git
pkgver=1.2.15.r0.g501a9e8
pkgrel=2
pkgdesc="A virtual network tool (or VPN),简便高效的异地组网、内网穿透工具"
arch=($CARCH)
url="https://github.com/lbl8603/vnt"
license=(Apache-2.0)
provides=(${pkgname%-git})
conflicts=(${pkgname%-git})
replaces=()
depends=(
    gcc-libs
    glibc)
makedepends=(git
    cargo)
optdepends=('iptables: Linux kernel packet control tool (using legacy interface)')
backup=()
options=('!lto')
install=
source=("${pkgname}::git+${url}.git")
sha256sums=('SKIP')

pkgver() {
    cd "${srcdir}/${pkgname}/"

    git describe --exclude=nightly --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
    git -C "${srcdir}/${pkgbase}" clean -dfx

    cd "${srcdir}/${pkgbase}/"

    git submodule update --init --recursive
}

build() {
    cd "${srcdir}/${pkgname}/"

    export RUSTUP_TOOLCHAIN=stable
    export CARGO_TARGET_DIR=target
    cargo build -p vnt-cli --release --all-features
}

check() {
    cd "${srcdir}/${pkgname}/"

    export RUSTUP_TOOLCHAIN=stable
    cargo test -p vnt-cli --all-features
}

package() {
    cd "${srcdir}/${pkgname}/"

    export RUSTUP_TOOLCHAIN=stable
    cargo install --no-track --all-features --path ./vnt-cli --root "$pkgdir/usr/" --bins

    install -Dm644 /dev/stdin "${pkgdir}/usr/lib/systemd/system/vnt-cli@.service" <<EOF
[Unit]
Description=VNT CLI Service for %i.
After = network.target syslog.target
Wants = network.target

[Service]
Type=forking
User=%i
Restart=on-abort
ExecStart=/usr/bin/vnt-cli
ExecStop=/usr/bin/vnt-cli --stop

[Install]
WantedBy=multi-user.target
EOF

    install -Dm644 /dev/stdin "${pkgdir}/etc/sysctl.d/80-vnt.conf" <<EOF
net.ipv4.ip_forward = 1
EOF

    install -Dm644 /dev/stdin "${pkgdir}/etc/vnt/iptables-vnt.rules" <<EOF
*nat
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING ! -o vnt-tun -s 10.26.0.0/24 -j MASQUERADE
COMMIT
EOF
}