-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathng
executable file
·82 lines (66 loc) · 2 KB
/
ng
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
#!/bin/bash
# Install/update ngrok, create a config, and launch ngrok
install_ngrok() {
curl -sSL https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null
echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | sudo tee /etc/apt/sources.list.d/ngrok.list
sudo apt update && sudo apt install -y ngrok
}
update_ngrok() {
if apt list --upgradable 2>/dev/null | grep -q "ngrok"; then
echo "Updating ngrok..."
install_ngrok
fi
}
is_config_existing() {
if [ -f ~/.config/ngrok/ngrok.yml ]; then
return 0 # true
else
return 1 # false
fi
}
is_valid_config() {
output=$(ngrok config check 2>&1)
if [[ "$output" =~ Valid[[:space:]]configuration[[:space:]]file[[:space:]]at[[:space:]].*\.config/ngrok/ngrok\.yml ]]; then
return 0 # true
else
return 1 # false
fi
}
make_template_config() {
mkdir -p ~/.config/ngrok
cat <<EOF > ~/.config/ngrok/ngrok.yml
version: "3"
agent:
authtoken: ??????
tunnels:
ngrok-tunnel:
proto: http
addr: 8080
url: ????????
EOF
}
if command -v ngrok &>/dev/null; then
update_ngrok
else
read -p "ngrok is not installed. Install now? (y/n) " answer
if [ "$answer" = "y" ] || [ "$answer" = "Y" ]; then
echo "Installing ngrok..."
install_ngrok
else
echo "Skipping ngrok installation."
exit 1
fi
fi
if ! is_config_existing; then
make_template_config
echo -e "Next, we'll add your ngrok authtoken and static url to the ngrok config. You'll find this data at:\n"
echo -e "https://dashboard.ngrok.com/get-started/setup/linux\n"
read -p "Press enter to open the config editor."
nano ~/.config/ngrok/ngrok.yml
echo -e "ngrok configuration file created.\n\n"
read -p "Okay. It appears you're all set. Press enter to launch ngrok."
elif ! is_valid_config; then
echo "ngrok configuration file is invalid. Please check the config file at ~/.config/ngrok/ngrok.yml."
exit 1
fi
ngrok start ngrok-tunnel