-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup-cloudflare.sh
More file actions
executable file
Β·40 lines (32 loc) Β· 1012 Bytes
/
Copy pathsetup-cloudflare.sh
File metadata and controls
executable file
Β·40 lines (32 loc) Β· 1012 Bytes
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
#!/bin/bash
echo "π Checking for cloudflared..."
# Detect OS
OS="$(uname)"
CLOUDFLARED_CMD="cloudflared"
# Check if cloudflared is installed
if ! command -v $CLOUDFLARED_CMD &> /dev/null; then
echo "π¦ Installing cloudflared globally via npm..."
npm install -g cloudflared
else
echo "β
cloudflared is already installed."
fi
# Path to cert.pem
CERT_PATH="$HOME/.cloudflared/cert.pem"
# Check if cert.pem exists
if [ ! -f "$CERT_PATH" ]; then
echo "π Cloudflare login is required."
echo "π A browser window will open for authentication..."
$CLOUDFLARED_CMD login
if [ ! -f "$CERT_PATH" ]; then
echo "β Login failed or was cancelled. Exiting..."
exit 1
fi
else
echo "π Cloudflare certificate found. Skipping login."
fi
# Prompt for port
read -p "π Enter the local port to expose (default: 5000): " PORT
PORT=${PORT:-5000}
# Start tunnel
echo "π Starting Cloudflare Tunnel for http://localhost:$PORT ..."
$CLOUDFLARED_CMD tunnel --url http://localhost:$PORT