-
Notifications
You must be signed in to change notification settings - Fork 16
/
naive-quickstart.sh
110 lines (93 loc) · 2.72 KB
/
naive-quickstart.sh
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
#!/bin/bash
##Adapted from Trojan-quickstart.sh
set -euo pipefail
function prompt() {
while true; do
read -p "$1 [y/N] " yn
case $yn in
[Yy] ) return 0;;
[Nn]|"" ) return 1;;
esac
done
}
if [[ $(id -u) != 0 ]]; then
echo Please run this script as root.
exit 1
fi
if [[ $(uname -m 2> /dev/null) != x86_64 ]]; then
echo Please run this script on x86_64 machine.
exit 1
fi
getPMT(){
if [[ -n `command -v apt-get` ]];then
apt-get -qq update
apt-get -y -qq install curl xz-utils libnss3
elif [[ -n `command -v yum` ]]; then
yum -q makecache
yum -y -q install curl xz nss
else
return 1
fi
return 0
}
getPMT
NAME=naive
#NAMESIM=naive
VERSION=$(curl -fsSL https://api.github.com/repos/klzgrad/naiveproxy/releases/latest | grep tag_name | sed -E 's/.*"v(.*)".*/\1/')
TARBALL="naiveproxy-v${VERSION}-linux-x64.tar.xz"
PATHNAME="naiveproxy-v$VERSION-linux-x64"
DOWNLOADURL="https://github.com/klzgrad/naiveproxy/releases/download/v${VERSION}/${TARBALL}"
TMPDIR="$(mktemp -d)"
INSTALLPREFIX=/usr/local
SYSTEMDPREFIX=/etc/systemd/system
BINARYPATH="$INSTALLPREFIX/bin/naive"
CONFIGPATH="$INSTALLPREFIX/etc/naive/config.json"
SYSTEMDPATH="$SYSTEMDPREFIX/naive.service"
echo Entering temp directory $TMPDIR...
cd "$TMPDIR"
echo Downloading $NAME $VERSION...
curl -LO --progress-bar "$DOWNLOADURL" || wget -q --show-progress "$DOWNLOADURL"
echo Unpacking $NAME $VERSION...
tar -xf "$TARBALL"
cd "$PATHNAME"
echo Installing $NAME $VERSION to $BINARYPATH...
install -Dm755 "$NAME" "$BINARYPATH"
echo Installing $NAME server config to $CONFIGPATH...
if ! [[ -f "$CONFIGPATH" ]] || prompt "The server config already exists in $CONFIGPATH, overwrite?"; then
install -Dm755 "config.json" "$CONFIGPATH"
cat <<EOF > "$CONFIGPATH"
{
"listen": "http://127.0.0.1:8383",
"padding": true
}
EOF
else
echo Skipping installing $NAME server config...
fi
if [[ -d "$SYSTEMDPREFIX" ]]; then
echo Installing $NAME systemd service to $SYSTEMDPATH...
if ! [[ -f "$SYSTEMDPATH" ]] || prompt "The systemd service already exists in $SYSTEMDPATH, overwrite?"; then
cat > "$SYSTEMDPATH" << EOF
[Unit]
Description=$NAME
After=network.target network-online.target nss-lookup.target mysql.service mariadb.service mysqld.service
[Service]
Type=simple
StandardError=journal
ExecStart="$BINARYPATH" "$CONFIGPATH"
ExecReload=/bin/kill -HUP \$MAINPID
LimitNOFILE=51200
Restart=on-failure
RestartSec=1s
[Install]
WantedBy=multi-user.target
EOF
echo Reloading systemd daemon...
systemctl daemon-reload
else
echo Skipping installing $NAME systemd service...
fi
fi
echo Deleting temp directory $TMPDIR...
rm -rf "$TMPDIR"
echo Done!