/home/projects/post.sh
:: page last updated 02007/10/28
post.sh is a curl bash script written to automatically post the contents of a directory to a trevorchan-style image board. So far it has only been tested and proven to work on 7chan and fapchan, but there is no reason it shouldn't work on any other trevorchan board. Similarly, it has only been tested on linux, but should work in any POSIX envrioment with bash, curl, and wc.
The complete source follows:
#written by OmgWtfIDiedLol of #7chan@irc.7chan.org
count=`ls | wc -l`; filen=0; for file in *; do filen=`expr $filen + 1`; sleep 5; echo "Uploading $file...($filen of $count)"; curl -F board="BOARD" -F message="File $filen of $count." -F name="NAME" -F em="EMAIL" -F replythread="THREAD NUMBER" -F imagefile=@"$file" http://img.7chan.org/board.php; echo "Done" ; done
Basically, the script counts the number of lines of a ls, defines that as $count, then increments $filen until it reaches $count. Every time $filen is incremented, $file is posted, and "Done" is echoed to the command line.
In operation, you set BOARD to whichever board you are posting to (b for /b/, h for /h/, etc), set NAME to whichever name you're using, EMAIL to whichever email you wish to use, and THREAD NUMBER to the root thread, which is critical. Without THREAD NUMBER, post.sh will just post the contents of the directory as a new thread for each file, which is very poor etiquette, and will usually result in a ban and deletion of the superfluous threads. Don't do it!
In this form, there are several serious bugs. The first is that post.sh will attempt to post everything in a directory, including text files and executables. This would not be more than annoying and a waste of bandwidth if it did not also attempt to post directories, which hangs the script.
An interm solution is to replace
count=`ls | wc -l`; filen=0; for file in *;
with
count=`ls | wc -l`; filen=0; for file in *{.jpg,.png,.gif,.jpeg,.JPG};
This introduces another bug, in that the for loop will match every case of the {} wildcards, even if it doesn't actually match any files. Thus, if you execute post.sh in a directory full of JPEGs, then it will cycle through the other extensions at the end, throwing off the count. Since these pseudofiles never get posted, this usually isn't visible to the end user, but it is nonetheless a terrible hack.
Lighttpd, otherwise a very fine web server, does not properly support the Expect: 100-continue header, and returns a 417 "Expectation failed" error. To get around this, we tell post.sh to not use the expect header, like thus:
count=`ls | wc -l`; filen=0; for file in *; do filen=`expr $filen + 1`; sleep 5; echo "Uploading $file...($filen of $count)"; curl -H "Expect" -F board="BOARD" -F message="File $filen of $count." -F name="NAME" -F em="EMAIL" -F replythread="THREAD NUMBER" -F imagefile=@"$file" http://img.duochan.org/board.php; echo "Done" ; done
post.sh was written by OmgWtfIDiedLol, who, despite having a very silly name, is a very nice person who wouldn't ban someone just for publishing their shell script without asking permission.