summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authordetiam2023-12-01 21:49:55 +0800
committerdetiam2023-12-01 21:49:55 +0800
commit8ee5ce35c01ae4491f88881a829920882b6adc8f (patch)
tree9972eb45da67581432c2edd07f0b49f01f89bab5
parent8ca8ea282a95c312b7b8d5d103f16d03c70a2150 (diff)
downloadaur-phantomsocks-git.tar.gz
sync with phantomsocks-ipv6-git
-rw-r--r--.SRCINFO21
-rw-r--r--.gitignore9
-rw-r--r--PKGBUILD81
-rw-r--r--phantomsocks-init.sh120
-rw-r--r--phantomsocks.install22
-rw-r--r--phantomsocks.service12
-rw-r--r--phantomsocks.sysusers1
-rw-r--r--phantomsocks@.service16
8 files changed, 201 insertions, 81 deletions
diff --git a/.SRCINFO b/.SRCINFO
index c7098cd37f12..ed0d244a0c5c 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,26 +1,25 @@
pkgbase = phantomsocks-git
pkgdesc = A cross-platform proxy client/server for Linux/Windows/macOS
- pkgver = r282.3c556b0
+ pkgver = r301.b1b13c5
pkgrel = 1
- url = https://github.com/detiam/phantomsocks
+ url = https://github.com/macronut/phantomsocks
+ install = phantomsocks.install
arch = i686
arch = x86_64
license = LGPL-3.0
makedepends = go
makedepends = git
- makedepends = libpcap
depends = systemd
- optdepends = v2raya: for use with v2raya
+ depends = jq
+ optdepends = libpcap: you can build pcap version if you want, see PKGBUILD build()
provides = phantomsocks
conflicts = phantomsocks
replaces = phantomsocks
- source = git+https://github.com/detiam/phantomsocks
- source = phantomsocks.sysusers
+ source = git+https://github.com/macronut/phantomsocks.git
+ source = phantomsocks-init.sh
source = phantomsocks.service
- source = phantomsocks@.service
- md5sums = SKIP
- md5sums = SKIP
- md5sums = SKIP
- md5sums = SKIP
+ sha256sums = SKIP
+ sha256sums = 22d5545c6bb8430cd8efd1452e0647ee0d3feab0c8e775167ec291e4fba24927
+ sha256sums = 4602cf1421b16780aea3eef1d69ed44197efa6cbfe5e64193a127852ba71750c
pkgname = phantomsocks-git
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000000..5dee91459ecc
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,9 @@
+*
+!.gitignore
+!.SRCINFO
+!*.sh
+!*.patch
+!*.install
+!*.service
+!*.sysusers
+!PKGBUILD \ No newline at end of file
diff --git a/PKGBUILD b/PKGBUILD
index 9ae41bfb8a59..a0b298a90eee 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -1,68 +1,59 @@
# Maintainer: detiam <dehe_tian@outlook.com>
-# Contributor: detian <dehe_detian@outlook.com>
-pkgname=phantomsocks-git
+
_pkgname=phantomsocks
-pkgver=r282.3c556b0
+pkgname=phantomsocks-git
+pkgver=r301.b1b13c5
pkgrel=1
-epoch=
pkgdesc="A cross-platform proxy client/server for Linux/Windows/macOS"
arch=(i686 x86_64)
-url="https://github.com/detiam/$_pkgname"
-#_commit=a521259ffc1cfd8753845997c09644b976af2d6c
+url="https://github.com/macronut/$_pkgname"
license=('LGPL-3.0')
-groups=()
-depends=('systemd')
-makedepends=('go' 'git' 'libpcap')
-checkdepends=()
-optdepends=(
- 'v2raya: for use with v2raya'
- #'libpcap: you can build pcap version if you want, see PKGBUILD build()'
-)
+
provides=("$_pkgname")
conflicts=("$_pkgname")
replaces=("$_pkgname")
-backup=()
-options=()
-install=
-changelog=
-source=(
- "git+$url"
- "$_pkgname.sysusers"
- "$_pkgname.service"
- "$_pkgname@.service"
+makedepends=('go' 'git')
+depends=('systemd' 'jq')
+optdepends=(
+ 'libpcap: you can build pcap version if you want, see PKGBUILD build()'
)
-noextract=()
-md5sums=('SKIP' 'SKIP' 'SKIP' 'SKIP')
-validpgpkeys=()
+
+install=$_pkgname.install
+source=(
+ "git+${url}.git"
+ "$_pkgname-init.sh"
+ "$_pkgname.service")
+sha256sums=('SKIP'
+ '22d5545c6bb8430cd8efd1452e0647ee0d3feab0c8e775167ec291e4fba24927'
+ '4602cf1421b16780aea3eef1d69ed44197efa6cbfe5e64193a127852ba71750c')
pkgver() {
- cd "$_pkgname"
- ( set -o pipefail
- git describe --long --abbrev=7 2>/dev/null | sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
- printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short=7 HEAD)"
- )
+ cd "$_pkgname"
+ ( set -o pipefail
+ git describe --long --abbrev=7 2>/dev/null | sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
+ printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short=7 HEAD)"
+ )
}
build() {
- cd "$_pkgname"
- # Choose between them
- #go build -tags rawsocket
- go build -tags pcap
+ cd "$_pkgname"
+ # Choose between them
+ go build -tags rawsocket
+ #go build -tags pcap
}
package() {
- cd "$_pkgname"
+ install -dm755 "$pkgdir/usr/bin"
+ install -dm755 "$pkgdir/usr/lib/systemd/user"
+ install -dm755 "$pkgdir/usr/share/phantomsocks"
- install -Dm644 "../$_pkgname.service" "$pkgdir/usr/lib/systemd/system/$_pkgname.service"
- install -Dm644 "../$_pkgname@.service" "$pkgdir/usr/lib/systemd/system/$_pkgname@.service"
+ install -Dm644 "$_pkgname.service" "$pkgdir/usr/lib/systemd/user/"
+ install "$_pkgname-init.sh" "$pkgdir/usr/bin/$_pkgname-init"
- install -dm755 "$pkgdir/etc/phantomsocks"
- install -dm755 "$pkgdir/usr/lib/systemd/system"
- install -Dm600 "config.json" "$pkgdir/etc/phantomsocks/config.json"
- install -Dm600 "default.conf" "$pkgdir/etc/phantomsocks/default.conf"
+ cd "$_pkgname"
- install -Dm644 "$srcdir/$_pkgname.sysusers" "$pkgdir/usr/lib/sysusers.d/phantomsocks.conf"
+ install -Dm644 "config.json" "$pkgdir/usr/share/phantomsocks"
+ install -Dm644 "default.conf" "$pkgdir/usr/share/phantomsocks"
- install -dm755 "$pkgdir/usr/bin"
- install "$_pkgname" "$pkgdir/usr/bin/$_pkgname"
+ install "$_pkgname" "$pkgdir/usr/bin/$_pkgname"
}
diff --git a/phantomsocks-init.sh b/phantomsocks-init.sh
new file mode 100644
index 000000000000..44f8ae6332ff
--- /dev/null
+++ b/phantomsocks-init.sh
@@ -0,0 +1,120 @@
+#!/usr/bin/env sh
+
+CONFIGFILE="config.json"
+CONFIGDIR="${XDG_DATA_HOME:-"$HOME/.config"}/phantomsocks"
+
+getInterfaces() {
+ family=$1
+ i=0 && while true; do
+ interfaces=$(ip -j -"$family" r | jq -r '.[]|select(.dst=="default").dev')
+ if [ -n "$interfaces" ]; then
+ echo "$interfaces"
+ break
+ fi
+ if [ "$i" -ge 5 ]; then
+ echo "!!! no v$family ifaces" 1>&2
+ return 1
+ else
+ i=$((i + 1))
+ printf '.' 1>&2
+ sleep 2
+ fi
+ done && i=0
+}
+
+getInterface() {
+ family=$1
+ address=:: && [ "$family" = 4 ] && address=1
+ i=0 && while true; do
+ interface=$(ip -j -"$family" r g $address | jq -r '.[].dev')
+ if [ -n "$interface" ]; then
+ echo "$interface"
+ break
+ fi
+ if [ "$i" -ge 5 ]; then
+ echo "!!! no v$family iface" 1>&2
+ return 2
+ else
+ i=$((i + 1))
+ printf '.' 1>&2
+ sleep 2
+ fi
+ done && i=0
+}
+
+if [ "$(id -u)" = "0" ]; then
+ echo "Please do not run this script as root!"
+ exit 1
+fi
+
+if [ ! -d "$CONFIGDIR" ] || [ ! -e "$CONFIGDIR/$CONFIGFILE" ]; then
+ mkdir -p "$CONFIGDIR" && \
+ cp -rn /usr/share/phantomsocks/*.* "$CONFIGDIR"
+fi
+
+cd "$CONFIGDIR" || exit 1
+
+ifs_v6="$(getInterfaces 6)"; NO_IPV6=$?
+ifs_v4="$(getInterfaces 4)"; NO_IPV4=$?
+
+if [ $NO_IPV6 = 1 ] && [ $NO_IPV4 = 1 ]; then
+ echo !!! no network connection
+ exit 1
+elif [ $NO_IPV6 = 1 ]; then
+ defaIf_v4="$(getInterface 4)" || exit $?
+ defaIf_v6=$defaIf_v4
+ ifs_v6=$ifs_v4
+elif [ $NO_IPV4 = 1 ]; then
+ defaIf_v6="$(getInterface 6)" || exit $?
+ defaIf_v4=$defaIf_v6
+ ifs_v4=$ifs_v6
+else
+ defaIf_v6="$(getInterface 6)" || exit $?
+ defaIf_v4="$(getInterface 4)" || exit $?
+fi
+
+modifiedConf=$(jq -j \
+ --arg ifs_v6 "$ifs_v6" \
+ --arg ifs_v4 "$ifs_v4" \
+ --arg defaIf_v6 "$defaIf_v6" \
+ --arg defaIf_v4 "$defaIf_v4" '
+
+def setPface(fam; dev):
+ if (fam == 4) then
+ if (dev | inside($ifs_v4) | not) or (dev == "") then
+ dev = $defaIf_v4
+ end
+ elif (fam == 6) then
+ if (dev | inside($ifs_v6) | not) or (dev == "") then
+ dev = $defaIf_v6
+ end
+ end ;
+
+def validatePface(dev; hint):
+ if (dev != null) then
+ if (hint != null) then
+ if (hint | contains("ipv6")) and (hint | contains("ipv4")) then
+ setPface(4; dev)
+ elif (hint | contains("ipv6")) then
+ setPface(6; dev)
+ elif (hint | contains("ipv4")) then
+ setPface(4; dev)
+ else
+ setPface(6; dev)
+ end
+ else
+ setPface(4; dev)
+ end
+ end ;
+
+.services[] |= validatePface(.device; .hint) |
+.interfaces[] |= validatePface(.device; .hint)
+
+' "$CONFIGDIR/$CONFIGFILE") && echo "$modifiedConf" > "$CONFIGDIR/$CONFIGFILE"
+
+# workaround for rawsocks
+if (strings /usr/bin/phantomsocks | grep -e '-tags=rawsocket' > /dev/null 2>&1); then
+ sleep 2
+fi
+
+exec phantomsocks "$@" \ No newline at end of file
diff --git a/phantomsocks.install b/phantomsocks.install
new file mode 100644
index 000000000000..441a7c1a41bf
--- /dev/null
+++ b/phantomsocks.install
@@ -0,0 +1,22 @@
+do_setcap() {
+ setcap cap_net_raw+ep $(realpath $(which phantomsocks))
+}
+
+un_setcap() {
+ setcap cap_net_raw-ep $(realpath $(which phantomsocks))
+}
+
+post_install() {
+ do_setcap
+ echo 'start with command phantomsocks-init to automate get interface'
+ echo 'and use config at "~/.config/phantomsocks/config.json"'
+ echo 'the built-in systemd unit are also launch using it'
+}
+
+post_upgrade() {
+ do_setcap
+}
+
+pre_remove() {
+ un_setcap
+} \ No newline at end of file
diff --git a/phantomsocks.service b/phantomsocks.service
index e8df89b79eee..5ca8544e1d76 100644
--- a/phantomsocks.service
+++ b/phantomsocks.service
@@ -4,13 +4,9 @@ Wants=network-online.target
After=network-online.target
[Service]
-Type=simple
-Group=phantomsocks
-WorkingDirectory=/etc/phantomsocks
-ExecStart=/usr/bin/phantomsocks
-Restart=on-abnormal
-RestartSec=5
+ExecStart=/usr/bin/phantomsocks-init
+Restart=no
+#RestartSec=5
[Install]
-WantedBy=multi-user.target
-Alias=
+WantedBy=default.target
diff --git a/phantomsocks.sysusers b/phantomsocks.sysusers
deleted file mode 100644
index 641b7580738d..000000000000
--- a/phantomsocks.sysusers
+++ /dev/null
@@ -1 +0,0 @@
-u phantomsocks - "Phantomsocks daemon"
diff --git a/phantomsocks@.service b/phantomsocks@.service
deleted file mode 100644
index ad26f0cfee6a..000000000000
--- a/phantomsocks@.service
+++ /dev/null
@@ -1,16 +0,0 @@
-[Unit]
-Description=Phantomsocks process, on %I
-Wants=network-online.target
-After=network-online.target
-
-[Service]
-Type=simple
-Group=phantomsocks
-WorkingDirectory=/etc/phantomsocks/%I
-ExecStart=/usr/bin/phantomsocks
-Restart=on-abnormal
-RestartSec=5
-
-[Install]
-WantedBy=multi-user.target
-Alias=