Monday, February 13, 2017

mutt print to pdf one liner

set print_command="iconv -c -t ISO-8859-1//TRANSLIT | enscript -B --word-wrap --font=Times10 $1 -p - 2>/dev/null| ps2pdf - /tmp/test.pdf && evince /tmp/test.pdf"

posted by admin at 9:26 pm  

Saturday, February 11, 2017

Time Machine backups on DreamCompute

I really like the simplicity of Time Machine for backing up my Macs. It makes restoring lost files and changing computers extremely easy. However, my laptop is rarely on my home network so it would go months without completing a full backup. My solution was to set up an openvpn server and bridge it with my home network. This allowed my laptop to appear as if it was on my home network regardless of where I was connected. This also allowed me to print to my network printer and VNC to machines on my home network when I was away. I also set it up where I could, when needed, tunnel all traffic through my home network so traffic would be encrypted even if I was on a public unencrypted wifi network.

I had been using BackBlaze for offsite backups but I wanted to see if I could get offsite TimeMachine working. A few notes before I get rolling:

  1. This uses a lot of bandwidth for initial backup. I was saturating my 100Mbps FIOS connection before I started packet shaping. However, incremental backups are usually small so it isn’t much of an issue after initial backup.
  2. If you follow the directions below, you can’t do a full system restore from it as a local VPN connection is required. So, if something happened to both your computer and your local backup, restoring would be still be possible but more complicated as you would need to copy the sparse image somewhere local.
  3. If you have a large (>100GB) amount of data to back up, this can get expensive as only 100GB is included with a DHC account.
  4. This should not be your primary backup. Because of the latency, browsing and restoring files lags a bit.

Setting up a server

I will be setting up an Ubuntu instance on DreamCompute. On that instance, I will be running an OpenVPN server, an AFP daemon, and an avahi daemon.

The first thing you need to do is create an Ubuntu 16.04 instance using the directions here. Even while backups were running, I never exceeded a load of .5 on a single proc instance or more than 100MB of RAM so a semisonic instance is more than powerful enough.

You need to create a volume for the backups to be stored on and attach it to the instance you just created. Make sure the volume you create is at least as big as the drive in the computer you are backing up. You should only use this volume for backups as Time Machine will grow to use all the space you give it to store incremental snapshots. Follow the directions here to set up a volume.

You also need to open up UDP port 1194 for your OpenVPN connection. Instructions for setting up a security group on DreamCompute are here.

Install dependencies

Now that we’ve got the server up and running, first thing we need to do is install needed dependencies!

sudo su
apt-get install openvpn easy-rsa netatalk avahi-daemon

Create and attach volume

Partition and format your volume. I used xfs but it doesn’t really matter.

parted -s /dev/vdb mklabel gpt mkpart P1 xfs 0% 100%
mkfs.xfs /dev/vdb1

Create the direction where you want the backups stored.

mkdir /mnt/backups

Edit /etc/fstab and add a line for your backup mount

/dev/vdb1 /mnt/backups xfs defaults 0 0

And get it mounted.

mount -a

Set up users

While it is possible to store all backups under the same user, I find it easier to manage backups if each computer’s backup is stored under its own user. For each computer you want to back up set up a user.


adduser luke
mkdir /mnt/backups/luke
chown -R luke /mnt/backups/luke

Set up certificate authority and generate keys

For computers to be able to connect to your OpenVPN server, you need to set up a certificate authority.

mkdir /etc/openvpn/easy-rsa/
cp -r /usr/share/easy-rsa/* /etc/openvpn/easy-rsa/

Edit /etc/openvpn/easy-rsa/vars and update the values to match your information.

Build the certificate authority

cd /etc/openvpn/easy-rsa/
source vars
./clean-all
./build-ca
./build-key-server timemachine
./build-dh
cp timemachine.crt timemachine.key ca.crt dh2048.pem /etc/openvpn/

Now, generate a key for each of the computers you wish to back up.

cd /etc/openvpn/easy-rsa/
source vars
./build-key luke

Copy ca.crt and the generated files to each machine you are going to be backing up using scp or rsync.

/etc/openvpn/ca.crt
/etc/openvpn/easy-rsa/keys/luke.crt
/etc/openvpn/easy-rsa/keys/luke.key

Next we have to set up the OpenVPN server itself. Copy the sample server config file and decompress it into /etc/openvn

cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/
gzip -d /etc/openvpn/server.conf.gz

Edit /etc/openvpn/server.conf For timemachine you want it to be a tap device, not tun so remove the semicolon from behind “dev tap” and add one behind “dev tun”.

dev tap
;dev tun

You also need to update ca, cert, and key to point to the correct files.

ca ca.crt
cert timemachine.crt
key timemachine.key

OpenVPN configuration is done. Time to start it up!

service openvpn start

Set up AFP

TimeMachine requires either a local disk or a disk mounted via AFP or SMB. AFP will be deprecated once apple moves to APFS. Unfortunately, as of the writing of this blog, the SMB implementation in Ubuntu doesn’t support an extension that TimeMachine requires. You can check https://bugzilla.samba.org/show_bug.cgi?id=12380 to see if that has changed. So, we will be using AFP here. Luckily, the default install includes a config file for Apple volumes we just have to tweak it for our setup. Edit /etc/netatalk/AppleVolumes.default and add this line:

/mnt/backups/$u "Time Machine" options:tm

Now you just have to restart the service!

service netatalk restart

Set up avahi

The last thing we have to set up is avahi. This is Apple’s zeroconf networking protocol that will allow our Mac to find the server to back up to it. There’s no configuration changes we need to make sure. Just start the service.

service avahi-daemon start

Set up OpenVPN on mac

While you can use the OpenVPN command line client or TunnelBlick, I have found Viscosity much more powerful and easy to use.

For address, use the ip of your DreamCompute instance.

We will be moving a lot of data over this connection. Make sure LZO compression is on.

Use the ca, cert, and key that you copied over earlier.

Start backups!!!

From System Preferences, go to Time Machine. From there click “Add Backup Disk.” Select the TimeMachine mount you created and the backup will start!

If you ssh back into the server, you should be able to see the sparse image.

ubuntu@timemachine:/mnt/backups/luke$ ls
Luke.sparsebundle Network Trash Folder Temporary Items

posted by admin at 9:37 pm  

Sunday, November 4, 2012

Site update check script (or how I knew the Viriginia Bar results within 5 seconds)

Joy just passed the Virginia bar (congrats baby!!!). The way that bar results work  in Virginia, is at some random time over the span of a couple days the list of everyone who passed gets posted to http://www.vbbe.state.va.us/bar/barresults.html This results in 1500 people staring at their computer endlessly beating the refresh key. To save Joy the stress on her fingers I wrote up a script to do it for her. I thought of two different ways of doing it.

1. Using the document.lastModified property

2. Checking the filesize of that webpage.

2 seemed like a cleaner/quicker option but did have the extremely unlikely chance that the modified page would be exactly the same size as the unmodified page. To fix this, I decided to do a checksum instead of a file size check. I also had it either dump the page to shell or email a copy of the source code just in case it got changed back quickly. I wrote the script in a way I could reuse it in the future. It should work on any *nix system. However, if you want an email instead of a shell output you will need to have mutt installed and outgoing mail properly configured. It will probably not work correctly on most dynamically generated sites. I’m sure there are better ways of going about this but this worked well for me and let Joy and me know results were up within 5 seconds of them being posted. Example usage and output below.

[harlow]$ ./sitecheck.sh
Usage: sitecheck.sh $site [$email] [$sleep (default 30)]

harlow]$ ./sitecheck.sh betterthanbacon.me/test.html luke@lukeodom.com 5
Sun Nov 4 19:57:13 PST 2012 no change
Sun Nov 4 19:57:18 PST 2012 no change
Sun Nov 4 19:57:23 PST 2012 no change
Sun Nov 4 19:57:28 PST 2012 no change
Change detected. Sending email to luke@lukeodom.com
Sun Nov 4 19:57:38 PST 2012 no change
Sun Nov 4 19:57:43 PST 2012 no change

Script can be downloaded at

http://betterthanbacon.me/sitecheck.sh

Or it’s dumped at:

#! /bin/bash

#Check for at least one variable

if [ $# == 0 ]
then
echo “Usage: sitecheck.sh \$site [\$email] [\$sleep (default 30)]”
exit
fi

#Create temp file

tmp=`mktemp`

#Create initial md5 sum

curl -s $1 > $tmp
md5old=`md5sum $tmp | awk ‘{print $1}’`

#Get site again, compare to inital md5 checksum, rinse, repeat

while true; do
curl -s $1 > $tmp
md5=`md5sum $tmp | awk ‘{print $1}’`
if [ $md5 != $md5old ]
then
if [ -z $2 ]
then
echo “change detected”
cat $tmp
else
echo Change detected. Sending email to $2
echo $1 |  mutt -a $tmp -s “$1 updated” $2
fi
md5old=$md5
else
echo `date` no change
fi
if [ -z $3 ]
then
sleep 30
else
sleep $3
fi
done

posted by admin at 8:02 pm  

Tuesday, November 29, 2011

Odom Family Cane Grinding 2011

Every year, on Green Friday (the day after Thanksgiving, not to be confused with Black Friday, its evil twin), my family has its annual cane grinding. The first cane grinding on my family’s farm was some time in the late 1800’s, however it was stopped about 60 years ago and not started again until 2005 when my father rebuilt the original shelter that housed the boiler.

The process we use changes from year to year but the following is a description of the process as it was done in 2011.

Preparation

The preparation for the grinding is usually done 1 to 2 weeks earlier and the process hasn’t really changed in the last 100 years. The leaves of the cane must be stripped off using a tool with a forked metal piece on the end.

A machete is used to cut the tops off the cane stalks and to cut them down.

The stalks are placed in wooden holders designed to fit approximately 1/2 of a boiling and be easily transported using a tractor forklift.

The stacks of cane are covered in the leaves that were stripped off earlier to protect them if there is a freeze during the 1 – 2 weeks they are there.

The Grindin’

The leaves are cleared off of a stack of cane and a fork lift on the back of a tractor is used to pick it up.

The cane is then sat down on a rack designed to make it easy to reach the cane and feed it into the grinder.

The cane is then fed into a Kenwood 1895 No. 0 grinder which is powered by driving a tractor in circles around the grinder

The juice comes out and is strained with a tea strainer and a burlap sack.

The juice then runs through an underground pipe system until it comes out and flows into a 60 gallon cast iron pot.

Once the pot is full, the juice level is brought down using the drain valve and then the juice is diverted into a 55 gallon barrel so that grinding can continue while the juice is cooking.

The Boiling

A gas burner under the pot is lit using a homemade matchstick.

Once the juice starts boiling (usually 20 – 30 minutes), a homemade skimmer made by wiring a grease splatter guard to a handle is used to skim any impurities that come to the surface off of the cane.

Once the juice start boiling up, a burlap sack is placed between the lower and upper rims of the pot. The juice then boils over the lower rim and through the burlap sack, further purifying it.

Once the juice is getting near done the level drops and the burlap is pulled off. The juice will then start “thumping,” or having explosive bubbles that shoot the juice up to 2 feet above the surface of the rest of the liquid.

There are two methods of telling when the syrup is ready to be bottled. The first is counting how long it takes for the boiling bubbles to cease once it is scooped up. The magic number is 37 but this is not 37 seconds, it is specific length of counting that is passed down from one generation to the next.

The second method is measuring the density of the liquid using the Baumé scale. The density of syrup when it is ready to be bottled is approximately 35 baume.

Once the syrup is ready you can see it flake when you pour it.

Bottling

The syrup is then poured through a cotton cloth to purify it one last time.

The syrup is then put into the bottles from the aluminum pot which was fitted with a brass valve at the bottom.

The bottles are then labeled and ready to go!

posted by admin at 8:56 am  

Sunday, October 23, 2011

Random Pic of 2011

Taken from my apartment on an overcast evening (not many of those to choose from) looking back towards the Hollywood letters.

posted by admin at 2:31 pm  

Sunday, November 14, 2010

Free in LA – The Nethercutt Museum and Collection

One of the hidden gems of Los Angeles is the Nethercutt Collection in Sylmar. This is a large collection of cars and musical equipment that was collected by the founder of Merle Norman. When he opened the collection to the public, he funded it with a trust ensuring that the public could view the entire collection at no charge. The tours of the Nethercutt Collection are by reservation only.

The first part of the tour goes into a room that is designed to look like a car showroom from the 1930’s. All of the cars here, and throughout the museum, are well maintained and functioning.

Later in the tour, they had a room full of orchestrians. These are basically large mechanical musical instruments that are a combination of many different instruments meant to sound like an orchestra. The picture above is of me standing beside one 🙂

nethercutt3

');" class="shutterset_" title="Open orchestrian. ">

This is one of the smaller orchestrians opened so that you can see the mechanical gears inside.

Across the road from the Nethercutt Collection is the Nethercutt Museum. This is a large room with row upon row of old cars. The cars were so well polished it was impossible to take a picture without getting myself in it!

One final attraction is behind the museum. They have a 1937 Canadian Pacific Royal Hudson Locomotive. The train is also pulling a private car that you can tour.

We only lived a couple miles from here but if you are in the LA area, it is definitely worth the drive into The Valley to see the Nethercutt Collection and Museum! More info at http://nethercuttcollection.org

posted by admin at 11:16 pm  

Sunday, October 31, 2010

Picture of the [insert random time period]

This Halloween Joy and I went to my company Halloween party as ghosts from “It’s The Great Pumpkin Charlie Brown.” While we were at the party, Joy got this awesome shot of me. A little more sinister than I had planned for the costume to be but still fun 😛

Charlie Brown Ghost

posted by admin at 11:09 pm  

Saturday, May 1, 2010

Free in LA – Grunion Run

Friday, April 30, 2010, Joy and I went to Last Friday’s in Santa Monica. This is where the businesses on Santa Monica’s Main Street stay open late and give specials, deals, and discounts on the last Friday of each month. After this, we made our way to Venice Beach to the Venice Oceanarium Grunion Party.

You may be wondering what a grunion is and why it would be partying. A grunion is a small fish that can only be found off the coast of southern California and Baja, Mexico. The grunion is partying because it is mating season. They have an unusual mating ritual where the female buries herself in the sand, the male wraps himself around the female, and then they both swim off.

We were given some illumination by the moon, but we were glad we brought our flashlight with us.

Soon, we started catching glimmers of the fish as they swam off.

I gave the flashlight to Joy. She was a lot better at spotting grunions than me.

This guy was trying to catch one but failed to notice the one swimming by his foot.

“Hey, have you seen any cute cold-blooded guys around here?”

“Nevermind, I found one.”

“Bye, come back soon for another Free in La. Thanks @365cheapdates for the idea.”

posted by admin at 9:26 pm  

Monday, April 5, 2010

Free in LA – International Pillow Fight Day

On April 3rd at 3:00 p.m., I was at Pershing Square. A picture speaks 1000 words. Here are 83,000 words.

posted by admin at 2:10 pm  

Sunday, April 4, 2010

Free in LA – Olvera Street “Blessing of the Animals”

Each year, on the Saturday before Easter, just outside of Union Station on Olvera Street, a tradition takes place. It is the “Blessing of the Animals.” Hundreds bring their pets and livestock to be blessed by the priest.

There is also live singing and dancing, both traditional Latino and Aztecan.

This dog is super excited about have a priest spray him with water,

as is this Alpaca,

and this dog and rabbit sharing a baby carriage.

As cows have given us the most, they are first in the parade.

Since llamas look cool, they go in the middle.

Snakes are scary so they go last. This one goes very last, far far away from me.

There are also a ton of vendors selling various items. Joy wanted a sombrero, but with our small budget we couldn’t get her a full size one 😀

posted by admin at 10:58 pm  
Next Page »

Powered by WordPress Copyright © 2011 Luke Odom