#!/bin/sh # cat "${@:--}" | # curl -qFfile=@- https://envs.sh 2>/dev/null | # tee /dev/stderr | # pbcopy REMOTE_HOST='acdw@tilde.town' REMOTE_HOME='~/public_html/junk' REMOTE_HTTP='https://tilde.town/~acdw/junk' FILE="$1" if test -z "$FILE" then echo >&2 "Usage: ./upload.sh FILE"; exit 1 fi SANSDIR="${FILE##*/}" BASENAME="${SANSDIR%%.*}" EXTENSION="${SANSDIR#*.}" textp() { case "$(file --brief --mime "$1")" in (text/*) return 0 ;; (*) return 1 ;; esac } if textp "$FILE" then EXTENSION="$EXTENSION${EXTENSION:+.}txt" # for easy web viewing fi hash() { if command -v md5 >/dev/null 2>&1 then md5 -q "$1" elif command -v md5sum >/dev/null 2>&1 then md5sum "$1" | awk '{print $1}' fi } copy() { if command -v pbcopy >/dev/null 2>&1 then pbcopy fi } LINKNAME="$(hash "$FILE")${EXTENSION:+.}$EXTENSION" if rsync -z "$FILE" "$REMOTE_HOST:$REMOTE_HOME/$LINKNAME" then echo >&2 chmod 644 ... ssh "$REMOTE_HOST" chmod 644 "$REMOTE_HOME/$LINKNAME" echo >&2 "$REMOTE_HTTP/$LINKNAME" echo "$REMOTE_HTTP/$LINKNAME" | copy fi