Archive for September, 2011

Arduino and Gentoo

Posted in HowTo on 28/09/2011 by Undersys

I wanted an fully OSS embedded device and IDE.
I also wanted something that was quick to develop for.
So I got myself an Arduino from dfrobot.

As expected the guide for Gentoo is a little out of date on the Arduino web site.

Here are some quick fixes to get the IDE up and running.

1)
Set Sun(Oracle) JRE or JDK as your system Java vm (Ice tea will make Arduino IDE fail)
I am using the JDK ( sun-jdk-1.6  system-vm)

2)
Building the tool chain. I had to remove the “-S” stable flag from the crossdev build would fail every-time.
$ USE=”-openmp” crossdev -t avr -s4 –without-headers 

3)
I had issues compiling my Arduino test code it complained at the two following things :-
“/usr/libexec/gcc/avr/ld: cannot open linker script file ldscripts/avr5.x: No such file or directory
collect2: ld returned 1 exit status”

To fix I made the following sym link :-
$ ln -s /usr/x86_64-pc-linux-gnu/avr/lib/ldscripts /usr/avr/lib/ldscripts

“/usr/libexec/gcc/avr/ld: cannot find crtm328p.o: No such file or directory
collect2: ld returned 1 exit status”

Once again fixed with another sym link :-
$ ln -s /usr/avr/lib/avr5/crtm328p.o /usr/avr/lib/crtm328p.o

4)
Use the current Arduino build from there web site the one in the portage overlay is way out of date.
I used the pre-compiled java binary with no issues from hear.
If you don’t use the latest one you may get an error like this :-
“avrdude: AVR Part “atmega328p” not found.”

Thats it! all up and running and writing code for it now.

Personal Post…

Posted in Personal on 18/09/2011 by Undersys

Ya we all hate them…

Living In Hong Kong now…
Unreal.

Just got my new rack set up and my servers shipped over.  Just got a 100/30mbit connection to my new house.

Watch out for more server posts and new embedded boards and dev kit.
Also my thoughts on a new keyboard… mechanical all the way..

Zimbra Copy to Amazon S3

Posted in Code on 18/09/2011 by Undersys

I was kinda against using S3 for backups or anything as it has a cost.
By rotating my backups keeping under the gb store limit I manage to only pay for transfers and that’s always under 1$ USD.
Now I have 4 weeks of backups stored on S3 thanks to the below script that will :-
* Put the file to S3
* rotate the 4th oldest backup file and delete it
* email me the results.

First set up an S3 account,
second setup s3cmd tool (http://s3tools.org/s3cmd)

Edit the following to suit:-

LLOC=/var/log
PFILE=`/bin/cat /tmp/curzmbk`
BKBKT="s3://basstech/backups/"
DATE=`date +%Y-%m-%d`
BKLOC="/backup"
MAILADDRESS@SERVER

 

So here is the script to do it :-

#!/bin/bash

LLOC=/var/log
PFILE=`/bin/cat /tmp/curzmbk`
BKBKT="s3://bucket/backups/"
DATE=`date +%Y-%m-%d`
BKLOC="/backup"


function loghd() {
  echo "Copy and file rotation to S3" > $LLOC/S3-CPY-$DATE.log
  echo "Started at:- `date +%c`" >> $LLOC/S3-CPY-$DATE.log
  echo "--------------------------------------------" >> $LLOC/S3-CPY-$DATE.log
}

function lstbkt() {
  /usr/bin/s3cmd ls $@
}

function putflbkt() {
  echo  "Putting File $@" >> $LLOC/S3-CPY-$DATE.log
  /usr/bin/s3cmd put $BKLOC/$PFILE $@ >> $LLOC/S3-CPY-$DATE.log
  echo "Status  $?" >> $LLOC/S3-CPY-$DATE.log
}

function rotatebk() {
  echo "--------------------------------------------" >> $LLOC/S3-CPY-$DATE.log
  /usr/bin/s3cmd ls $BKBKT > /tmp/bkbktlst
  echo "Current Files in $BKBKT" >> $LLOC/S3-CPY-$DATE.log
  cat /tmp/bkbktlst >> $LLOC/S3-CPY-$DATE.log
  BKCNT=`/usr/bin/wc -l /tmp/bkbktlst | awk ' { print $1 }'`
  if [ $BKCNT -ge 3 ]; then
    echo "--------------------------------------------" >> $LLOC/S3-CPY-$DATE.log
    OLDBK=`cat /tmp/bkbktlst | sort | sed -n 1p | awk '{print $4}'`
    echo "Roating out oldest backup file:-" >> $LLOC/S3-CPY-$DATE.log
    echo "$OLDBK" >> $LLOC/S3-CPY-$DATE.log
    /usr/bin/s3cmd del $OLDBK  >> $LLOC/S3-CPY-$DATE.log
    echo "Status :- $?" >> $LLOC/S3-CPY-$DATE.log
    rm -f /tmp/bkbktlst
  else
    echo "Less then two backup files, not roating" >> $LLOC/S3-CPY-$DATE.log
    rm -f /tmp/bkbktlst
  fi
}

function lognd() {
  echo "--------------------------------------------" >> $LLOC/S3-CPY-$DATE.log
  echo "Copy to S3 ended on `date +%c`" >> $LLOC/S3-CPY-$DATE.log
  echo "--------------------------------------------" >> $LLOC/S3-CPY-$DATE.log
}

function mailrpt() {
  /bin/cat $LLOC/S3-CPY-$DATE.log | /bin/mail -s "S3 Copy Report for `date +%c`" MAILADDRESS@SERVER
}


loghd
putflbkt  $BKBKT
rotatebk
lognd
mailrpt

Zimbra Cold backup script.

Posted in Code on 18/09/2011 by Undersys

I don’t need a hot backup solution for Zimbra I do try and sleep at night…

So I wrote the following script that will do the following :-
* stop zimba
* tar the /opt zimbra
* check the tar ball against /opt/zimbra
* encrypt the tar ball
* Email out the results.

Edit the following to suit your install :-

BKDIR=/backup
ZMHOME=/opt/zimbra
TARTL=/
GPGUSR=zimbra
LLOC=/var/log
DESTINIATION@EMAIL
#!/bin/bash

BKDIR=/backup
ZMHOME=/opt/zimbra
TARTL=/
GPGUSR=zimbra
LLOC=/var/log

DATE=`date +%Y-%m-%d`
ZMBVER=`su - zimbra -c '/opt/zimbra/bin/zmcontrol -v | awk '\''{print $2}'\'''`

function loghd() {
  echo "Starting Zimbra Full Backup" > $LLOC/ZM-FB-$DATE.log
  echo "Backup started on `date +%c`" >> $LLOC/ZM-FB-$DATE.log
  echo "--------------------------------------------" >> $LLOC/ZM-FB-$DATE.log
}

function zmstart() {
  /bin/su - zimbra -c '/opt/zimbra/bin/zmcontrol start'
}

function zmstop() {
  /bin/su - zimbra -c '/opt/zimbra/bin/zmcontrol stop'
  echo "Stopping Zimbra" >> $LLOC/ZM-FB-$DATE.log
  echo "Status $?" >> $LLOC/ZM-FB-$DATE.log
  sleep 20
}

function zmstatus() {
  echo "--------------------------------------------" >> $LLOC/ZM-FB-$DATE.log
  echo "Zimbra Status :-" >> $LLOC/ZM-FB-$DATE.log
  /bin/su - zimbra -c '/opt/zimbra/bin/zmcontrol status' >> $LLOC/ZM-FB-$DATE.log
  sleep 20
}

function tarbk() {
  echo "--------------------------------------------" >> $LLOC/ZM-FB-$DATE.log
  echo "Starting backup on `date +%c`" >> $LLOC/ZM-FB-$DATE.log
  echo "Backing up $ZMHOME :-" >> $LLOC/ZM-FB-$DATE.log
  /bin/tar -zpcf $BKDIR/zimbra-$ZMBVER-$DATE.tgz $ZMHOME
  echo "Tar exit exist status $?" >> $LLOC/ZM-FB-$DATE.log
}

function chktar() {
  echo "--------------------------------------------" >> $LLOC/ZM-FB-$DATE.log
  echo "Checking status of tarball :-" >> $LLOC/ZM-FB-$DATE.log
  /bin/tar -df $BKDIR/zimbra-$ZMBVER-$DATE.tgz -C $TARTL >> $LLOC/ZM-FB-$DATE.log
  echo "Tarball integrity $?" >> $LLOC/ZM-FB-$DATE.log
}

function encbk() {
  echo "--------------------------------------------" >> $LLOC/ZM-FB-$DATE.log
  echo "Encripting file zimbra-$ZMBVER-$DATE.tgz" >> $LLOC/ZM-FB-$DATE.log
  echo "Output :- zimbra-$ZMBVER-$DATE.tgz.gpg" >> $LLOC/ZM-FB-$DATE.log
  /usr/bin/gpg -es -r $GPGUSR $BKDIR/zimbra-$ZMBVER-$DATE.tgz
  echo "GPG exit status $?" >> $LLOC/ZM-FB-$DATE.log
}

function killzm() {
  echo "--------------------------------------------" >> $LLOC/ZM-FB-$DATE.log
  echo "Killing all Zimbra owned process" >> $LLOC/ZM-FB-$DATE.log
  /usr/bin/pkill -9 -u zimbra
  echo "Kill status $?" >> $LLOC/ZM-FB-$DATE.log
}

function bkend() {
  echo "--------------------------------------------" >> $LLOC/ZM-FB-$DATE.log
  echo "Backup and GPG ended on `date +%c`" >> $LLOC/ZM-FB-$DATE.log
  echo "--------------------------------------------" >> $LLOC/ZM-FB-$DATE.log
  echo zimbra-$ZMBVER-$DATE.tgz.gpg > /tmp/curzmbk
}

function mailrpt() {
  /bin/cat $LLOC/ZM-FB-$DATE.log | /bin/mail -s "Backup Report for `date +%c`" DESTINIATION@EMAIL
}

loghd
zmstop
killzm
zmstatus
tarbk
chktar
encbk
zmstart
zmstatus
bkend
mailrpt