#!/bin/bash

if [ "$1" != "" ]; then
    echo "Usage $0 < file_to_paste or cat file_to_paste | $0"
    exit 0
fi

TARGET="http://laltromondo.dynalias.net/~nopaste/index.php"
TMPFILE=`mktemp`
NAME=`whoami`
DATE=`date +%d-%m-%T`
TITLE="nopaste.sh $DATE"
cat /dev/stdin > $TMPFILE

curl $TARGET -F "code=<$TMPFILE" \
    -F "submit=submit" \
    -F "name=$NAME" \
    -F "title=$TITLE" \
    -F "expire=1440" \
    -F "lang=text"

if [ $? != 0 ]; then 
    echo "something got wrong"
    exit 2
fi

wget -q -O- http://laltromondo.dynalias.net/~nopaste/lists | \
    grep -e "$TITLE" | \
    sed -e "s/.*href=\"\(.*\)\">$TITLE.*/\1/"

rm $TMPFILE

