-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserve-certs.sh
More file actions
executable file
Β·60 lines (49 loc) Β· 1.6 KB
/
serve-certs.sh
File metadata and controls
executable file
Β·60 lines (49 loc) Β· 1.6 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
#!/bin/bash
# ============================================
# Temporary HTTP Server for Sharing Cert Files
# --------------------------------------------
# - Serves ./certs_output over HTTP
# - Shows a QR code for easy LAN access
# - Automatically stops after X minutes
#
# Requirements:
# - Python 3 (for http.server)
# - qrencode (optional, for QR display)
# ============================================
# === CONFIG ===
EXPIRE_MINUTES=5 # How long to keep the server up
PORT=8080
SERVE_DIR="certs_output"
# === GET LOCAL IP ===
LOCAL_IP=$(ip -4 addr show eth0 | grep -Po 'inet \K[\d.]+')
if [[ -z "$LOCAL_IP" ]]; then
echo "β Could not determine local IP. Check interface name in the script."
exit 1
fi
# === CHECK FOLDER EXISTS ===
if [ ! -d "$SERVE_DIR" ]; then
echo "β Error: '$SERVE_DIR' folder not found."
exit 1
fi
cd "$SERVE_DIR"
# === SHOW URL & QR CODE ===
URL="http://$LOCAL_IP:$PORT"
echo "π Serving files at: $URL"
echo ""
if command -v qrencode > /dev/null; then
echo "π± Scan this QR code to access from another device:"
qrencode -t ansiutf8 "$URL"
else
echo "β οΈ qrencode not found. Install it with: sudo apt install qrencode"
fi
# === START SERVER WITH AUTO-EXPIRATION ===
echo ""
echo "β³ This server will automatically stop in $EXPIRE_MINUTES minute(s)..."
echo "π Press Ctrl+C to stop the server when done."
# Start the server in the background
python3 -m http.server "$PORT" > /dev/null 2>&1 &
SERVER_PID=$!
# Sleep for configured time then stop the server
sleep "${EXPIRE_MINUTES}m"
kill "$SERVER_PID" 2>/dev/null
echo "π Server stopped after $EXPIRE_MINUTES minute(s)."