Astronut commited on
Commit
ae7b5c8
·
1 Parent(s): f80dd0e
Files changed (7) hide show
  1. Dockerfile +103 -0
  2. README.md +3 -3
  3. app.py +224 -0
  4. fallback.html +112 -0
  5. nginx.conf +39 -0
  6. start.sh +5 -0
  7. tailscale-install.sh +658 -0
Dockerfile ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use Ubuntu as base for better Tailscale support
2
+ FROM ubuntu:22.04
3
+
4
+ # Avoid prompts from apt
5
+ ENV DEBIAN_FRONTEND=noninteractive
6
+
7
+ USER root
8
+ # Install dependencies including SSH server and Python3
9
+ RUN apt-get update && apt-get install -y \
10
+ curl \
11
+ ca-certificates \
12
+ openssh-server \
13
+ sudo \
14
+ gnupg \
15
+ lsb-release \
16
+ nginx \
17
+ python3 \
18
+ python3-pip
19
+
20
+ COPY tailscale-install.sh /tailscale-install.sh
21
+ RUN chmod +x /tailscale-install.sh
22
+ RUN /tailscale-install.sh && rm /tailscale-install.sh
23
+
24
+ RUN apt-get clean \
25
+ && rm -rf /var/lib/apt/lists/*
26
+
27
+
28
+ # Set up a new user named "user" with user ID 1000
29
+ RUN useradd -m -u 1000 user && \
30
+ echo "user:password" | chpasswd && \
31
+ usermod -aG sudo user
32
+
33
+ # Prepare nginx directories
34
+
35
+ RUN mkdir -p /var/cache/nginx \
36
+ /var/log/nginx \
37
+ /var/lib/nginx
38
+ RUN touch /var/run/nginx.pid
39
+
40
+ RUN chown -R user:user /var/cache/nginx \
41
+ /var/log/nginx \
42
+ /var/lib/nginx \
43
+ /var/run/nginx.pid
44
+ # Create startup script
45
+ COPY start.sh /start.sh
46
+ RUN chown user:user /start.sh
47
+ RUN chmod +x /start.sh
48
+
49
+ # Copy pre-downloaded Tailscale install script
50
+ COPY tailscale-install.sh /tmp/tailscale-install.sh
51
+
52
+ # Install Tailscale from the local script
53
+ RUN chmod +x /tmp/tailscale-install.sh && /tmp/tailscale-install.sh && rm /tmp/tailscale-install.sh
54
+
55
+ # Configure SSH
56
+ RUN mkdir -p /var/run/sshd && \
57
+ sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
58
+ sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config && \
59
+ sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config
60
+
61
+ # Prepare Tailscale directories
62
+ RUN mkdir -p /var/lib/tailscale /var/run/tailscale && \
63
+ chown -R root:root /var/lib/tailscale /var/run/tailscale
64
+
65
+ # Create .ssh directory for the user
66
+ RUN mkdir -p /home/user/.ssh && \
67
+ chmod 700 /home/user/.ssh && \
68
+ chown -R user:user /home/user/
69
+
70
+ # Copy nginx configuration
71
+ COPY nginx.conf /etc/nginx/sites-available/default
72
+ RUN chown -R user:user /etc/nginx
73
+
74
+ # Copy fallback page for when backend is unavailable
75
+ COPY fallback.html /home/user/fallback.html
76
+ RUN chown user:user /home/user/fallback.html
77
+
78
+ # Copy Python process manager
79
+ COPY app.py /home/user/app/app.py
80
+ RUN chown user:user /home/user/app/app.py && chmod +x /home/user/app/app.py
81
+
82
+ # Create directories needed by SSH
83
+ RUN mkdir -p /home/user/run /home/user/.ssh/hostkeys && \
84
+ chown -R user:user /home/user/run /home/user/.ssh
85
+
86
+ # Note: We stay as root user because sshd and tailscaled require root privileges
87
+ # Supervisord will handle user switching for individual programs as needed
88
+
89
+ # Set home to the user's home directory
90
+ ENV HOME=/home/user \
91
+ PATH=/home/user/.local/bin:$PATH
92
+
93
+ # Set the working directory to the user's home directory
94
+ WORKDIR $HOME/app
95
+
96
+ # Copy the current directory contents into the container
97
+ COPY --chown=user . $HOME/app
98
+
99
+ COPY --chown=user . .
100
+
101
+ EXPOSE 7860
102
+
103
+ CMD ["bash", "start.sh"]
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: Litellm
3
- emoji: 🐢
4
- colorFrom: blue
5
- colorTo: yellow
6
  sdk: docker
7
  pinned: false
8
  ---
 
1
  ---
2
  title: Litellm
3
+ emoji: 💻
4
+ colorFrom: purple
5
+ colorTo: red
6
  sdk: docker
7
  pinned: false
8
  ---
app.py ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Simple Python-based reverse proxy with multi-process management
4
+ No supervisord needed - runs nginx and sshd as subprocesses
5
+ """
6
+ import os
7
+ import signal
8
+ import subprocess
9
+ import sys
10
+ import time
11
+ from pathlib import Path
12
+
13
+ # Track running processes
14
+ processes = []
15
+
16
+
17
+ def signal_handler(sig, frame):
18
+ """Handle shutdown signals gracefully"""
19
+ print(f"\nReceived signal {sig}, shutting down gracefully...")
20
+ for proc in processes:
21
+ try:
22
+ proc.terminate()
23
+ proc.wait(timeout=5)
24
+ except subprocess.TimeoutExpired:
25
+ proc.kill()
26
+ except Exception as e:
27
+ print(f"Error stopping process: {e}")
28
+ sys.exit(0)
29
+
30
+
31
+ def setup_ssh():
32
+ """Generate SSH host keys if they don't exist"""
33
+ key_dir = Path("/home/user/.ssh/hostkeys")
34
+ key_dir.mkdir(parents=True, exist_ok=True)
35
+
36
+ rsa_key = key_dir / "ssh_host_rsa_key"
37
+ ed_key = key_dir / "ssh_host_ed25519_key"
38
+
39
+ if not rsa_key.exists() or not ed_key.exists():
40
+ print("Generating SSH host keys...")
41
+ subprocess.run(
42
+ ["ssh-keygen", "-t", "rsa", "-b", "4096", "-f", str(rsa_key), "-N", ""],
43
+ check=True,
44
+ )
45
+ subprocess.run(
46
+ ["ssh-keygen", "-t", "ed25519", "-f", str(ed_key), "-N", ""], check=True
47
+ )
48
+ else:
49
+ print("SSH host keys already exist")
50
+
51
+ # Add SSH public key from environment if provided
52
+ ssh_public_key = os.getenv("SSH_PUBLIC_KEY")
53
+ if ssh_public_key:
54
+ print("Adding SSH public key from environment...")
55
+ ssh_dir = Path("/home/user/.ssh")
56
+ ssh_dir.mkdir(parents=True, exist_ok=True)
57
+
58
+ authorized_keys = ssh_dir / "authorized_keys"
59
+ with open(authorized_keys, "a") as f:
60
+ f.write(f"{ssh_public_key}\n")
61
+
62
+ os.chmod(ssh_dir, 0o700)
63
+ os.chmod(authorized_keys, 0o600)
64
+ subprocess.run(["chown", "-R", "user:user", str(ssh_dir)], check=True)
65
+ print("SSH public key added successfully")
66
+
67
+
68
+ def start_nginx():
69
+ """Start nginx in foreground mode"""
70
+ print("Starting nginx...")
71
+ proc = subprocess.Popen(
72
+ ["/usr/sbin/nginx", "-g", "daemon off;"],
73
+ stdout=subprocess.PIPE,
74
+ stderr=subprocess.STDOUT,
75
+ text=True,
76
+ )
77
+ processes.append(proc)
78
+ return proc
79
+
80
+
81
+ def start_sshd():
82
+ """Start sshd in non-daemon mode"""
83
+ print("Starting sshd...")
84
+ proc = subprocess.Popen(
85
+ ["/usr/sbin/sshd", "-D"],
86
+ stdout=subprocess.PIPE,
87
+ stderr=subprocess.STDOUT,
88
+ text=True,
89
+ )
90
+ processes.append(proc)
91
+ return proc
92
+
93
+
94
+ def start_tailscale():
95
+ """Start Tailscale if auth key is provided"""
96
+ auth_key = os.getenv("TAILSCALE_AUTHKEY")
97
+ if not auth_key:
98
+ print("No TAILSCALE_AUTHKEY provided, skipping Tailscale")
99
+ return None, None
100
+
101
+ print("Starting tailscaled...")
102
+ tailscaled = subprocess.Popen(
103
+ [
104
+ "/usr/sbin/tailscaled",
105
+ "--state=/var/lib/tailscale/tailscaled.state",
106
+ "--socket=/var/run/tailscale/tailscaled.sock",
107
+ "--tun=userspace-networking",
108
+ ],
109
+ stdout=subprocess.PIPE,
110
+ stderr=subprocess.STDOUT,
111
+ text=True,
112
+ )
113
+ processes.append(tailscaled)
114
+
115
+ # Wait for tailscaled to be ready
116
+ print("Waiting for tailscaled to start...")
117
+ for i in range(30):
118
+ result = subprocess.run(
119
+ ["tailscale", "status"],
120
+ stdout=subprocess.DEVNULL,
121
+ stderr=subprocess.DEVNULL,
122
+ )
123
+ if result.returncode == 0:
124
+ break
125
+ time.sleep(1)
126
+ else:
127
+ print("Warning: tailscaled did not start in time")
128
+ return tailscaled, None
129
+
130
+ # Connect to Tailscale network
131
+ print("Connecting to Tailscale network...")
132
+ tailscale_up = subprocess.Popen(
133
+ ["tailscale", "up", "--authkey", auth_key, "--accept-routes"],
134
+ stdout=subprocess.PIPE,
135
+ stderr=subprocess.STDOUT,
136
+ text=True,
137
+ )
138
+ tailscale_up.wait()
139
+ print("Tailscale connection initiated")
140
+
141
+ return tailscaled, tailscale_up
142
+
143
+
144
+ def monitor_processes():
145
+ """Monitor all processes and restart if they crash"""
146
+ restart_count = {}
147
+ max_restarts = 3
148
+ restart_window = 60 # seconds
149
+
150
+ while True:
151
+ time.sleep(5)
152
+
153
+ for i, proc in enumerate(processes[:]): # Copy list to iterate safely
154
+ if proc.poll() is not None: # Process has died
155
+ proc_name = {0: "nginx", 1: "sshd", 2: "tailscaled"}.get(
156
+ i, f"process-{i}"
157
+ )
158
+
159
+ print(
160
+ f"WARNING: {proc_name} (PID {proc.pid}) has stopped with code {proc.returncode}"
161
+ )
162
+
163
+ # Check restart limits
164
+ now = time.time()
165
+ if proc_name not in restart_count:
166
+ restart_count[proc_name] = []
167
+
168
+ # Remove old restart timestamps
169
+ restart_count[proc_name] = [
170
+ ts for ts in restart_count[proc_name] if now - ts < restart_window
171
+ ]
172
+
173
+ if len(restart_count[proc_name]) >= max_restarts:
174
+ print(f"ERROR: {proc_name} has restarted too many times, giving up")
175
+ continue
176
+
177
+ # Restart the process
178
+ print(f"Restarting {proc_name}...")
179
+ restart_count[proc_name].append(now)
180
+
181
+ if i == 0: # nginx
182
+ new_proc = start_nginx()
183
+ processes[i] = new_proc
184
+ elif i == 1: # sshd
185
+ new_proc = start_sshd()
186
+ processes[i] = new_proc
187
+ # Don't auto-restart tailscaled as it's more complex
188
+
189
+
190
+ def main():
191
+ """Main entry point"""
192
+ print("=" * 60)
193
+ print("Starting Multi-Process Service Manager")
194
+ print("=" * 60)
195
+
196
+ # Register signal handlers
197
+ signal.signal(signal.SIGTERM, signal_handler)
198
+ signal.signal(signal.SIGINT, signal_handler)
199
+
200
+ # Setup SSH
201
+ setup_ssh()
202
+
203
+ # Start Tailscale (optional)
204
+ start_tailscale()
205
+
206
+ # Start core services
207
+ start_nginx()
208
+ start_sshd()
209
+
210
+ print("\n" + "=" * 60)
211
+ print("All services started successfully!")
212
+ print("=" * 60)
213
+ print(f"Running with {len(processes)} processes")
214
+ print("Press Ctrl+C to stop\n")
215
+
216
+ # Monitor processes indefinitely
217
+ try:
218
+ monitor_processes()
219
+ except KeyboardInterrupt:
220
+ signal_handler(signal.SIGINT, None)
221
+
222
+
223
+ if __name__ == "__main__":
224
+ main()
fallback.html ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Service Unavailable</title>
7
+ <style>
8
+ * {
9
+ margin: 0;
10
+ padding: 0;
11
+ box-sizing: border-box;
12
+ }
13
+ body {
14
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
15
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
16
+ min-height: 100vh;
17
+ display: flex;
18
+ align-items: center;
19
+ justify-content: center;
20
+ padding: 20px;
21
+ }
22
+ .container {
23
+ background: white;
24
+ border-radius: 12px;
25
+ padding: 40px;
26
+ max-width: 600px;
27
+ width: 100%;
28
+ box-shadow: 0 20px 60px rgba(0,0,0,0.3);
29
+ text-align: center;
30
+ }
31
+ .icon {
32
+ font-size: 64px;
33
+ margin-bottom: 20px;
34
+ }
35
+ h1 {
36
+ color: #333;
37
+ margin-bottom: 16px;
38
+ font-size: 28px;
39
+ }
40
+ p {
41
+ color: #666;
42
+ line-height: 1.6;
43
+ margin-bottom: 12px;
44
+ }
45
+ .status {
46
+ background: #f8f9fa;
47
+ border-left: 4px solid #ffc107;
48
+ padding: 16px;
49
+ margin: 24px 0;
50
+ text-align: left;
51
+ }
52
+ .status-title {
53
+ font-weight: bold;
54
+ color: #333;
55
+ margin-bottom: 8px;
56
+ }
57
+ .code {
58
+ font-family: 'Courier New', monospace;
59
+ background: #f1f3f4;
60
+ padding: 2px 6px;
61
+ border-radius: 3px;
62
+ font-size: 14px;
63
+ }
64
+ .footer {
65
+ margin-top: 24px;
66
+ padding-top: 24px;
67
+ border-top: 1px solid #e0e0e0;
68
+ color: #999;
69
+ font-size: 14px;
70
+ }
71
+ .retry-btn {
72
+ display: inline-block;
73
+ background: #667eea;
74
+ color: white;
75
+ padding: 12px 24px;
76
+ border-radius: 6px;
77
+ text-decoration: none;
78
+ margin-top: 16px;
79
+ transition: background 0.3s;
80
+ }
81
+ .retry-btn:hover {
82
+ background: #5568d3;
83
+ }
84
+ </style>
85
+ </head>
86
+ <body>
87
+ <div class="container">
88
+ <div class="icon">⚠️</div>
89
+ <h1>Backend Service Unavailable</h1>
90
+ <p>The backend service is currently not accessible. This typically happens when:</p>
91
+
92
+ <div class="status">
93
+ <div class="status-title">Possible Causes:</div>
94
+ <ul style="margin-left: 20px; color: #666;">
95
+ <li>Tailscale VPN is not connected</li>
96
+ <li>Backend service at <span class="code">100.115.20.30:4000</span> is offline</li>
97
+ <li>Network connectivity issues</li>
98
+ </ul>
99
+ </div>
100
+
101
+ <p>This is a proxy service that forwards requests to a Tailscale-connected backend.</p>
102
+ <p>Please ensure the backend service is running and Tailscale is properly configured.</p>
103
+
104
+ <a href="/" class="retry-btn">Retry Connection</a>
105
+
106
+ <div class="footer">
107
+ SSH access may still be available if configured<br>
108
+ Contact your administrator if this issue persists
109
+ </div>
110
+ </div>
111
+ </body>
112
+ </html>
nginx.conf ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ server {
2
+ listen 7860 default_server;
3
+ listen [::]:7860 default_server;
4
+
5
+ server_name _;
6
+
7
+ # Health check endpoint for Hugging Face Spaces
8
+ location /health {
9
+ access_log off;
10
+ return 200 "healthy\n";
11
+ add_header Content-Type text/plain;
12
+ }
13
+
14
+ location / {
15
+ # Try to proxy to backend, if it fails, serve fallback page
16
+ proxy_pass http://100.115.20.30:4000;
17
+ proxy_http_version 1.1;
18
+ proxy_set_header Upgrade $http_upgrade;
19
+ proxy_set_header Connection 'upgrade';
20
+ proxy_set_header Host $host;
21
+ proxy_set_header X-Real-IP $remote_addr;
22
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
23
+ proxy_cache_bypass $http_upgrade;
24
+ proxy_read_timeout 86400;
25
+ proxy_redirect off;
26
+
27
+ # Connection timeout settings
28
+ proxy_connect_timeout 5s;
29
+
30
+ # If backend is down, serve the fallback page
31
+ error_page 502 503 504 /fallback.html;
32
+ }
33
+
34
+ # Serve the fallback page
35
+ location = /fallback.html {
36
+ root /home/user;
37
+ internal;
38
+ }
39
+ }
start.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ echo "Starting services with Python process manager..."
5
+ exec python3 /home/user/app/app.py
tailscale-install.sh ADDED
@@ -0,0 +1,658 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ # Copyright (c) Tailscale Inc & AUTHORS
3
+ # SPDX-License-Identifier: BSD-3-Clause
4
+ #
5
+ # This script detects the current operating system, and installs
6
+ # Tailscale according to that OS's conventions.
7
+
8
+ set -eu
9
+
10
+ # All the code is wrapped in a main function that gets called at the
11
+ # bottom of the file, so that a truncated partial download doesn't end
12
+ # up executing half a script.
13
+ main() {
14
+ # Step 1: detect the current linux distro, version, and packaging system.
15
+ #
16
+ # We rely on a combination of 'uname' and /etc/os-release to find
17
+ # an OS name and version, and from there work out what
18
+ # installation method we should be using.
19
+ #
20
+ # The end result of this step is that the following three
21
+ # variables are populated, if detection was successful.
22
+ OS=""
23
+ VERSION=""
24
+ PACKAGETYPE=""
25
+ APT_KEY_TYPE="" # Only for apt-based distros
26
+ APT_SYSTEMCTL_START=false # Only needs to be true for Kali
27
+ TRACK="${TRACK:-stable}"
28
+
29
+ case "$TRACK" in
30
+ stable|unstable)
31
+ ;;
32
+ *)
33
+ echo "unsupported track $TRACK"
34
+ exit 1
35
+ ;;
36
+ esac
37
+
38
+ if [ -f /etc/os-release ]; then
39
+ # /etc/os-release populates a number of shell variables. We care about the following:
40
+ # - ID: the short name of the OS (e.g. "debian", "freebsd")
41
+ # - VERSION_ID: the numeric release version for the OS, if any (e.g. "18.04")
42
+ # - VERSION_CODENAME: the codename of the OS release, if any (e.g. "buster")
43
+ # - UBUNTU_CODENAME: if it exists, use instead of VERSION_CODENAME
44
+ . /etc/os-release
45
+ case "$ID" in
46
+ ubuntu|pop|neon|zorin|tuxedo)
47
+ OS="ubuntu"
48
+ if [ "${UBUNTU_CODENAME:-}" != "" ]; then
49
+ VERSION="$UBUNTU_CODENAME"
50
+ else
51
+ VERSION="$VERSION_CODENAME"
52
+ fi
53
+ PACKAGETYPE="apt"
54
+ # Third-party keyrings became the preferred method of
55
+ # installation in Ubuntu 20.04.
56
+ if expr "$VERSION_ID" : "2.*" >/dev/null; then
57
+ APT_KEY_TYPE="keyring"
58
+ else
59
+ APT_KEY_TYPE="legacy"
60
+ fi
61
+ ;;
62
+ debian)
63
+ OS="$ID"
64
+ VERSION="$VERSION_CODENAME"
65
+ PACKAGETYPE="apt"
66
+ # Third-party keyrings became the preferred method of
67
+ # installation in Debian 11 (Bullseye).
68
+ if [ -z "${VERSION_ID:-}" ]; then
69
+ # rolling release. If you haven't kept current, that's on you.
70
+ APT_KEY_TYPE="keyring"
71
+ # Parrot Security is a special case that uses ID=debian
72
+ elif [ "$NAME" = "Parrot Security" ]; then
73
+ # All versions new enough to have this behaviour prefer keyring
74
+ # and their VERSION_ID is not consistent with Debian.
75
+ APT_KEY_TYPE="keyring"
76
+ # They don't specify the Debian version they're based off in os-release
77
+ # but Parrot 6 is based on Debian 12 Bookworm.
78
+ VERSION=bookworm
79
+ elif [ "$VERSION_ID" -lt 11 ]; then
80
+ APT_KEY_TYPE="legacy"
81
+ else
82
+ APT_KEY_TYPE="keyring"
83
+ fi
84
+ ;;
85
+ linuxmint)
86
+ if [ "${UBUNTU_CODENAME:-}" != "" ]; then
87
+ OS="ubuntu"
88
+ VERSION="$UBUNTU_CODENAME"
89
+ elif [ "${DEBIAN_CODENAME:-}" != "" ]; then
90
+ OS="debian"
91
+ VERSION="$DEBIAN_CODENAME"
92
+ else
93
+ OS="ubuntu"
94
+ VERSION="$VERSION_CODENAME"
95
+ fi
96
+ PACKAGETYPE="apt"
97
+ if [ "$VERSION_ID" -lt 5 ]; then
98
+ APT_KEY_TYPE="legacy"
99
+ else
100
+ APT_KEY_TYPE="keyring"
101
+ fi
102
+ ;;
103
+ elementary)
104
+ OS="ubuntu"
105
+ VERSION="$UBUNTU_CODENAME"
106
+ PACKAGETYPE="apt"
107
+ if [ "$VERSION_ID" -lt 6 ]; then
108
+ APT_KEY_TYPE="legacy"
109
+ else
110
+ APT_KEY_TYPE="keyring"
111
+ fi
112
+ ;;
113
+ industrial-os)
114
+ OS="debian"
115
+ PACKAGETYPE="apt"
116
+ if [ "$(printf %.1s "$VERSION_ID")" -lt 5 ]; then
117
+ VERSION="buster"
118
+ APT_KEY_TYPE="legacy"
119
+ else
120
+ VERSION="bullseye"
121
+ APT_KEY_TYPE="keyring"
122
+ fi
123
+ ;;
124
+ parrot|mendel)
125
+ OS="debian"
126
+ PACKAGETYPE="apt"
127
+ if [ "$VERSION_ID" -lt 5 ]; then
128
+ VERSION="buster"
129
+ APT_KEY_TYPE="legacy"
130
+ else
131
+ VERSION="bullseye"
132
+ APT_KEY_TYPE="keyring"
133
+ fi
134
+ ;;
135
+ galliumos)
136
+ OS="ubuntu"
137
+ PACKAGETYPE="apt"
138
+ VERSION="bionic"
139
+ APT_KEY_TYPE="legacy"
140
+ ;;
141
+ pureos|kaisen)
142
+ OS="debian"
143
+ PACKAGETYPE="apt"
144
+ VERSION="bullseye"
145
+ APT_KEY_TYPE="keyring"
146
+ ;;
147
+ raspbian)
148
+ OS="$ID"
149
+ VERSION="$VERSION_CODENAME"
150
+ PACKAGETYPE="apt"
151
+ # Third-party keyrings became the preferred method of
152
+ # installation in Raspbian 11 (Bullseye).
153
+ if [ "$VERSION_ID" -lt 11 ]; then
154
+ APT_KEY_TYPE="legacy"
155
+ else
156
+ APT_KEY_TYPE="keyring"
157
+ fi
158
+ ;;
159
+ kali)
160
+ OS="debian"
161
+ PACKAGETYPE="apt"
162
+ YEAR="$(echo "$VERSION_ID" | cut -f1 -d.)"
163
+ APT_SYSTEMCTL_START=true
164
+ # Third-party keyrings became the preferred method of
165
+ # installation in Debian 11 (Bullseye), which Kali switched
166
+ # to in roughly 2021.x releases
167
+ if [ "$YEAR" -lt 2021 ]; then
168
+ # Kali VERSION_ID is "kali-rolling", which isn't distinguishing
169
+ VERSION="buster"
170
+ APT_KEY_TYPE="legacy"
171
+ else
172
+ VERSION="bullseye"
173
+ APT_KEY_TYPE="keyring"
174
+ fi
175
+ ;;
176
+ Deepin|deepin) # https://github.com/tailscale/tailscale/issues/7862
177
+ OS="debian"
178
+ PACKAGETYPE="apt"
179
+ if [ "$VERSION_ID" -lt 20 ]; then
180
+ APT_KEY_TYPE="legacy"
181
+ VERSION="buster"
182
+ else
183
+ APT_KEY_TYPE="keyring"
184
+ VERSION="bullseye"
185
+ fi
186
+ ;;
187
+ pika)
188
+ PACKAGETYPE="apt"
189
+ # All versions of PikaOS are new enough to prefer keyring
190
+ APT_KEY_TYPE="keyring"
191
+ # Older versions of PikaOS are based on Ubuntu rather than Debian
192
+ if [ "$VERSION_ID" -lt 4 ]; then
193
+ OS="ubuntu"
194
+ VERSION="$UBUNTU_CODENAME"
195
+ else
196
+ OS="debian"
197
+ VERSION="$DEBIAN_CODENAME"
198
+ fi
199
+ ;;
200
+ sparky)
201
+ OS="debian"
202
+ PACKAGETYPE="apt"
203
+ VERSION="$DEBIAN_CODENAME"
204
+ APT_KEY_TYPE="keyring"
205
+ ;;
206
+ centos)
207
+ OS="$ID"
208
+ VERSION="$VERSION_ID"
209
+ PACKAGETYPE="dnf"
210
+ if [ "$VERSION" = "7" ]; then
211
+ PACKAGETYPE="yum"
212
+ fi
213
+ ;;
214
+ ol)
215
+ OS="oracle"
216
+ VERSION="$(echo "$VERSION_ID" | cut -f1 -d.)"
217
+ PACKAGETYPE="dnf"
218
+ if [ "$VERSION" = "7" ]; then
219
+ PACKAGETYPE="yum"
220
+ fi
221
+ ;;
222
+ rhel|miraclelinux)
223
+ OS="$ID"
224
+ if [ "$ID" = "miraclelinux" ]; then
225
+ OS="rhel"
226
+ fi
227
+ VERSION="$(echo "$VERSION_ID" | cut -f1 -d.)"
228
+ PACKAGETYPE="dnf"
229
+ if [ "$VERSION" = "7" ]; then
230
+ PACKAGETYPE="yum"
231
+ fi
232
+ ;;
233
+ fedora)
234
+ OS="$ID"
235
+ VERSION=""
236
+ PACKAGETYPE="dnf"
237
+ ;;
238
+ rocky|almalinux|nobara|openmandriva|sangoma|risios|cloudlinux|alinux|fedora-asahi-remix)
239
+ OS="fedora"
240
+ VERSION=""
241
+ PACKAGETYPE="dnf"
242
+ ;;
243
+ amzn)
244
+ OS="amazon-linux"
245
+ VERSION="$VERSION_ID"
246
+ PACKAGETYPE="yum"
247
+ ;;
248
+ xenenterprise)
249
+ OS="centos"
250
+ VERSION="$(echo "$VERSION_ID" | cut -f1 -d.)"
251
+ PACKAGETYPE="yum"
252
+ ;;
253
+ opensuse-leap|sles)
254
+ OS="opensuse"
255
+ VERSION="leap/$VERSION_ID"
256
+ PACKAGETYPE="zypper"
257
+ ;;
258
+ opensuse-tumbleweed)
259
+ OS="opensuse"
260
+ VERSION="tumbleweed"
261
+ PACKAGETYPE="zypper"
262
+ ;;
263
+ sle-micro-rancher)
264
+ OS="opensuse"
265
+ VERSION="leap/15.4"
266
+ PACKAGETYPE="zypper"
267
+ ;;
268
+ arch|archarm|endeavouros|blendos|garuda|archcraft|cachyos)
269
+ OS="arch"
270
+ VERSION="" # rolling release
271
+ PACKAGETYPE="pacman"
272
+ ;;
273
+ manjaro|manjaro-arm|biglinux)
274
+ OS="manjaro"
275
+ VERSION="" # rolling release
276
+ PACKAGETYPE="pacman"
277
+ ;;
278
+ alpine)
279
+ OS="$ID"
280
+ VERSION="$VERSION_ID"
281
+ PACKAGETYPE="apk"
282
+ ;;
283
+ postmarketos)
284
+ OS="alpine"
285
+ VERSION="$VERSION_ID"
286
+ PACKAGETYPE="apk"
287
+ ;;
288
+ nixos)
289
+ echo "Please add Tailscale to your NixOS configuration directly:"
290
+ echo
291
+ echo "services.tailscale.enable = true;"
292
+ exit 1
293
+ ;;
294
+ bazzite)
295
+ echo "Bazzite comes with Tailscale installed by default."
296
+ echo "Please enable Tailscale by running the following commands as root:"
297
+ echo
298
+ echo "ujust enable-tailscale"
299
+ echo "tailscale up"
300
+ exit 1
301
+ ;;
302
+ void)
303
+ OS="$ID"
304
+ VERSION="" # rolling release
305
+ PACKAGETYPE="xbps"
306
+ ;;
307
+ gentoo)
308
+ OS="$ID"
309
+ VERSION="" # rolling release
310
+ PACKAGETYPE="emerge"
311
+ ;;
312
+ freebsd)
313
+ OS="$ID"
314
+ VERSION="$(echo "$VERSION_ID" | cut -f1 -d.)"
315
+ PACKAGETYPE="pkg"
316
+ ;;
317
+ osmc)
318
+ OS="debian"
319
+ PACKAGETYPE="apt"
320
+ VERSION="bullseye"
321
+ APT_KEY_TYPE="keyring"
322
+ ;;
323
+ photon)
324
+ OS="photon"
325
+ VERSION="$(echo "$VERSION_ID" | cut -f1 -d.)"
326
+ PACKAGETYPE="tdnf"
327
+ ;;
328
+
329
+ # TODO: wsl?
330
+ # TODO: synology? qnap?
331
+ esac
332
+ fi
333
+
334
+ # If we failed to detect something through os-release, consult
335
+ # uname and try to infer things from that.
336
+ if [ -z "$OS" ]; then
337
+ if type uname >/dev/null 2>&1; then
338
+ case "$(uname)" in
339
+ FreeBSD)
340
+ # FreeBSD before 12.2 doesn't have
341
+ # /etc/os-release, so we wouldn't have found it in
342
+ # the os-release probing above.
343
+ OS="freebsd"
344
+ VERSION="$(freebsd-version | cut -f1 -d.)"
345
+ PACKAGETYPE="pkg"
346
+ ;;
347
+ OpenBSD)
348
+ OS="openbsd"
349
+ VERSION="$(uname -r)"
350
+ PACKAGETYPE=""
351
+ ;;
352
+ Darwin)
353
+ OS="macos"
354
+ VERSION="$(sw_vers -productVersion | cut -f1-2 -d.)"
355
+ PACKAGETYPE="appstore"
356
+ ;;
357
+ Linux)
358
+ OS="other-linux"
359
+ VERSION=""
360
+ PACKAGETYPE=""
361
+ ;;
362
+ esac
363
+ fi
364
+ fi
365
+
366
+ # Ideally we want to use curl, but on some installs we
367
+ # only have wget. Detect and use what's available.
368
+ CURL=
369
+ if type curl >/dev/null; then
370
+ CURL="curl -fsSL"
371
+ elif type wget >/dev/null; then
372
+ CURL="wget -q -O-"
373
+ fi
374
+ if [ -z "$CURL" ]; then
375
+ echo "The installer needs either curl or wget to download files."
376
+ echo "Please install either curl or wget to proceed."
377
+ exit 1
378
+ fi
379
+
380
+ TEST_URL="https://pkgs.tailscale.com/"
381
+ RC=0
382
+ TEST_OUT=$($CURL "$TEST_URL" 2>&1) || RC=$?
383
+ if [ $RC != 0 ]; then
384
+ echo "The installer cannot reach $TEST_URL"
385
+ echo "Please make sure that your machine has internet access."
386
+ echo "Test output:"
387
+ echo $TEST_OUT
388
+ exit 1
389
+ fi
390
+
391
+ # Step 2: having detected an OS we support, is it one of the
392
+ # versions we support?
393
+ OS_UNSUPPORTED=
394
+ case "$OS" in
395
+ ubuntu|debian|raspbian|centos|oracle|rhel|amazon-linux|opensuse|photon)
396
+ # Check with the package server whether a given version is supported.
397
+ URL="https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/installer-supported"
398
+ $CURL "$URL" 2> /dev/null | grep -q OK || OS_UNSUPPORTED=1
399
+ ;;
400
+ fedora)
401
+ # All versions supported, no version checking required.
402
+ ;;
403
+ arch)
404
+ # Rolling release, no version checking needed.
405
+ ;;
406
+ manjaro)
407
+ # Rolling release, no version checking needed.
408
+ ;;
409
+ alpine)
410
+ # All versions supported, no version checking needed.
411
+ # TODO: is that true? When was tailscale packaged?
412
+ ;;
413
+ void)
414
+ # Rolling release, no version checking needed.
415
+ ;;
416
+ gentoo)
417
+ # Rolling release, no version checking needed.
418
+ ;;
419
+ freebsd)
420
+ if [ "$VERSION" != "12" ] && \
421
+ [ "$VERSION" != "13" ] && \
422
+ [ "$VERSION" != "14" ] && \
423
+ [ "$VERSION" != "15" ]
424
+ then
425
+ OS_UNSUPPORTED=1
426
+ fi
427
+ ;;
428
+ openbsd)
429
+ OS_UNSUPPORTED=1
430
+ ;;
431
+ macos)
432
+ # We delegate macOS installation to the app store, it will
433
+ # perform version checks for us.
434
+ ;;
435
+ other-linux)
436
+ OS_UNSUPPORTED=1
437
+ ;;
438
+ *)
439
+ OS_UNSUPPORTED=1
440
+ ;;
441
+ esac
442
+ if [ "$OS_UNSUPPORTED" = "1" ]; then
443
+ case "$OS" in
444
+ other-linux)
445
+ echo "Couldn't determine what kind of Linux is running."
446
+ echo "You could try the static binaries at:"
447
+ echo "https://pkgs.tailscale.com/$TRACK/#static"
448
+ ;;
449
+ "")
450
+ echo "Couldn't determine what operating system you're running."
451
+ ;;
452
+ *)
453
+ echo "$OS $VERSION isn't supported by this script yet."
454
+ ;;
455
+ esac
456
+ echo
457
+ echo "If you'd like us to support your system better, please email support@tailscale.com"
458
+ echo "and tell us what OS you're running."
459
+ echo
460
+ echo "Please include the following information we gathered from your system:"
461
+ echo
462
+ echo "OS=$OS"
463
+ echo "VERSION=$VERSION"
464
+ echo "PACKAGETYPE=$PACKAGETYPE"
465
+ if type uname >/dev/null 2>&1; then
466
+ echo "UNAME=$(uname -a)"
467
+ else
468
+ echo "UNAME="
469
+ fi
470
+ echo
471
+ if [ -f /etc/os-release ]; then
472
+ cat /etc/os-release
473
+ else
474
+ echo "No /etc/os-release"
475
+ fi
476
+ exit 1
477
+ fi
478
+
479
+ # Step 3: work out if we can run privileged commands, and if so,
480
+ # how.
481
+ CAN_ROOT=
482
+ SUDO=
483
+ if [ "$(id -u)" = 0 ]; then
484
+ CAN_ROOT=1
485
+ SUDO=""
486
+ elif type sudo >/dev/null; then
487
+ CAN_ROOT=1
488
+ SUDO="sudo"
489
+ elif type doas >/dev/null; then
490
+ CAN_ROOT=1
491
+ SUDO="doas"
492
+ fi
493
+ if [ "$CAN_ROOT" != "1" ]; then
494
+ echo "This installer needs to run commands as root."
495
+ echo "We tried looking for 'sudo' and 'doas', but couldn't find them."
496
+ echo "Either re-run this script as root, or set up sudo/doas."
497
+ exit 1
498
+ fi
499
+
500
+
501
+ # Step 4: run the installation.
502
+ OSVERSION="$OS"
503
+ [ "$VERSION" != "" ] && OSVERSION="$OSVERSION $VERSION"
504
+ echo "Installing Tailscale for $OSVERSION, using method $PACKAGETYPE"
505
+ case "$PACKAGETYPE" in
506
+ apt)
507
+ export DEBIAN_FRONTEND=noninteractive
508
+ if [ "$APT_KEY_TYPE" = "legacy" ] && ! type gpg >/dev/null; then
509
+ $SUDO apt-get update
510
+ $SUDO apt-get install -y gnupg
511
+ fi
512
+
513
+ set -x
514
+ $SUDO mkdir -p --mode=0755 /usr/share/keyrings
515
+ case "$APT_KEY_TYPE" in
516
+ legacy)
517
+ $CURL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION.asc" | $SUDO apt-key add -
518
+ $CURL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION.list" | $SUDO tee /etc/apt/sources.list.d/tailscale.list
519
+ $SUDO chmod 0644 /etc/apt/sources.list.d/tailscale.list
520
+ ;;
521
+ keyring)
522
+ $CURL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION.noarmor.gpg" | $SUDO tee /usr/share/keyrings/tailscale-archive-keyring.gpg >/dev/null
523
+ $SUDO chmod 0644 /usr/share/keyrings/tailscale-archive-keyring.gpg
524
+ $CURL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION.tailscale-keyring.list" | $SUDO tee /etc/apt/sources.list.d/tailscale.list
525
+ $SUDO chmod 0644 /etc/apt/sources.list.d/tailscale.list
526
+ ;;
527
+ esac
528
+ $SUDO apt-get update
529
+ $SUDO apt-get install -y tailscale tailscale-archive-keyring
530
+ if [ "$APT_SYSTEMCTL_START" = "true" ]; then
531
+ $SUDO systemctl enable --now tailscaled
532
+ $SUDO systemctl start tailscaled
533
+ fi
534
+ set +x
535
+ ;;
536
+ yum)
537
+ set -x
538
+ $SUDO yum install yum-utils -y
539
+ $SUDO yum-config-manager -y --add-repo "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/tailscale.repo"
540
+ $SUDO yum install tailscale -y
541
+ $SUDO systemctl enable --now tailscaled
542
+ set +x
543
+ ;;
544
+ dnf)
545
+ # DNF 5 has a different argument format; determine which one we have.
546
+ DNF_VERSION="3"
547
+ if LANG=C.UTF-8 dnf --version | grep -q '^dnf5 version'; then
548
+ DNF_VERSION="5"
549
+ fi
550
+
551
+ # The 'config-manager' plugin wasn't implemented when
552
+ # DNF5 was released; detect that and use the old
553
+ # version if necessary.
554
+ if [ "$DNF_VERSION" = "5" ]; then
555
+ set -x
556
+ $SUDO dnf install -y 'dnf-command(config-manager)' && DNF_HAVE_CONFIG_MANAGER=1 || DNF_HAVE_CONFIG_MANAGER=0
557
+ set +x
558
+
559
+ if [ "$DNF_HAVE_CONFIG_MANAGER" != "1" ]; then
560
+ if type dnf-3 >/dev/null; then
561
+ DNF_VERSION="3"
562
+ else
563
+ echo "dnf 5 detected, but 'dnf-command(config-manager)' not available and dnf-3 not found"
564
+ exit 1
565
+ fi
566
+ fi
567
+ fi
568
+
569
+ set -x
570
+ if [ "$DNF_VERSION" = "3" ]; then
571
+ $SUDO dnf install -y 'dnf-command(config-manager)'
572
+ $SUDO dnf config-manager --add-repo "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/tailscale.repo"
573
+ elif [ "$DNF_VERSION" = "5" ]; then
574
+ # Already installed config-manager, above.
575
+ $SUDO dnf config-manager addrepo --from-repofile="https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/tailscale.repo"
576
+ else
577
+ echo "unexpected: unknown dnf version $DNF_VERSION"
578
+ exit 1
579
+ fi
580
+ $SUDO dnf install -y tailscale
581
+ $SUDO systemctl enable --now tailscaled
582
+ set +x
583
+ ;;
584
+ tdnf)
585
+ set -x
586
+ curl -fsSL "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/tailscale.repo" > /etc/yum.repos.d/tailscale.repo
587
+ $SUDO tdnf install -y tailscale
588
+ $SUDO systemctl enable --now tailscaled
589
+ set +x
590
+ ;;
591
+ zypper)
592
+ set -x
593
+ $SUDO rpm --import "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/repo.gpg"
594
+ $SUDO zypper --non-interactive ar -g -r "https://pkgs.tailscale.com/$TRACK/$OS/$VERSION/tailscale.repo"
595
+ $SUDO zypper --non-interactive --gpg-auto-import-keys refresh
596
+ $SUDO zypper --non-interactive install tailscale
597
+ $SUDO systemctl enable --now tailscaled
598
+ set +x
599
+ ;;
600
+ pacman)
601
+ set -x
602
+ $SUDO pacman -S tailscale --noconfirm
603
+ $SUDO systemctl enable --now tailscaled
604
+ set +x
605
+ ;;
606
+ pkg)
607
+ set -x
608
+ $SUDO pkg install --yes tailscale
609
+ $SUDO service tailscaled enable
610
+ $SUDO service tailscaled start
611
+ set +x
612
+ ;;
613
+ apk)
614
+ set -x
615
+ if ! grep -Eq '^http.*/community$' /etc/apk/repositories; then
616
+ if type setup-apkrepos >/dev/null; then
617
+ $SUDO setup-apkrepos -c -1
618
+ else
619
+ echo "installing tailscale requires the community repo to be enabled in /etc/apk/repositories"
620
+ exit 1
621
+ fi
622
+ fi
623
+ $SUDO apk add tailscale
624
+ $SUDO rc-update add tailscale
625
+ $SUDO rc-service tailscale start
626
+ set +x
627
+ ;;
628
+ xbps)
629
+ set -x
630
+ $SUDO xbps-install tailscale -y
631
+ set +x
632
+ ;;
633
+ emerge)
634
+ set -x
635
+ $SUDO emerge --ask=n net-vpn/tailscale
636
+ set +x
637
+ ;;
638
+ appstore)
639
+ set -x
640
+ open "https://apps.apple.com/us/app/tailscale/id1475387142"
641
+ set +x
642
+ ;;
643
+ *)
644
+ echo "unexpected: unknown package type $PACKAGETYPE"
645
+ exit 1
646
+ ;;
647
+ esac
648
+
649
+ echo "Installation complete! Log in to start using Tailscale by running:"
650
+ echo
651
+ if [ -z "$SUDO" ]; then
652
+ echo "tailscale up"
653
+ else
654
+ echo "$SUDO tailscale up"
655
+ fi
656
+ }
657
+
658
+ main