Raspberry Pi of Death Blog

By N. Leveck

On a simple pastebin

On the list of projects I have been kicking around in my mind, a simple pastebin has been high on the list. It struck me that since I live in ssh, a daemonized port dwelling beast was overkill. Then it hit me that everyone's webserver is an scp away.So a simple bash script to pipe to would suffice for pulling this off. Character encoding via the (granted, not totally accurate) hueristics of the file command and some simple css to state that we are using UTF-8 (the one true character encoding) was added.

I started down the rabbithole of adding a width handler for output, then unix philosophy came slapping me in the face. If I needed width formatting I could pipe thru cut/fmt/fold. So here is my script, there are many like it, but this one is mine...

#!/usr/bin/env bash 
while read line 
a=$(echo -e "$a\n$line\n") 
CHARSET="$(file -bi "$i"|awk -F "=" '{print $2}')" 
nam=$(date +%s) 
echo "<html><head><meta charset='UTF-8'><title>Leveck.us pastebin "\ 
"document $nam</title></head><body style='font-size: "\ 
"calc(16px + 1vw); line-height: calc(1.1em + 0.5vw);'><pre>"\ 
> /tmp/$nam echo "$a" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g;\ 
s/"/\&quot;/g; s/'"'"'/\&#39;/g' | iconv -f "$CHARSET" -t UTF-8 \ 
>> /tmp/$nam 
echo "</pre></body></html>" >> /tmp/$nam 
scp /tmp/$nam leveck@rpod:/var/www/html/pastebin 
rm /tmp/$nam 
echo -e "\n\nYour link:\nhttps://leveck.us/pastebin/$nam"
All content © 2017-2019 Nathaniel Leveck, all rights reserved. Gopher links funneled through the RPoD gopher->http proxy server.