-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
149 lines (139 loc) · 3.08 KB
/
run.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
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
#!/bin/bash
set -e
SYSTEM_KEY= # keys.system_admin_key
PUBLIC_ADDR= # public address in public_addr
function ion_exec() {
local args=$1
docker exec ionscale-vpn sh -c "${args}"
}
function ion_auth_exec() {
local args=$1
ion_exec "ionscale ${args} --addr $PUBLIC_ADDR --system-admin-key $SYSTEM_KEY"
}
function init() {
docker-compose up -d
echo "Waiting...."
sleep 10
echo "==================="
echo "Setup for Warp:"
docker exec ionscale-warp bash -c "cat /tailscaled-setup.log"
echo "==================="
echo "Setup for NordVPN:"
docker exec ionscale-nord bash -c "cat /tailscaled-setup.log"
echo "==================="
}
function tailnet_exec() {
local args=("$@")
local name=$2
case "$1" in
create)
ion_auth_exec "tailnets create --name $name"
;;
list)
ion_auth_exec "tailnets list"
;;
delete)
ion_auth_exec "tailnets delete ${args[*]}"
;;
*)
exit 1
;;
esac
}
function enable_exit_node_exec() {
local args=("$@")
local uid=$1
ion_auth_exec "machines enable-exit-node --machine-id $uid"
}
function auth_key_exec() {
local args=("$@")
local name=$2
local tailnet=$3
case "$1" in
create)
ion_auth_exec "auth-keys create --expiry 3600d --tag tag:$name --tailnet $tailnet"
;;
list)
echo "authen keys:"
ion_auth_exec "auth-keys list --tailnet $2"
echo "\nmachines:"
ion_auth_exec "machines list --tailnet $2"
;;
delete)
ion_auth_exec "auth-keys delete --id $name"
;;
*)
exit 1
;;
esac
}
function machine_exec() {
local args=("$@")
local machine_opt=$1
case "$machine_opt" in
get)
if [ -z "$2" ]; then
echo "$0 $machine_opt {machine-id}"
exit 1
fi
local uid=$2
ion_auth_exec "machines get --machine-id $uid"
;;
list)
local tailnetName=$2
if [ -z "$tailnetName" ]; then
echo "$0 $machine_opt {Tailnet Name}"
exit 1
fi
ion_auth_exec "machines list --tailnet $tailnetName"
;;
delete)
local id=$2
if [ -z "$id" ]; then
echo "$0 $machine_opt {machine-id}"
exit 1
fi
ion_auth_exec "machines delete --machine-id $id"
;;
*)
exit 1
;;
esac
}
case "$1" in
init)
init
;;
tailnet)
if [ -z "$2" ]; then
echo "$0 $1 {create|list|delete} name"
exit 1
fi
tailnet_exec "${@:2}"
;;
auth)
if [ -z "$2" ]; then
echo "$0 $1 {create|list|delete} name tailscale"
exit 1
fi
auth_key_exec "${@:2}"
;;
enable_exit_node)
if [ -z "$2" ]; then
echo "$0 $1 {machine-id}"
exit 1
fi
enable_exit_node_exec "${@:2}"
;;
machine)
if [ -z "$2" ]; then
echo "$0 $1 {get|list|delete} {machine-id}"
exit 1
fi
machine_exec "${@:2}"
;;
*)
echo "Usage: $0 {tailnet|auth|enable_exit_node|machine}"
exit 1
;;
esac