#!/bin/sh # vnsh pipe mode - zero-install encrypted upload from stdin # Usage: cat file.log | bash <(curl -sL vnsh.dev/pipe) # Or: some_cmd | curl -sL vnsh.dev/pipe | sh set -e HOST="${VNSH_HOST:-https://vnsh.dev}" command -v openssl >/dev/null 2>&1 || { echo "error: openssl required" >&2; exit 1; } command -v curl >/dev/null 2>&1 || { echo "error: curl required" >&2; exit 1; } KEY=$(openssl rand -hex 32) IV=$(openssl rand -hex 16) TMP=$(mktemp) ENC=$(mktemp) trap "rm -f $TMP $ENC" EXIT INT TERM if [ -t 0 ]; then echo "error: no stdin input. Usage: cat file | curl -sL vnsh.dev/pipe | bash" >&2 exit 1 fi cat > "$TMP" SIZE=$(wc -c < "$TMP" | tr -d ' ') if [ "$SIZE" -eq 0 ]; then echo "error: empty input" >&2 exit 1 fi if [ "$SIZE" -gt 26214400 ]; then echo "error: input too large ($SIZE bytes, max 25MB)" >&2 exit 1 fi openssl enc -aes-256-cbc -K "$KEY" -iv "$IV" -in "$TMP" -out "$ENC" 2>/dev/null _VN_TTL_QS="" if [ -n "${TTL:-}" ]; then _VN_TTL_QS="?ttl=$TTL"; fi RESP=$(curl -s -X POST --data-binary @"$ENC" -H "Content-Type: application/octet-stream" -H "X-Vnsh-Client: cli/2.0.0" "$HOST/api/drop$_VN_TTL_QS") ID=$(echo "$RESP" | grep -o '"id":"[^"]*"' | cut -d'"' -f4) if [ -z "$ID" ]; then echo "error: upload failed: $RESP" >&2 exit 1 fi # Build v2 URL with base64url encoded key+iv SECRET=$(printf '%s%s' "$KEY" "$IV" | xxd -r -p | base64 | tr '+/' '-_' | tr -d '=') echo "$HOST/v/$ID#$SECRET"