-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtailscale-setup
More file actions
606 lines (497 loc) · 18.9 KB
/
tailscale-setup
File metadata and controls
606 lines (497 loc) · 18.9 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
#!/bin/sh
SCRIPT="$(basename $0)"
HOSTNAME=$(uci -q get system.@system[0].hostname)
HOSTNAME=$(echo "$HOSTNAME" | tr A-Z a-z)
usage() {
cat <<EOH
Tailscale installer for GL.iNet and Technicolour (firmware > 20.3.c.) devices
based on OpenWRT.
By default, it will install the latest release $(echo -e "\033[1m($LATEST)\033[0m") of the Tailscale
binaries from here: $(echo -e "\033[1;34m\033[4mhttps://pkgs.tailscale.com/stable/\033[0m")
Usage: tailscale-setup [options]
options:
-a alias The Tailscale device alias for identification in the admin portal
If not specified, the machine name defaults to: $(echo -e "\033[7;32m$HOSTNAME\033[0m")
-c Adds or removes a CRON Job to periodically upgrade Tailscale to
the next version if it is installed
-d Regress to the Previous version of Tailscale if it is installed
-i Upgrade to the Next version of Tailscale if it is installed
-r Removes Tailscale but retains the machine's identity and
authorisation status
-u Uninstalls Tailscale completely, including the machine's identity
and all its authorisations
-y Bypass confirmation prompt (answers 'y'), as the first option
-U Download the latest version of $SCRIPT from GitHub
NOTE: All options are mutually exclusive. The FIRST specified will take precedence
all others are ignored.
EOH
if [ -n "$1" ]; then
local index=$(( $1 - 1 ))
echo -e "${ORANGE}ERROR! Parameter $index is an unknown option!${NC}";
echo -e
fi
# exit
}
BOLD='\033[1m'
RED='\033[0;31m'
GREEN='\033[1;32m'
ORANGE='\033[0;33m'
BLUE='\033[0;34m'
REVERSED='\033[7m'
NC='\033[0m' # No Color
ping -c1 1.1.1.1 >/dev/null 2>&1 || { echo -e "${RED}[$SCRIPT] ERROR! No internet access. Exiting.${NC}"; exit 1; }
ALIAS="$HOSTNAME"
BYPASS="N"
REGRESS="N"
REMOVE="N"
UNINSTALL=N
ARCH=""
PARTPATH="/root"
FIRSTRUN="N"
# Get latest published version from the static tarballs
LATEST=$(curl -s https://pkgs.tailscale.com/stable/ \
| grep -o 'tailscale_[0-9.]\+_[a-zA-Z0-9]\+\.tgz' \
| sed -n 's/tailscale_\([0-9.]\+\)_[a-zA-Z0-9]\+\.tgz/\1/p' \
| grep -v '-' \
| sort -Vru \
| head -n1)
[ "/$1/" = "/-?/" -o "/$1/" = "/--help/" ] && usage
case "$(uname -m)" in
aarch64) ARCH="arm64";;
armv7l) ARCH="arm";;
mips) ARCH="mipsle";;
*) echo -e "${RED}[$SCRIPT] ERROR! Unable to handle $(uname -m) archictecture! Aborting...${NC}"; exit 2;;
esac
if [ "$ARCH" = "mipsle" ] ; then
# find microSD
echo -e "${NC}[$SCRIPT] Finding microSD... ${NC}"
DEVPATH=""
if [ -b "/dev/sda" ]; then
DEVPATH="/dev/sda"
PARTPATH="/mnt/sda1"
elif [ -b "/dev/mmcblk0" ]; then
DEVPATH="/dev/mmcblk0"
PARTPATH="/mnt/mmcblk0p1"
else
echo -e "${RED}[$SCRIPT] ERROR! Can't find microSD /dev path. Aborteding... ${NC}"
exit 2
fi
echo -e "${GREEN}[$SCRIPT] Found microSD! $DEVPATH ${NC}"
# Automount
block umount
block detect | uci import fstab
uci set fstab.@mount[-1].enabled='1'
uci commit fstab
block mount
fi
update() {
RESPONSE_CODE=$(curl -kLsI -o /dev/null -w '%{http_code}' https://raw.githubusercontent.com/UncleSam1966/tch-tailscale/master/$SCRIPT)
if [ "$RESPONSE_CODE" = 200 ];then
curl -kL -o $SCRIPT https://raw.githubusercontent.com/UncleSam1966/tch-tailscale/master/$SCRIPT
if [ $? -eq 0 ];then
chmod +x $SCRIPT
echo -e "${GREEN}[$SCRIPT] Successfully downloaded $SCRIPT.${NC}"
else
echo -e "${ORANGE}[$SCRIPT] Failed to download $SCRIPT.${NC}"
fi
elif [ "$RESPONSE_CODE" = 404 ];then
echo -e "${ORANGE}[$SCRIPT] ERROR! Not found on GitHub???${NC}"
elif [ "$RESPONSE_CODE" = 000 ];then
echo -e "${RED}ERROR! No Internet connection???${NC}"
else
echo -e "${RED}[$SCRIPT] ERROR! Unknown response code $RESPONSE_CODE${NC}"
fi
exit
}
install() {
if [ "$BYPASS" != "Y" ] ; then
echo -e
echo -e "${NC}Installs the latest release of Tailscale.${NC}"
echo -e
echo -e "${NC}If you wish to proceed, enter y otherwise just press [Enter] to stop: ${NC}"
echo -e
read -r REPLY
if [ "$REPLY" != "y" -a "$REPLY" != "Y" ]; then
# rm ./runonce
echo -e "${RED}[$SCRIPT] Installation aborted.${NC}"
echo -e
exit
fi
fi
# Check if tailscale is already installed and if so prompt to update and exit
CURRENT=""
if [ -e /usr/sbin/tailscale ] ;then
CURRENT=$(/usr/sbin/tailscale --version | head -n 1);
fi
if [ ! -z "$CURRENT" ] ; then
echo -e "${ORANGE}[$SCRIPT] Tailscale is already installed and its version is $CURRENT"
echo -e "${ORANGE}[$SCRIPT] Run $SCRIPT -i to check for a newer version and upgrade${NC}"
echo -e "${RED}[$SCRIPT] Aborting Install...${NC}"
echo -e "${ORANGE}[$SCRIPT] $(/usr/sbin/tailscale status | grep Tailscale || echo -e "${GREEN}Tailscale is running")${NC}"
exit 2
fi
# Check the latest version of Tailscale
echo -e "${NC}[$SCRIPT] Getting latest Tailscale version...${NC}"
if [ -z "$LATEST" ] ; then
echo -e "${RED}[$SCRIPT] ERROR! Could not determine latest Tailscale version. Aborting...${NC}"
exit 2
fi
echo -e "${ORANGE}[$SCRIPT] Latest Tailscale version is $LATEST${NC}"
get_tailscale $LATEST
# Create the tailscale service /etc/init.d/tailscale
echo -e "${NC}[$SCRIPT] Creating the tailscale service...${NC}"
cat <<EOF > /etc/init.d/tailscale
#!/bin/sh /etc/rc.common
USE_PROCD=1
START=95
STOP=01
start_service() {
/usr/sbin/tailscaled --cleanup
procd_open_instance
procd_set_param command /usr/sbin/tailscaled
# Set the port to listen on for incoming VPN packets.
# Remote nodes will automatically be informed about the new port number,
# but you might want to configure this in order to set external firewall
# settings.
procd_append_param command --port 41641
# OpenWRT /var is a symlink to /tmp, so write persistent state elsewhere.
procd_append_param command --state $PARTPATH/tailscale/tailscaled.state
procd_set_param respawn
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}
stop_service() {
/usr/sbin/tailscale down
/usr/sbin/tailscaled --cleanup
}
EOF
chmod +x /etc/init.d/tailscale
# Enable the tailscale service
echo -e "${NC}[$SCRIPT] Enabling Tailscale...${NC}"
/etc/init.d/tailscale enable
# Start the tailscale service
echo -e "${NC}[$SCRIPT] Starting Tailscale...${NC}"
/etc/init.d/tailscale start > /dev/null 2>&1
# Set the Devivce Alias
echo -e "${NC}[$SCRIPT] Setting the device alias to: ${GREEN}${REVERSED}$ALIAS${NC}"
# Acquire the IPv4 CIDR subnet address
SUBNET=$(ip route | grep br-lan | grep proto | sed 's/|/ /' | awk '{print $1}')
echo -e "${NC}[$SCRIPT] The device IPv4 CIDR subnet address is ${REVERSED}$SUBNET${NC}"
# Flags you need to pass to tailscale
FLAGS="up"
FLAGS=$FLAGS" --reset"
FLAGS=$FLAGS" --hostname $ALIAS"
# Extra flags you might want to pass to tailscale
FLAGS=$FLAGS" --advertise-routes=$SUBNET"
FLAGS=$FLAGS" --advertise-exit-node"
# Unused flags
# FLAGS=\$FLAGS" --netfilter-mode=off"
# FLAGS=\$FLAGS" --accept-routes"
# FLAGS=\$FLAGS"login --authkey=tskey-auth-..."
# Setup firewall zones and rules and then restart firewall at the end
echo -e "${NC}[$SCRIPT] Setting up Firewall rules for Tailscale${NC}"
# Add a new zone for tailscale
uci -q add firewall zone > /dev/null
uci -q set firewall.@zone[-1].device='tailscale0' > /dev/null
uci -q set firewall.@zone[-1].name='tailscale' > /dev/null
uci -q set firewall.@zone[-1].mtu_fix='1' > /dev/null
uci -q set firewall.@zone[-1].input='ACCEPT' > /dev/null
uci -q set firewall.@zone[-1].forward='ACCEPT' > /dev/null
uci -q set firewall.@zone[-1].masq='1' > /dev/null
uci -q set firewall.@zone[-1].output='ACCEPT' > /dev/null
uci add_list firewall.@zone[-1].network='tailscale' > /dev/null
uci add_list firewall.@zone[-1].network='tailscale0' > /dev/null
# Add new forwarding rules for tailscale
uci -q add firewall forwarding > /dev/null
uci -q set firewall.@forwarding[-1].dest='lan' > /dev/null
uci -q set firewall.@forwarding[-1].src='tailscale' > /dev/null
uci -q add firewall forwarding > /dev/null
uci -q set firewall.@forwarding[-1].dest='wan' > /dev/null
uci -q set firewall.@forwarding[-1].src='tailscale' > /dev/null
uci -q add firewall forwarding > /dev/null
uci -q set firewall.@forwarding[-1].dest='tailscale' > /dev/null
uci -q set firewall.@forwarding[-1].src='lan' > /dev/null
uci -q add firewall forwarding > /dev/null
uci -q set firewall.@forwarding[-1].dest='tailscale' > /dev/null
uci -q set firewall.@forwarding[-1].src='wan' > /dev/null
# Add a new Firewall rule for tailscale
uci -q add firewall rule > /dev/null
uci -q set firewall.@rule[-1].src='*' > /dev/null
uci -q set firewall.@rule[-1].target='ACCEPT' > /dev/null
uci -q set firewall.@rule[-1].proto='udp' > /dev/null
uci -q set firewall.@rule[-1].name='Allow-Tailscale' > /dev/null
uci -q set firewall.@rule[-1].dest_port='41641' > /dev/null
# Create a file that contains files and directories to be preserved during an upgrade.
echo -e "${NC}[$SCRIPT] Setting up Tailscale to be preserved during a firmware upgrade${NC}"
cat <<EOF > /lib/upgrade/keep.d/tailscale
/root/tailscale-setup
/usr/sbin/tailscale
/usr/sbin/tailscaled
/etc/init.d/tailscale
/etc/rc.d/*tailscale
/etc/sysctl.d/99-tailscale.conf
$PARTPATH/tailscale/
/lib/upgrade/keep.d/tailscale
EOF
echo -e "${NC}[$SCRIPT] Restarting modified services...${NC}"
uci commit
/etc/init.d/firewall reload > /dev/null 2>&1
/etc/init.d/network reload > /dev/null 2>&1
/etc/init.d/cron reload > /dev/null 2>&1
FIRSTRUN="Y"
crontoggle
cleanup
# Prompt the user to login to the following webpage to authorise the installation.
# echo "${NC}[$SCRIPT] Visit the following link to authorise this tailscale installation${NC}"
/usr/sbin/tailscale $FLAGS
exit
}
regress() {
if [ "$BYPASS" != "Y" ] ; then
echo -e
echo -e "${ORANGE}Regress the installed release of Tailscale.${NC}"
echo -e
echo -e "${NC}If you wish to proceed, enter y otherwise just press [Enter] to stop: ${NC}"
echo -e
read -r REPLY
if [ "$REPLY" != "y" -a "$REPLY" != "Y" ]; then
# rm ./runonce
echo -e "${GREEN}[$SCRIPT] Regress aborted.${NC}"
echo -e
exit
fi
fi
# check the installed version of Tailscale
echo -e "${NC}[$SCRIPT] Getting installed Tailscale version...${NC}"
CURRENT=$(/usr/sbin/tailscale --version | head -n 1)
if [ -z "$CURRENT" ] ; then
echo -e "${RED}[$SCRIPT] ERROR! Could not determine current Tailscale version. Aborting...${NC}"
exit 2
fi
echo -e "${NC}[$SCRIPT] Installed Tailscale version is $CURRENT${NC}"
# Check the previous version of Tailscale
echo -e "${NC}[$SCRIPT] Getting previous Tailscale version...${NC}"
get_previous $CURRENT
if [ -z "$PREVIOUS" ] ; then
echo -e "${RED}[$SCRIPT] ERROR! Could not determine previous Tailscale version. Aborting...${NC}"
exit 2
fi
echo -e "${NC}[$SCRIPT] Previous version of Tailscale is $PREVIOUS${NC}"
echo -e "${NC}[$SCRIPT] Stopping Tailscale version $CURRENT...${NC}"
/etc/init.d/tailscale stop > /dev/null 2>&1
get_tailscale $PREVIOUS
echo -e "${NC}[$SCRIPT] Starting Tailscale...${NC}"
/etc/init.d/tailscale start > /dev/null 2>&1
cleanup
exit
}
uninstall() {
if [ "$BYPASS" != "Y" ] ; then
if [ "$REMOVE" = "N" ] ; then
FULLREMOVAL="partially"
else
FULLREMOVAL="completely"
fi
echo -e
echo -e "${RED}Uninstalls the current release of Tailscale $FULLREMOVAL.${NC}"
echo -e
echo -e "${NC}If you wish to proceed, enter y otherwise just press [Enter] to stop: ${NC}"
echo -e
read -r REPLY
if [ "$REPLY" != "y" -a "$REPLY" != "Y" ]; then
# rm ./runonce
echo -e "${GREEN}[$SCRIPT] Uninstallation aborted.${NC}"
echo -e
exit
fi
fi
# Disable the tailscale service
echo -e "${NC}[$SCRIPT] Disabling Tailscale...${NC}"
/etc/init.d/tailscale disable
echo -e "${GREEN}[$SCRIPT] Tailscale service has been disabled${NC}"
# Stop the tailscale service
echo -e "${NC}[$SCRIPT] Stopping Tailscale...${NC}"
/etc/init.d/tailscale stop > /dev/null 2>&1
echo -e "${GREEN}[$SCRIPT] Tailscale service has stopped${NC}"
# Remove the tailscale service /etc/init.d/tailscale
echo -e "${NC}[$SCRIPT] Removing Tailscale Service...${NC}"
rm -rf /etc/init.d/tailscale
rm -rf /etc/rc.d/K01tailscaled
rm -rf /etc/rc.d/S95tailscaled
rm -rf /var/run/tailscale
echo -e "${GREEN}[$SCRIPT] Tailscale service has been removed${NC}"
# Remove the tailscale binaries /usr/sbin/tailscale & /usr/sbin/tailscaled
echo -e "${NC}[$SCRIPT] Removing Tailscale binaries...${NC}"
rm -rf /usr/sbin/tailscale
rm -rf /usr/sbin/tailscaled
rm -rf $PARTPATH/tailscale/tailscale
rm -rf $PARTPATH/tailscale/tailscaled
echo -e "${GREEN}[$SCRIPT] Tailscale binaries have been removed${NC}"
# Remove the cron job to run the tailscale update script every Saturday
echo -e "${NC}[$SCRIPT] Removing scheduled Tailscale update script...${NC}"
grep -q "$SCRIPT" /etc/crontabs/root
if [ $? = 0 ]; then
sed -e "/$SCRIPT/d" -i /etc/crontabs/root
echo -e "${NC}[$SCRIPT] Scheduled Tailscale update has been removed.${NC}"
fi
# Remove the Tailscale firewall zones and rules and then restart firewall at the end
echo -e "${NC}[$SCRIPT] Removing Tailscale firewall zones and rules...${NC}"
fw=$(uci -q show firewall | grep -m1 -E "ailscale" | cut -d. -f1-2)
while [ -n "$fw" ]; do
uci delete $fw
fw=$(uci -q show firewall | grep -m1 -E "ailscale" | cut -d. -f1-2)
done
uci commit
/etc/init.d/firewall reload > /dev/null 2>&1
echo -e "${GREEN}[$SCRIPT] Tailscale firewall zones and rules have been removed${NC}"
# Remove the tailscale ip forwarding rules script /etc/sysctl.d/99-tailscale.conf
echo -e "${NC}[$SCRIPT] Removing Tailscale IP forwarding...${NC}"
rm -rf /etc/sysctl.d/99-tailscale.conf
echo -e "${GREEN}[$SCRIPT] Tailscale IP forwarding has been removed${NC}"
# Remove the file that contains files and directories to be preserved during an upgrade
echo -e "${NC}[$SCRIPT] Removing Tailscale Keep File...${NC}"
rm -rf /lib/upgrade/keep.d/tailscale
echo -e "${GREEN}[$SCRIPT] Tailscale Keep File has been removed${NC}"
# Completely remove or retain identity files for reinstall
if [ "$REMOVE" = "Y" ] ; then
# Remove the installation files
echo -e "${NC}[$SCRIPT] Removing Tailscale installation files...${NC}"
rm -rf /root/tailscale-setup
echo -e "${GREEN}[$SCRIPT] Tailscale installation files have been removed${NC}"
# Remove the directory that contains the logs and config files
echo -e "${NC}[$SCRIPT] Removing Tailscale config files...${NC}"
rm -rf /var/lib/tailscale
rm -rf $PARTPATH/tailscale
echo -e "${GREEN}[$SCRIPT] Tailscale config files have been removed${NC}"
echo -e "${GREEN}[$SCRIPT] Tailscale has been completely uninstalled${NC}"
else
echo -e "${ORANGE}[$SCRIPT] Tailscale installation files have not been removed${NC}"
echo -e "${ORANGE}[$SCRIPT] Tailscale config files have not been removed${NC}"
echo -e "${ORANGE}[$SCRIPT] Tailscale has not been completely uninstalled${NC}"
echo -e "${ORANGE}[$SCRIPT] Tailscale can be reinstalled by running ./$SCRIPT${NC}"
fi
exit
}
upgrade() {
if [ "$BYPASS" != "Y" ] ; then
echo -e
echo -e "${ORANGE}Upgrades the installed release of Tailscale.${NC}"
echo -e
echo -e "${NC}If you wish to proceed, enter y otherwise just press [Enter] to stop: ${NC}"
echo -e
read -r REPLY
if [ "$REPLY" != "y" -a "$REPLY" != "Y" ]; then
# rm ./runonce
echo -e "${GREEN}[$SCRIPT] Upgrade aborted.${NC}"
echo -e
exit
fi
fi
# check the version of the installed Tailscale
echo -e "${NC}[$SCRIPT] Getting installed Tailscale version...${NC}"
CURRENT=$(/usr/sbin/tailscale --version | head -n 1)
[ -z "$CURRENT" ] && { echo -e "${RED}[$SCRIPT] ERROR! Could not determine current Tailscale version. Aborting...${NC}"; exit 2; }
echo -e "${NC}[$SCRIPT] Installed Tailscale version is $CURRENT${NC}"
# Check the latest version of Tailscale
echo -e "${NC}[$SCRIPT] Getting latest Tailscale version...${NC}"
[ -z "$LATEST" ] && { echo -e "${RED}[$SCRIPT] ERROR! Could not determine latest Tailscale version. Aborting...${NC}"; exit 2; }
echo -e "${NC}[$SCRIPT] Latest Tailscale version is $LATEST${NC}"
if [ $CURRENT != $LATEST ]; then
echo -e "${NC}[$SCRIPT] Stopping Tailscale version $CURRENT...${NC}"
/etc/init.d/tailscale stop > /dev/null 2>&1
get_tailscale $LATEST
echo -e "${NC}[$SCRIPT] Starting Tailscale...${NC}"
/etc/init.d/tailscale start > /dev/null 2>&1
cleanup
fi
exit
}
crontoggle() {
grep -q "$SCRIPT" /etc/crontabs/root
if [ $? = 0 ]; then
sed -e "/$SCRIPT/d" -i /etc/crontabs/root
echo -e "${NC}[$SCRIPT] Scheduled Tailscale update has been removed.${NC}"
else
mm=$(awk 'BEGIN{srand();print int(rand()*59);}')
hh=$(awk 'BEGIN{srand();print int(rand()*3)+2;}')
echo "$mm $hh * * 5 $(cd $(dirname $0); pwd)/$SCRIPT -yi" >> /etc/crontabs/root
echo -e "${NC}[$SCRIPT] Tailscale update has been scheduled to execute every Saturday at $hh:$(printf '%02d' $mm)am.${NC}"
fi
/etc/init.d/cron reload
if [ "$FIRSTRUN" = "Y" ] ; then
return
else
exit
fi
}
get_tailscale() {
FILENAME="tailscale_$1_${ARCH}.tgz"
DIRNAME="tailscale_$1_${ARCH}"
URL="https://pkgs.tailscale.com/stable/$FILENAME"
# Download the requisite version of Tailscale static binaries
cd $PARTPATH
echo -e "${NC}[$SCRIPT] Downloading $URL${NC}"
curl -kLSO "$URL"
echo -e "${NC}[$SCRIPT] Extracting $FILENAME into $PARTPATH${NC}"
tar -zxf "$FILENAME" # -C $PARTPATH
if [ ! -d "$PARTPATH/tailscale" ] ; then
mkdir "$PARTPATH/tailscale"
fi
echo -e "${NC}[$SCRIPT] Installing Tailscale version $1...${NC}"
mv "$PARTPATH/$DIRNAME/tailscale" $PARTPATH/tailscale/
mv "$PARTPATH/$DIRNAME/tailscaled" $PARTPATH/tailscale/
# create symbolic links to the binaries
echo -e "${NC}[$SCRIPT] Creating symbolic links...${NC}"
if [ ! -e /usr/sbin/tailscale ]; then
ln -s $PARTPATH/tailscale/tailscale /usr/sbin/tailscale
fi
if [ ! -e /usr/sbin/tailscaled ]; then
ln -s $PARTPATH/tailscale/tailscaled /usr/sbin/tailscaled
fi
return
}
get_previous() {
# Fetch repo tags, clean and sort descending
VERSIONS=$(curl -s "https://pkgs.tailscale.com/stable/?v=latest" \
| grep '<option' \
| sed 's/.*value="\([^"]*\)".*/\1/' \
| sort -Vru)
# Find latest or installed version in the list, then pick previous
PREVIOUS=""
FOUND=0
for version in $VERSIONS; do
if [ "$FOUND" -eq 1 ]; then
PREVIOUS=$version
break
fi
if [ "$version" = "$1" ]; then
FOUND=1
fi
done
}
cleanup() {
echo -e "${NC}[$SCRIPT] Cleaning up...${NC}"
rm -rf "$FILENAME" "$DIRNAME"
echo -e "${GREEN}[$SCRIPT] Done!${NC}"
return
}
while getopts a:cdiruyU option ; do
case $option in
a) ALIAS="${OPTARG}";;
c) crontoggle;;
d) REGRESS="Y";regress;;
i) upgrade;;
r) REMOVE="N";uninstall;;
u) REMOVE="Y";uninstall;;
U) update;;
y) BYPASS="Y";;
*) usage;;
esac
done
# Check if no options were specified
if [[ $OPTIND -eq 1 ]]; then
usage
fi
shift $((OPTIND-1))
install