home of the madduck/ blog/
Publishing files to the masses, temporarily

Especially on IRC, I am often faced with the task to share a file with someone. There are pastebins, but they don't help with binary files, quick updates, or sharing directories.

Over the past year, I thus developed the pub shell script, which you can obtain from my SVN repository_ (you can check out the parent directory with several other helpers, or all my non-admin shell scripts). I documented it in the header, so if I have piqued your interest, have a look there for details.

pub requires an SSH-accessible machine with a directory to which you can write, and which is exported via HTTP or FTP (it would be nice to support WebDAV in the future). In my case, that's madduck@scratch.madduck.net:/srv/apache2/stuff.madduck.net/htdocs/scratch, which is available as http://scratch.madduck.net/. Thus, I created ~/.pubrc with the following contents:


Here's what I can do now (lines are truncated after 80 characters):

## publish a simple file
$ pub /etc/fstab
http://scratch.madduck.net/__etc__fstab 1446 885c2219df938a059a5f0a13e65e8f9

## ... with optional verification by downloading and comparing md5sums
$ pub --verify /etc/fstab 
http://scratch.madduck.net/__etc__fstab 1446 885c2219df938a059a5f0a13e65e8f9
I: successfully uploaded: /etc/fstab

$ HEAD http://scratch.madduck.net/__etc__fstab | head -1
200 OK

## remove the published file
$ pub --delete --verify /etc/fstab                             
I: successfully deleted: /etc/fstab

$ HEAD http://scratch.madduck.net/__etc__fstab | head -1
403 Forbidden

## bzip2 the file while publishing
$ pub --bzip2 /etc/fstab         
http://scratch.madduck.net/__etc__fstab.bz2 501 16e3b533f6588b670c75160dce1f
$ pub --bzip2 --delete /etc/fstab 

## same with gzip
$ pub --gzip /etc/fstab 
http://scratch.madduck.net/__etc__fstab.gz 423 ea28b1fc537690a0344b74ad2f2d7
$ pub --gzip --delete /etc/fstab  

## sometimes I don't want the filename to be guessable:
$ pub --obscure /etc/fstab
http://scratch.madduck.net/__etc__fstab__7eb7d8881a02e47e2906131dec256115 14
$ pub --obscure --delete /etc/fstab 

## and this even works with extensions, properly:
$ pub --obscure /etc/a2ps.cfg
$ pub --obscure --delete /etc/a2ps.cfg

## and finally: directories:
$ pub --bzip2 /etc/init.d
http://scratch.madduck.net/__etc__init.d.tar.bz2 59758 1f94314ff9fd472f28172
$ pub --bzip2 --delete /etc/init.d 

You'll see how the name is chosen: __etc__fstab. If you're publishing a file from underneath $HOME, the base is truncated:

$ pub ~/debian/misc/security/debsec.zuml 
http://scratch.madduck.net/debian__misc__security__debsec.zuml 14366 537b7f7

Of course, all of the above take an arbitrary number of arguments:

$ pub /etc/fstab /does/not/exist /etc/init.d 
W: skipping nonexistent file: /does/not/exist
http://scratch.madduck.net/__etc__init.d.tar 337920 c350629b859e1369ed29a98c
http://scratch.madduck.net/__etc__fstab 1446 885c2219df938a059a5f0a13e65e8f9

$ pub -d /etc/fstab /does/not/exist /etc/init.d 
W: skipping nonexistent file: /does/not/exist

Over time, the scratch space will fill up. Thus, I am using tmpreaper to delete files which have not been accessed in 30 days. The script in use, as well as the files that givern the way the HTTP server presents the scratch space, are available in this SVN repository_.

I hope this tool will be useful to some, and I am looking forward to patches and suggestions!

NP: No-Man / Returning Jesus