You are not logged in.

#1 2007-02-14 20:27:36

lydgate
Member
From: London, UK
Registered: 2006-01-10
Posts: 60

apaste (BASH script to paste to pastebin.archlinux.org)

If I shouldn't be doing this, someone let me know, and I apologize for spamming up the bin while testing it (but they should all be gone tomorrow).

Anyway, we were whining in #dwm about nopaste requiring ruby, someone mentioned that any form can be submitted with curl.  So I buckled down, read the documentation, and here's what I came up with:

Download here

#!/bin/bash
#
# apaste
#
# author: lydgate
# http://lydgate.nonlogic.org/archlinux/apaste.sh
#
# revision: 3
#
# history:
# r3: reads from stdin if no file given
# r2: spits out URL
# r1: just uploads
#
# Simple bash script to paste to archlinux's pastebin.  Requires urlencode.sh,
# file, and curl.
#
# urlencode.sh: http://www.acmesystems.it/articles/00080/urlencode.sh
#
# Todo:
# - check for dependencies

USER=apaste

case `file "$1"` in
    *Bourne*)
        TYPE="bash";;
    *python*)
        TYPE="python";;
    *perl*)
        TYPE="perl";;
    *HTML*)
        TYPE="html4strict";;
    *)
        TYPE="text";;
esac

DATA=`cat "$@" | urlencode.sh`

curl -d format=$TYPE -d code2="$DATA" -d poster=$USER \
  -d expiry=expiry_day -d paste=Send -i -s http://pastebin.archlinux.org \
  | grep Location

Basically, you can run "apaste /path/to/file" or "command | apaste" and it will give you the URL to the pastebin.  Requires file and curl.  It also needs urlencode.sh, which I got here.  If anyone can tell me a better way to urlencode something in a BASH script, I'm all ears.

Nothing to configure but the top line, setting USER if you so desire.  It will expire in a day by default.

Also, obviously it's really easy to implement the filetypes above; they're used for syntax coloring on the site.  I will try to keep things updated here.

Last edited by lydgate (2007-02-14 20:36:47)

Offline

#2 2007-02-15 02:48:34

stonecrest
Member
From: Boulder
Registered: 2005-01-22
Posts: 1,190

Re: apaste (BASH script to paste to pastebin.archlinux.org)

There's also this one from yankees26:
http://bbs.archlinux.org/viewtopic.php?id=28355


I am a gated community.

Offline

#3 2007-02-15 02:55:35

lydgate
Member
From: London, UK
Registered: 2006-01-10
Posts: 60

Re: apaste (BASH script to paste to pastebin.archlinux.org)

Yeah, that requires python, mine requires some random urlencoder, so choose your choice.

Oh, I'm also not an apple fanboy if that means anything to you

Offline

Board footer

Powered by FluxBB