logo

sshpaste

Simple paste script to a server having SSH+HTTP daemons
commit: 057dec5f0fa67704b06be59241b9e38d2095bf18
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 29 Apr 2018 10:28:12 +0200

Initial Commit

Diffstat:

ALICENSE13+++++++++++++
AREADME5+++++
Asshpaste86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 104 insertions(+), 0 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,13 @@ +Copyright (c) 2018, Haelwenn (lanodan) Monnier <contact@hacktivis.me> + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/README b/README @@ -0,0 +1,5 @@ +# sshpaste + +A small shell script inspired by wgetpaste but for pushing to your own server. + +Please modify target_ssh and target_www to the appropriate servers and paths. diff --git a/sshpaste b/sshpaste @@ -0,0 +1,86 @@ +#!/bin/sh +# Copyright 2018 Haelwenn (lanodan) Monnier <contact@hacktivis.me> +# Distributed under the terms of the ISC license + +datetime="$(date -u +%FT%T)" +target_ssh="cloudsdale.hacktivis.me:pastes/${datetime}" +target_www="https://cloudsdale.hacktivis.me/pastes/${datetime}" + +die() { + if [[ -z "$*" ]] + then echo "${*}, exiting…" + else echo "Failed, exiting…" + fi + + exit +} + +sshpaste_file() { + test $(wc -c < "$1") -gt 1 || die "$1 is empty" + target_name=$(basename "$1") + chmod +r "$1" + if scp "$1" "${target_ssh}-${target_name}" + then echo "Uploaded at: ${target_www}-${target_name}" + else die "Failed uploading $1" + fi +} + +sshpaste_xclip() { + temporary_file="$(mktemp /tmp/sshpaste_xclip.XXXXX.raw)" + xclip -o > "${temporary_file}" || die "xclip output" + sshpaste_file "${temporary_file}" + rm -f "${temporary_file}" +} + +sshpaste_command() { + temporary_file="$(mktemp /tmp/sshpaste_command.XXXXX.log)" + sh -x -c "$*" > "${temporary_file}" 2>&1 + #echo "${PS4}$*" > "${temporary_file}" + #sh -c "$*" >> "${temporary_file}" 2>&1 + sshpaste_file "${temporary_file}" + rm -f "${temporary_file}" +} + +sshpaste_usage() { + echo "${1}: [options] [file(s)]" >&2 + echo ' Options:' >&2 + echo ' -x read input from clipboard (requires xclip)' >&2 + echo ' -c COMMAND paste COMMAND and the output of COMMAND' >&2 +} + +flag_x= + +set -x + +while getopts "xc:" opt +do + case $opt in + 'x') + flag_x=1 + ;; + 'c') + opt_command="${OPTARG}" + ;; + '?') + sshpaste_usage $0 + exit 2 + ;; + ':') + echo "Option -${OPTARG} requires an argument, exiting…" >&2 + exit 1 + ;; + esac +done + +if [ ! -z "${flag_x}" ] +then + sshpaste_xclip +elif [ ! -z "${opt_command}" ] +then + sshpaste_command ${opt_command} +elif shift $(($OPTIND - 1)) ; test -n "$1" +then + sshpaste_file "$1" +else + sshpaste_usage "$0" +fi