-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy patheasy-dp.sh
More file actions
executable file
·158 lines (130 loc) · 3.75 KB
/
easy-dp.sh
File metadata and controls
executable file
·158 lines (130 loc) · 3.75 KB
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
#!/bin/bash
# halt on any error for safety and proper pipe handling
set -euo pipefail ; # <- this semicolon and comment make options apply
# even when script is corrupt by CRLF line terminators
# empty line must follow this comment for immediate fail with CRLF newlines
arch="$(uname -m)"
ensure_deps() {
for dep in "$@"; do
if ! command -v "$dep" >/dev/null 2>&1 ; then
>&2 echo "Unable to locate dependency: \"$dep\". Please install it."
exit 1
fi
done
}
ensure_deps curl openssl tr mktemp install
mkdir -p /usr/local/bin
# Install or update dumbproxy
#
declare -A dp_arch_map=(
["x86_64"]="amd64"
["i386"]="386"
["i486"]="386"
["i586"]="386"
["i686"]="386"
["aarch64"]="arm64"
["armv5l"]="arm"
["armv6l"]="arm"
["armv7l"]="arm"
["armhf"]="arm"
)
dp_download_url="https://github.com/SenseUnit/dumbproxy/releases/latest/download/dumbproxy.linux-${dp_arch_map[$arch]}"
tmp="$(mktemp)"
curl --no-progress-meter -Lo "$tmp" "$dp_download_url"
install "$tmp" /usr/local/bin/dumbproxy
rm "$tmp" || true
mkdir -p /etc/dumbproxy
passwd="$(tr -cd '[:alnum:]' < /dev/urandom | dd bs=1 count=10 2>/dev/null || true)"
/usr/local/bin/dumbproxy -passwd /etc/dumbproxy/passwd "auto" "${passwd}"
cat > /etc/dumbproxy/dumbproxy.cfg <<EOF
auth basicfile://?path=/etc/dumbproxy/passwd
bind-address :443
cert /etc/dumbproxy/fullchain.pem
key /etc/dumbproxy/key.pem
EOF
cat > /etc/systemd/system/dumbproxy.service <<'EOF'
[Unit]
Description=Dumb Proxy
Documentation=https://github.com/SenseUnit/dumbproxy/
After=network.target network-online.target
Requires=network-online.target
[Service]
User=root
Group=root
ExecStart=/usr/local/bin/dumbproxy -config /etc/dumbproxy/dumbproxy.cfg
TimeoutStopSec=5s
PrivateTmp=true
ProtectSystem=full
LimitNOFILE=20000
[Install]
WantedBy=default.target
EOF
systemctl enable dumbproxy
# Install or update myip
#
myip_download_url="https://github.com/Snawoot/myip/releases/latest/download/myip.linux-${dp_arch_map[$arch]}"
tmp="$(mktemp)"
curl --no-progress-meter -Lo "$tmp" "$myip_download_url"
install "$tmp" /usr/local/bin/myip
rm "$tmp" || true
# External IP address discovery
#
ext_ip="$(/usr/local/bin/myip)"
# Install acme.sh
#
curl --no-progress-meter -Lo /usr/local/bin/acme.sh 'https://raw.githubusercontent.com/acmesh-official/acme.sh/refs/heads/master/acme.sh'
chmod +x /usr/local/bin/acme.sh
# Install systemd timer renewing certs
#
cat > /etc/systemd/system/acme.sh.service <<'EOF'
[Unit]
Description=Renew ACME-issued certificates using acme.sh
After=network-online.target nss-lookup.target
[Service]
Environment="NO_TIMESTAMP=1"
Type=oneshot
SyslogIdentifier=acme.sh
ExecStart=/usr/local/bin/acme.sh --cron --home "/root/.acme.sh"
EOF
cat > /etc/systemd/system/acme.sh.timer <<'EOF'
[Unit]
Description=Daily renewal of ACME-issued certificates
[Timer]
OnCalendar=daily
RandomizedDelaySec=1h
Persistent=true
[Install]
WantedBy=timers.target
EOF
systemctl daemon-reload
systemctl enable acme.sh.timer
systemctl start acme.sh.timer
# Issue certificate
#
acme.sh --issue \
-d "$ext_ip" \
--alpn \
--force \
--pre-hook "systemctl stop dumbproxy || true" \
--post-hook "[ -e /etc/dumbproxy/cert.pem -a -e /etc/dumbproxy/fullchain.pem ] && systemctl restart dumbproxy || true" \
--server letsencrypt \
--certificate-profile shortlived \
--days 3
acme.sh --install-cert \
-d "$ext_ip" \
--cert-file /etc/dumbproxy/cert.pem \
--key-file /etc/dumbproxy/key.pem \
--fullchain-file /etc/dumbproxy/fullchain.pem \
--reloadcmd "systemctl restart dumbproxy"
cat <<EOF
=========================
Installation is finished!
=========================
Proxy URL: https://auto:${passwd}@${ext_ip}:443
which is
Proxy protocol: https
Proxy port: 443
Proxy host: ${ext_ip}
Proxy user: auto
Proxy password: ${passwd}
EOF