aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md8
-rwxr-xr-xextras/estampa-ssh2
-rw-r--r--extras/estampa.sh75
3 files changed, 81 insertions, 4 deletions
diff --git a/README.md b/README.md
index 2cce13b..f5c9e26 100644
--- a/README.md
+++ b/README.md
@@ -19,14 +19,16 @@ returns 404.
## Install
-Build from source:
+On the server, you need the `estampa` binary (CGI handler + cleanup
+tool) and the `estampa-ssh` wrapper (forced command for the upload
+account). Build from source:
```sh
cargo build --release
sudo install -m 755 target/release/estampa /usr/bin/estampa
+sudo install -m 755 extras/estampa-ssh /usr/local/bin/estampa-ssh
```
-Prebuilt packages are available on [build.r.bdr.sh][build].
## Serving (nginx + fcgiwrap)
@@ -74,7 +76,7 @@ To wire that up:
```sh
sudo install -d -m 755 /srv/estampa
-sudo useradd estampa -s /usr/sbin/nologin --home /srv/http/estampa
+sudo useradd estampa -s /usr/sbin/nologin --home /srv/estampa
sudo chown estampa:estampa /srv/estampa
sudo install -d -m 700 -o estampa -g estampa /srv/estampa/.ssh
sudo -u estampa touch /srv/estampa/.ssh/authorized_keys
diff --git a/extras/estampa-ssh b/extras/estampa-ssh
index f1cbd08..4b2202f 100755
--- a/extras/estampa-ssh
+++ b/extras/estampa-ssh
@@ -2,7 +2,7 @@
# estampa-ssh: forced command for the upload account in ~/.ssh/authorized_keys.
#
# Usage in authorized_keys:
-# command="/usr/local/bin/estampa-ssh /srv/estampa/pastes",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding ssh-ed25519 AAAA... uploader
+# command="/usr/local/bin/estampa-ssh /srv/estampa",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding ssh-ed25519 AAAA... uploader
#
# On every incoming SSH session this:
# 1. prunes pastes older than one week from $1 (best-effort, never blocks),
diff --git a/extras/estampa.sh b/extras/estampa.sh
new file mode 100644
index 0000000..53a705a
--- /dev/null
+++ b/extras/estampa.sh
@@ -0,0 +1,75 @@
+# Shell helpers for estampa. Source this from your shell rc:
+#
+# export ESTAMPA_HOST=estampa@paste.example.com
+# . /path/to/extras/estampa.sh
+#
+# Optional:
+# export ESTAMPA_URL=https://paste.example.com
+# Defaults to "https://" + the host part of $ESTAMPA_HOST.
+#
+# Functions:
+# estampaup ./file.txt upload a file, print the URL.
+# estampaste file.txt upload the clipboard as <file.txt>, print the URL.
+#
+# estampaste uses wl-paste on Wayland and pbpaste on macOS.
+
+estampaup() {
+ if [ $# -ne 1 ]; then
+ printf 'usage: estampaup <file>\n' >&2
+ return 2
+ fi
+ if [ ! -f "$1" ]; then
+ printf 'estampaup: not a file: %s\n' "$1" >&2
+ return 1
+ fi
+
+ local host="${ESTAMPA_HOST:?set ESTAMPA_HOST=estampa@paste.example.com}"
+ local url="${ESTAMPA_URL:-https://${host#*@}}"
+ local name
+ name=$(basename -- "$1")
+
+ scp -q "$1" "$host:./$name" || return $?
+ printf '%s/%s\n' "$url" "$name"
+}
+
+estampaste() {
+ if [ $# -ne 1 ]; then
+ printf 'usage: estampaste <filename>\n' >&2
+ return 2
+ fi
+
+ local host="${ESTAMPA_HOST:?set ESTAMPA_HOST=estampa@paste.example.com}"
+ local url="${ESTAMPA_URL:-https://${host#*@}}"
+ local name="$1"
+
+ local clip
+ if command -v wl-paste >/dev/null 2>&1; then
+ clip=wl-paste
+ elif command -v pbpaste >/dev/null 2>&1; then
+ clip=pbpaste
+ else
+ printf 'estampaste: no clipboard tool (need wl-paste or pbpaste)\n' >&2
+ return 1
+ fi
+
+ local tmp
+ tmp=$(mktemp) || return 1
+ # >| overrides zsh/bash `noclobber`; mktemp just created the file
+ # and we intentionally want to write over it.
+ if ! $clip >|"$tmp"; then
+ rm -f "$tmp"
+ return 1
+ fi
+ if [ ! -s "$tmp" ]; then
+ printf 'estampaste: clipboard is empty\n' >&2
+ rm -f "$tmp"
+ return 1
+ fi
+
+ if ! scp -q "$tmp" "$host:./$name"; then
+ rm -f "$tmp"
+ return 1
+ fi
+ rm -f "$tmp"
+ printf '%s/%s\n' "$url" "$name"
+}