#!/bin/bash
# Sticky notes script made for https://paste.openttdcoop.org
# Script made by ^Spike^ (spike <at that place> openttdcoop <dots> org)
# For any further questions try joining our IRC @ OFTC (#openttdcoop)
# h: Help
# l: Language
# v: Visibility
# p: Password
# t: Title
# d: Data
PASTEURL="https://paste.openttdcoop.org"
LANGUAGE="text"
PRIVATE="false"
TITLE=""
PASSWORD=""
usage()
{
echo "#openttdcoop Paste Script"
echo "Script is made to work with sticky-notes v1.8"
echo "It may work with earlier/later versions but no guarantees"
echo ""
echo "Usage:"
echo "$0 [-l <language>|-t <title>|-d <data>|-p <password>|-v]"
echo ""
echo " -l <language>"
echo " Can be any language which is supported by sticky-notes"
echo " Default: text"
echo " -t <title>"
echo " The title you would like to give to your paste"
echo " Default: none"
echo " -d <data>"
echo " The data you would like to publish to the paste"
echo " You can also pipe data into this script. In that case"
echo " there is no need to give the -d option"
echo " -v"
echo " Set your paste to private. This will make your paste"
echo " only be accessable if the proper hash has been supplied"
echo " with the paste ID"
echo " -p <password>"
echo " Set a password on the paste which will be needed to see it"
echo " Can be seen as more secure then private"
}
while getopts "hl:vt:p:t:d:" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
l)
LANGUAGE=$OPTARG
;;
v)
PRIVATE="true"
;;
t)
TITLE=$OPTARG
;;
d)
DATA=$OPTARG
;;
p)
PASSWORD=$OPTARG
;;
?)
usage
exit;;
esac
done
if [ -z $DATA ]
then
DATA=$(cat)
if [ -z "$DATA" ]
then
usage
exit 1
fi
fi
TEMPFILE=$(mktemp sticky-notes.XXXXXXXX)
echo $DATA > $TEMPFILE
DATA_RETURNED=""
if $PRIVATE
then
DATA_RETURNED=$(curl -s -d data="$DATA" -d language="$LANGUAGE" -d title="$TITLE" -d private="$PRIVATE" -d password="$PASSWORD" $PASTEURL/api/xml/create)
else
DATA_RETURNED=$(curl -s -d data="$DATA" -d language="$LANGUAGE" -d title="$TITLE" -d password="$PASSWORD" $PASTEURL/api/xml/create)
fi
PASTEID=$(echo $DATA_RETURNED | grep -oPm1 "(?<=<id>)[^<]+")
PASTEHASH=$(echo $DATA_RETURNED | grep -oPm1 "(?<=<hash>)[^<]+")
if [ -z $PASTEID ]
then
echo "Woops something has gone wrong pasting!"
echo "We made a backup copy of you paste in $TEMPFILE"
exit 1
fi
if [ -z $PASTEHASH ]
then
echo "Paste created at: $PASTEURL/$PASTEID"
rm $TEMPFILE
else
echo "Paste created at: $PASTEURL/$PASTEID/$PASTEHASH"
rm $TEMPFILE
fi