-
-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathuserdata.go
More file actions
47 lines (39 loc) · 1.5 KB
/
userdata.go
File metadata and controls
47 lines (39 loc) · 1.5 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
// Copyright (c) inlets Author(s) 2019. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package main
import "fmt"
// makeExitServerUserdata makes a user-data script in bash to setup inlets
//
// with a systemd service and the given version. If proxyProto is non-empty,
//
// the PROXY_PROTO environment variable is set in the service configuration.
func makeExitServerUserdata(authToken, version, proxyProto string) string {
return fmt.Sprintf(`#!/bin/bash
export AUTHTOKEN="%s"
export IP=$(curl -sfSL https://checkip.amazonaws.com)
export PROXY_PROTO="%s"
curl -SLsf https://github.com/inlets/inlets-pro/releases/download/%s/inlets-pro -o /tmp/inlets-pro && \
chmod +x /tmp/inlets-pro && \
mv /tmp/inlets-pro /usr/local/bin/inlets-pro
cat > /etc/systemd/system/inlets-pro.service <<EOF
[Unit]
Description=inlets TCP server
After=network.target
[Service]
Type=simple
Restart=always
RestartSec=2
StartLimitInterval=0
EnvironmentFile=/etc/default/inlets-pro
ExecStart=/usr/local/bin/inlets-pro tcp server --auto-tls --auto-tls-san="\${IP}" --token="\${AUTHTOKEN}" --proxy-protocol="\${PROXY_PROTO}"
[Install]
WantedBy=multi-user.target
EOF
echo "AUTHTOKEN=$AUTHTOKEN" >> /etc/default/inlets-pro && \
echo "IP=$IP" >> /etc/default/inlets-pro && \
echo "PROXY_PROTO=$PROXY_PROTO" >> /etc/default/inlets-pro && \
systemctl daemon-reload && \
systemctl start inlets-pro && \
systemctl enable inlets-pro
`, authToken, proxyProto, version)
}