You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
4.0 KiB

#!/bin/bash
# Aufrufsyntax:
# paste42.sh [-s] [-t "filetype"] [-l] [-h] [-u] file
# Variablen initialisieren & defaults setzen
VERSION="20151119.1"
ATTR=''
TYPE="text"
TYPES="4cs 6502acme 6502kickass 6502tasm 68000devpac abap actionscript3 actionscript ada algol68 apache applescript apt_sources asm asp autoconf autohotkey autoit avisynth awk bascomavr bash basic4gl bf bibtex blitzbasic bnf boo caddcl cadlisp cfdg cfm chaiscript cil c_loadrunner clojure c_mac cmake cobol coffeescript c cpp cpp-qt csharp css cuesheet dcs delphi diff div dos dot d ecmascript eiffel email epc e erlang euphoria f1 falcon fo fortran freebasic fsharp gambas gdb genero genie gettext glsl gml gnuplot go groovy gwbasic haskell hicest hq9plus html4strict html5 icon idl ini inno intercal io java5 java javascript j jquery kixtart klonec klonecpp latex lb lisp llvm locobasic logtalk lolcode lotusformulas lotusscript lscript lsl2 lua m68k magiksf make mapbasic matlab mirc mmix modula2 modula3 mpasm mxml mysql newlisp nsis oberon2 objc objeck ocaml-brief ocaml oobas oracle11 oracle8 oxygene oz pascal pcre perl6 perl per pf php-brief php pic16 pike pixelbender pli plsql postgresql povray powerbuilder powershell proftpd progress prolog properties providex purebasic pycon python qbasic q rails rebol reg robots rpmspec rsplus ruby sas scala scheme scilab sdlbasic smalltalk smarty sql systemverilog tcl teraterm text thinbasic tsql typoscript unicon uscript vala vbnet vb verilog vhdl vim visualfoxpro visualprolog whitespace whois winbatch xbasic xml xorg_conf xpp yaml z80 zxbasic"
pw=0
trap 'stty echo;exit 1;' 3 9 15
usage() {
echo "Usage:"
echo " $0 [-s] [-t \"type\"] [-l] [-e 10m|1h|1d|1w|4w|1y|date] file"
echo " -s not \"public\""
echo " -t <type> file type"
echo " -l filetypes"
echo " -h this help"
echo " -u check for update"
echo " -e <time> expiration:"
echo " 10m = 10 minutes ; 1h = 1 hour ; 1d = 1day ;"
echo " 1w = 1 week ; 4w = 4weeks ; 1y = 1 year ;"
echo " or date: YYYY-MM-DD HH:II:SS"
echo " -p set a password to delete the paste"
echo ""
echo "Version: $VERSION"
}
filetypes() {
echo "Filetypes:"
for i in $TYPES ; do
echo " $i"
done
}
checkUpdate() {
SERV_VER=$(curl -s -S 'http://git.thomasba.de/cgit/paste42/plain/paste42.sh' | sed -e '/^VERSION=.*/ !d;s/VERSION="\(.*\)"/\1/')
if [ "$SERV_VER" != "$VERSION" ] ; then
echo "Update available!"
echo "Your version: $VERSION"
echo "Remote Version: $SERV_VER"
else
echo "No Updates."
fi
}
# wenn keine argumente, usage ausgeben
if [ $# -eq 0 ] ; then usage ; exit ; fi
# argumente auswerten
while getopts pst:lhue: opt ; do
case "$opt" in
-) break;;
s) ATTR=$ATTR' -d sec=true';;
t) TYPE=$OPTARG;;
[hH]) usage;exit;;
l) filetypes;exit;;
u) checkUpdate;exit;;
p) pw=1;;
e) ATTR=$ATTR' -d exp='$(echo "$OPTARG"|sed -e 's/[^0-9:\.a-zA-Z ,]//g');;
esac
done
shift $((OPTIND - 1))
# wenn dateiname leer ist, beenden
if [ -z "$1" ] ; then
usage
exit
fi
# wenn datei nicht existiert oder nicht lesbar ist, suizid
if [ ! -f "$1" ] || [ ! -r "$1" ] ; then
echo "File \"$1\" not readable!" >&2
exit 1
fi
if [ ! -s "$1" ] ; then
echo "File is empty!" >&2
exit 1
fi
if [ -b "$1" ] || [ -c "$1" ] || [ -S "$1" ] || [ -d "$1" ] ; then
echo "\"$1\" is no ordinary file!"
exit 1
fi
# meckern, wenn mehr als eine datei angegeben wurde...
if [ $# -gt 1 ] ; then
echo "only the first file will be used ;)" >&2
fi
if [ $pw -eq 1 ] ; then
echo "Please choose the Passwort:"
password="";password2="1"
while [ ! "$password" = "$password2" ] ; do
if [ ! "$password" = "" ] ; then echo "The passwords didn't match." ; fi
echo -ne " Password: "
stty -echo ; read -r password ; stty echo
echo -ne "\n Repeat the password: "
stty -echo ; read -r password2 ; stty echo
echo ""
done
fi
filename=$(basename "$1")
# und die daten absenden.
curl -s -S --data-urlencode "del=$password" -d "title=curl paste of $filename" $ATTR -d "type=$TYPE" --data-urlencode "text@$1" 'http://paste42.de/save'