Debian Codegraph @

debian/v2ray.postinst

raw
1 #!/bin/sh
2
3 set -e
4
5 # POSIX-compliant maint function recommend by devref
6 # to check for the existence of a command
7 # https://www.debian.org/doc/manuals/developers-reference/ch06.html#bpp-debian-maint-scripts
8 pathfind() {
9 OLDIFS="$IFS"
10 IFS=:
11 for p in $PATH; do
12 if [ -x "$p/$*" ]; then
13 IFS="$OLDIFS"
14 return 0
15 fi
16 done
17 IFS="$OLDIFS"
18 return 1
19 }
20
21 case "$1" in
22 configure|reconfigure)
23 if pathfind setcap; then
24 if ! setcap \
25 cap_net_bind_service+ep /usr/bin/v2ray; then
26 echo "Failed to set capabilities; v2ray will only be able to start by root."
27 fi
28 else
29 echo "setcap not installed; v2ray will only be able to start by root."
30 fi
31 if [ ! -f /etc/v2ray/config.json ]; then
32 set +e
33 uuid="$(cat '/proc/sys/kernel/random/uuid')"
34 set -e
35 mkdir -p /etc/v2ray
36 sed "s/23ad6b10-8d1a-40f7-8ad0-e3e35cd38297/${uuid}/g" \
37 /usr/share/v2ray/config_vmess.json \
38 > /etc/v2ray/config.json
39 fi
40 ;;
41 abort-upgrade|abort-remove|abort-deconfigure)
42 exit 0
43 ;;
44 *)
45 echo "postinst called with unknown argument \`$1'" >&2
46 exit 0
47 ;;
48 esac
49
50 #DEBHELPER#
51
52 exit 0