-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsprint.sh
More file actions
51 lines (40 loc) · 1.27 KB
/
sprint.sh
File metadata and controls
51 lines (40 loc) · 1.27 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
#!/bin/bash
# Arguments
SERVICE_NAME="$1"
NEW_TOKEN="$2"
# Paths
SRC_SERVICE="/etc/systemd/system/cloudflared.service"
DEST_SERVICE="/etc/systemd/system/${SERVICE_NAME}.service"
SRC_BINARY="/usr/local/bin/cloudflared"
DEST_BINARY="/usr/local/bin/${SERVICE_NAME}"
# Old token pattern (original token to be replaced - adjust if needed)
TOKEN_REGEX='--token [a-zA-Z0-9._-]*'
# Validate input
if [[ -z "$SERVICE_NAME" || -z "$NEW_TOKEN" ]]; then
echo "Usage: $0 <new-service-name> <new-token>"
exit 1
fi
# Check original service file exists
if [[ ! -f "$SRC_SERVICE" ]]; then
echo "❌ Original service file $SRC_SERVICE not found."
exit 1
fi
# Copy the service file
cp "$SRC_SERVICE" "$DEST_SERVICE"
echo "✅ Copied service to $DEST_SERVICE"
# Replace token with new one
sed -i "s/${TOKEN_REGEX}/--token ${NEW_TOKEN}/g" "$DEST_SERVICE"
echo "🔄 Replaced token in service file"
# Copy the binary
cp "$SRC_BINARY" "$DEST_BINARY"
chmod +x "$DEST_BINARY"
echo "✅ Copied binary to $DEST_BINARY"
# Reload systemd
systemctl daemon-reload
echo "🔁 Reloaded systemd"
# Done
echo "🎉 New service $SERVICE_NAME is ready. Use:"
echo " sudo systemctl enable $SERVICE_NAME"
sudo systemctl enable $SERVICE_NAME
echo " sudo systemctl start $SERVICE_NAME"
sudo systemctl start $SERVICE_NAME