-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathpreview.sh
More file actions
executable file
·60 lines (51 loc) · 1.34 KB
/
Copy pathpreview.sh
File metadata and controls
executable file
·60 lines (51 loc) · 1.34 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/sh
# Quick preview of the Merecat default landing page.
# Starts a local merecat instance serving www/ and opens a browser.
#
# Usage: ./preview.sh [PORT]
PORT=${1:-8080}
TOPDIR=$(cd "$(dirname "$0")" && pwd)
WEBROOT="$TOPDIR/www"
MERECAT="$TOPDIR/src/merecat"
if [ ! -x "$MERECAT" ]; then
echo "error: merecat binary not found at $MERECAT"
echo " run 'make' first"
exit 1
fi
# Pick a browser to open
for browser in xdg-open open firefox chromium-browser chromium google-chrome; do
if command -v $browser >/dev/null 2>&1; then
BROWSER=$browser
break
fi
done
CONF=$(mktemp /tmp/merecat-preview.XXXXXX.conf)
cat > "$CONF" << EOF
server default {
port = $PORT
}
EOF
cleanup() {
echo ""
echo "Stopping merecat (pid $PID) ..."
kill "$PID" 2>/dev/null
wait "$PID" 2>/dev/null
rm -f "$CONF"
}
trap cleanup INT TERM EXIT
echo "Starting merecat on http://localhost:$PORT ..."
"$MERECAT" -n -l warning -f "$CONF" "$WEBROOT" &
PID=$!
sleep 0.3
if ! kill -0 "$PID" 2>/dev/null; then
echo "error: merecat failed to start (port $PORT in use?)"
exit 1
fi
if [ -n "$BROWSER" ]; then
echo "Opening browser ($BROWSER) ..."
$BROWSER "http://localhost:$PORT/" 2>/dev/null &
else
echo "No browser found — open http://localhost:$PORT/ manually"
fi
echo "Press Ctrl-C to stop."
wait "$PID"