LINUX - Pastebin called hastebin - hosting Haste-server make your own pastebin server with a cli pasteing ability

HOW TO SETUP HASTEBIN SERVER THAT WORKS WITH CLI
################################################

EXAMPLE END RESULT: http://ec2.kossboss.com:7777/mejodeboca - note thats just for show, the final article which you are looking at on this kossboss.com site is the final deal, the ec2.kossboss one is a draft.

OBJECTIVE: run "output-command | hpaste" which then tells me what URL to go to see my output in a nice formated text permenantly

I followed the instructions here: http://aricgardner.com/intranet-pastebin-hasteserver/ All credit goes to that guy. Just incase his link or server is down, I included a copy paste of his article below - I hope thats not breaking any copywrite laws :) after all we are talking about pastebins :} Anyhow all credit goes to the owner of that site.

Back to topic...
I used Method 1 and did some modification, I like I only used the root user.

Before we begin:
Sorry If I make a mistake on path, all of the commands are ran as root either from /root or from /root/scripts, or a couple other locations with in /root.

THE HOW TO BEGINS
=================
First step log in as root, he goes about making a pastebin user and I dont know - now its typically better to follow the recommended way of user per service but I decide to break that rule here - more on that below in the SIDE NOTE section at the end.

Its important to get all the right tools for the job right?

sudo apt-get install build-essential libssl-dev redis-server git-core curl libssl-dev libcurl4-openssl-dev

GET NVM AND RUN IN
==================
cd ~
git clone git://github.com/creationix/nvm.git ~/nvm
. ~/nvm/install.sh
#log out of the server
#log back in (i logged back in as root)
. ~/nvm/nvm.sh

INSTALL LATEST NVM
==================
nvm install 0.6.14
cd ~/
git clone https://github.com/seejohnrun/haste-server.git
cd haste-server/
vim config.js 

I LEFT CONFIG DEFAULT - JUST FYI THATS WHERE YOU SET THE PORT
BUT THATS WHERE YOU WOULD CHANGE THE PORT - MY CONFIG.JS LOOKS LIKE THIS: cat 

npm install
npm start &

Now the hastebin server is starter, go to your IP:7777 (not https unfortunatly - https instructions are Method 2 on that link above)

LETS MAKE AN INIT SCRIPT THAT WILL START IT OFF DURING BOOT
===========================================================

This is where my script is different. Remember to start an NPM app, first start NVM then start NPM from within the folder where the app is.

First I make the script, into a scripts folder in my ~ aka /root and then put the text into the script via vim, then edit the /etc/rc.local script (which launches during boot) to launch that script we just wrote with the sudo prefix - I tested the rc.local script and trust me without that sudo it doesnt work.

cd /root/
mkdir scripts
cd scripts
touch hstart
chmod +x hstart
vim hstart

PUT THIS INTO SCRIPT (scripts are red):
#!/bin/bash
cd /root/nvm/
. ./nvm.sh
nvm use 0.6.14
cd /root/haste-server/
npm start &

Save and exit with it, then go to rc.local script in etc and before the "exit 0" line add in the following line "sudo /root/scripts/hstart" without quotes of course. (Side note: The sudo I was talking about earlier was the sudo in that previous line.)

What about reboot? Havent made the script yet, but just rebooting doesnt hurt, you will some errors, but it recovers, if you want a legit shutdown, I would just do the reverse of the init script, and find out the npm stop and nvm stop commands.

NOW TO PASTE THINGS
===================

Make this script (and put it in one your directories from $PATH for easier use)

cd ~
mkdir scripts; cd scripts; touch hpaste; chmod +x hpaste; vim hpaste;

SCRIPT (scripts are red):
#!/bin/bash
url="http://ec2.kossboss.com:7777"
key="$(curl --silent --insecure --data-binary @/dev/fd/0  $url/documents | cut -d "\"" -f 4)"
echo $url"/"$key

HOW TO USE:
Take a command that has some output to stdout, and redirect it through a pipe into hpaste.
It will output the full link, it autogenerates the last part called the key.

AS AN EXAMPLE HERE IS HOW I DID THE config.js PASTLET:
cat config.js | /root/scripts/hpaste
OUTPUT IS:
verbose: added document key=situpajova
http://ec2.kossboss.com:7777/situpajova

So then I would share with everyone http://ec2.kossboss.com:7777/situpajova
And the situpajova is the random key it made up

SIDENOTE: As I was following the instructions I got lost on which user he wanted me to be throughout the commands, so in the very beginning I logged in as root and actually made the pastebin user and gave it a simple password, any how from there on I never logged in as that pastebin user, I wasnt sure If I was supposed to as the instructions were ambigious on that part. I stayed as root and everthing worked out. So if you follow my instructions no need to make pastebin user.







COPY OF SITE - I have an OCD thing about thinking peoples sites might be down one day, so I copy paste the material out, but I still give full credit where its due, in this case its all due to the owner of the site: http://aricgardner.com/intranet-pastebin-hasteserver/ - If this is something bad and you dont want me to include this, let me know my contact information is all over this blog. opps@kossboss.com will get to me.

My Intranet Pastebin: haste-server

hastebin was easy to install and is the prettiest pastebin server I could find on github. It’s no surprise that its the first search result. It also has a command line client to make uploading to the service dead simple. The following is a record of my installation of haste server, it took all of five minutes (depending on compile time) Hastebin in action:http://hastebin.com/ I will use Node Version Manager to install and maintain Node JShttps://github.com/creationix/nvm
https://npmjs.org/doc/install.html

Step one, prerequisites.

Method 1 (NVM Quick and dirty)

1
sudo apt-get install build-essential libssl-dev redis-server git-core curl libssl-dev libcurl4-openssl-dev

make a user for your service

1
2
adduser pastebin
cd ~/


Get nodjs manager

1
2
3
4
5
git clone git://github.com/creationix/nvm.git ~/nvm
. ~/nvm/install.sh
#log out
#log back in
. ~/nvm/nvm.sh

Install node js 0.6.14 and hasteserver

1
2
3
4
5
6
7
nvm install 0.6.14
cd ~/
git clone https://github.com/seejohnrun/haste-server.git
cd haste-server/
vim config.js
npm install
npm start &

After the machine rebooted i needed to do some things. better make a proper init script

1
2
3
4
[[ -s /home/pastebin/.nvm/nvm.sh ]] && . /home/pastebin/.nvm/nvm.sh # This loads NVM
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
cd /home/username/haste-server
/home/pastebin/.nvm/v0.6.14/bin/npm start

Method 2: (Production)
Using Node from git clone https://github.com/joyent/node.git
Rather than NVM, start stop daemon etc.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
adduser hastebin
su hastebin
cd ~/
git clone https://github.com/joyent/node.git
cd node
git checkout v0.8.20
./configure
make
sudo checkinstall
wget http://npmjs.org/install.sh
chmod +x install.sh
sudo ./install.sh
git clone https://github.com/seejohnrun/haste-server.git
cd haste server
npm install
vim config.js
npm start

I’m going to put apache in front of this, as that’s whats running on port 80 at work

1
2
a2enmod proxy
a2enmod proxy_http

Example Apache config

1
2
3
4
5
6
7
8
9
10
11
12
13
<VirtualHost *:80>
ProxyRequests Off
<Proxy *>
                Order deny,allow
                Allow from all
</Proxy>
   <Directory />
 
                ProxyPass http://127.0.0.1:7777/
                ProxyPassReverse http://127.0.0.1:7777/
   </Directory>
</VirtualHost>
~

Now that its working you need a proper init file. I’ve found that with nodejs –chdir is your friend.
https://gist.github.com/Aricg/5032312

As root add your new init file to startup.

1
2
3
4
5
6
7
8
9
10
11
/home/hastebin# update-rc.d hastebin defaults
update-rc.d: warning: /etc/init.d/hastebin missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
 Adding system startup for /etc/init.d/hastebin ...
   /etc/rc0.d/K20hastebin -> ../init.d/hastebin
   /etc/rc1.d/K20hastebin -> ../init.d/hastebin
   /etc/rc6.d/K20hastebin -> ../init.d/hastebin
   /etc/rc2.d/S20hastebin -> ../init.d/hastebin
   /etc/rc3.d/S20hastebin -> ../init.d/hastebin
   /etc/rc4.d/S20hastebin -> ../init.d/hastebin
   /etc/rc5.d/S20hastebin -> ../init.d/hastebin

Haste Bin Bash/curl Command Line Client
Apparently there is a ruby command line client. but.. I don’t really see the need, we all have bash and curl right?

Put this in your path somewhere, (name it haste) and make it executable

1
2
3
4
#!/bin/bash
key="$(curl --silent --insecure --data-binary @/dev/fd/0  $url/documents | cut -d "\"" -f 4)"
echo $url"/"$key

Then you can just send any stdout to your pastebin server. Just copy the link afterwards and share it with your colleges
example usage:

1
2
3
ps -ef | haste
 
https://paste.somecompany.com/lokoxapura
SelectionFile type iconFile nameDescriptionSizeRevisionTimeUser
Comments