Initial scaffold: blob store server, CLI scripts, and PWA share target

Clipboard/screenshot sync across own devices via a single DEVICE_TOKEN-gated
blob store, plus a small installable web app so a phone can push/pull
clips and share screenshots via the OS share sheet.
This commit is contained in:
Fredrik Johansson
2026-08-20 15:28:42 +02:00
commit 4eee44f675
28 changed files with 3132 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Fetches the latest `clip` blob from scrot and writes it into the local
# system clipboard.
set -euo pipefail
: "${SCROT_SERVER:?set SCROT_SERVER, e.g. https://scrot.example.com}"
: "${DEVICE_TOKEN:?set DEVICE_TOKEN}"
response=$(curl -sf -w '\n%{http_code}' "$SCROT_SERVER/api/clip/latest" \
-H "X-Device-Token: $DEVICE_TOKEN")
status="${response##*$'\n'}"
body="${response%$'\n'*}"
if [ "$status" = "204" ]; then
echo "no clip yet" >&2
exit 1
fi
if [ -n "${WAYLAND_DISPLAY:-}" ]; then
printf '%s' "$body" | wl-copy
else
printf '%s' "$body" | xclip -selection clipboard
fi
echo "clip pulled into clipboard"
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# Reads the system clipboard and pushes it to scrot as a `clip` blob.
set -euo pipefail
: "${SCROT_SERVER:?set SCROT_SERVER, e.g. https://scrot.example.com}"
: "${DEVICE_TOKEN:?set DEVICE_TOKEN}"
if [ -n "${WAYLAND_DISPLAY:-}" ]; then
content=$(wl-paste --no-newline)
else
content=$(xclip -selection clipboard -o)
fi
curl -sf -X POST "$SCROT_SERVER/api/blobs" \
-H "X-Device-Token: $DEVICE_TOKEN" \
-H "X-Blob-Kind: clip" \
-H "Content-Type: text/plain; charset=utf-8" \
--data-binary "$content" \
-o /dev/null
echo "clip pushed"
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# Prints (and, if qrencode is installed, renders as a terminal QR code) the
# onboarding link for the scrot PWA: opening it on a phone saves the device
# token (via app.js's #t= handler) and, once the app is added to the home
# screen, enables "Share to scrot" from the OS share sheet.
set -euo pipefail
: "${SCROT_SERVER:?set SCROT_SERVER, e.g. https://scrot.example.com}"
: "${DEVICE_TOKEN:?set DEVICE_TOKEN}"
url="$SCROT_SERVER/#t=$DEVICE_TOKEN"
echo "$url"
echo
if command -v qrencode >/dev/null 2>&1; then
qrencode -t ANSIUTF8 "$url"
else
echo "(install qrencode to render this as a scannable QR code in-terminal)"
fi
cat <<'EOF'
On the phone:
1. Open the link/QR above — saves the device token, this device is now onboarded.
2. Add scrot to the home screen (share/menu -> "Add to Home Screen").
3. Reopen from the home screen icon once — this re-fetches the manifest
with the token baked into the share target, enabling "Share to scrot"
from the OS share sheet (photos, browser selection, etc).
EOF
Executable
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
# Captures a region screenshot, pushes it to scrot as a `shot` blob, and
# copies the returned public link to the clipboard.
set -euo pipefail
: "${SCROT_SERVER:?set SCROT_SERVER, e.g. https://scrot.example.com}"
: "${DEVICE_TOKEN:?set DEVICE_TOKEN}"
tmpfile=$(mktemp --suffix=.png)
trap 'rm -f "$tmpfile"' EXIT
if [ -n "${WAYLAND_DISPLAY:-}" ]; then
grim -g "$(slurp)" "$tmpfile"
else
maim -s "$tmpfile"
fi
response=$(curl -sf -X POST "$SCROT_SERVER/api/blobs" \
-H "X-Device-Token: $DEVICE_TOKEN" \
-H "X-Blob-Kind: shot" \
-H "Content-Type: image/png" \
--data-binary "@$tmpfile")
url=$(printf '%s' "$response" | grep -o '"url":"[^"]*"' | cut -d'"' -f4)
full_url="$SCROT_SERVER$url"
if [ -n "${WAYLAND_DISPLAY:-}" ]; then
printf '%s' "$full_url" | wl-copy
else
printf '%s' "$full_url" | xclip -selection clipboard
fi
echo "screenshot uploaded: $full_url"