BLOG MOVED

Posted in Uncategorized on 16/05/2013 by Undersys

MOVED

You should not be hear anymore…
Please go to http://lepig.net

Please update any hyperlinks you may of had pointing to “lpig.wordpress.com”, please point them at http://lepig.net

Saleae Logic — Gentoo Linux

Posted in HowTo on 13/04/2013 by Undersys

Certain company’s to me deserve my cash.. and that’s not easy.
Saleae is one of them. Saleae produces logic analyzer’s and 8 channel and a  16 channel version.

Logic analyzers are quite common and most of them are desk side stand alone units. Where Saleae differs is there logic analyzer  connects to your USB port.
Whats even better is this…

$ file Logic
Logic: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped

That’s right, the software that interfaces the to the logic unit has a NATIVE Linux port. In fact there is a native version for Windows,Mac and Linux in both 32bit and 64bit! Not some shitty wine app or java rubbish its a pure native port and it works very well on every operating system. You can see why I like Saleae now!

Before you ask, in no way did Saleae make me or ask me to write about there device, I am doing it because its amazing.

I have brought the 8 channel version as I can’t see my self needing anymore channels then 8 but you can always have more then one right!

There is also another reason why I like Saleae’s product.
Its well made, comes in a nice case and is VERY small
You can see the logic and its attached probes in the below image.
IMG_0248
That’s a standard SD card in the image to show you how small the logic really is.
Saleae also include the little probe clips, but you can just plug the end of the wires into a pin header if you want to.

The main set of 8 wires easily unplugs from the main logic unit to store easily in the provided case.

Now time to make it work!

To get the Logic detected under Linux you will need very little.
1) Kernel support for Cypress FX2.
2) LibUSB 0.1 (Legacy).

For number 1 You need to add FTDI_SIO support to your kernel :

CONFIG_USB_SERIAL_FTDI_SIO=m

For number 2 you need to emerge the following package :

dev-libs/libusb-compat

Once you have the above two things, go ahead and plug the, if all has gone well dmesg will print something like this :

[950447.239197] usb 1-1.5.2: new high-speed USB device number 14 using ehci-pci
[950447.324654] usb 1-1.5.2: New USB device found, idVendor=0925, idProduct=3881
[950447.324658] usb 1-1.5.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[950447.324662] usb 1-1.5.2: Product: Logic
[950447.324672] usb 1-1.5.2: Manufacturer: Saleae LLC

Now that your Logic is detected go do the download page and get your software.  The Linux package is labeled as “ubuntu”. Lucky for the rest of us Linux people its just a zip file that you can unpack anywhere and run the Logic application.
I like to extract it under /opt but you can run it anywhere you like.

You can see in the below image a test I did with my logic, the software interface is clean and easy to use but feature rich.logic-test
Click the above to get a higher res image.

owncloud on Centos with nginx and mysql

Posted in HowTo on 08/04/2013 by Undersys

In this post I am going to show you how to install the free owncloud server.
I will be using Centos , Nginx , mysql and PHP-FPM .

I am not a huge fan of Apache, hence why this guide has nginx!
Sadly some our dependencies  will pull in Apache web server under Centos.
Not to worry just don’t enable Apache/httpd.

Lets get stuck into it.

1)
Firstly Disable selinux
Edit the  file “/etc/selinux/config” and ensure the selinux is disabled :

SELINUX=disabled

2)
Next your going to need to add in the ngix repo
Create the file “/etc/yum.repos.d/nginx.repo” and enter the following into it :

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

3)
Now its time to install all the packages you will need to run owncloud.

Install :

yum install mysql mysql-server
yum install nginx
yum install php php-gd php-xml-parser php-intl php-mysql php-mbstring php-xml php-fpm php-pear php-devel pcre-devel

Not the above command will pull in httpd! Yuck! Sadly you have no choice on Centos :

# repoquery --requires php
httpd
httpd-mmn = 20051115
...SNIPED OUTPUT.."

That’s OK. Just don’t enable the silly thing.

Lastly since you’re using nginx and not apache you need to fix the default php cache directory permissions. Run the following :

# chown -R root:nginx /var/lib/php/

Ensure to start nginx and set it to start on boot :

# service nginx start
# chkconfig nginx on

4)
Since nginx has no way to spawn a php process, unlike apache with mod_php you need to have anoter proces that can handle the php requests. This is where php-fpm comes into play.

You need to configure a few settings first.

The first settings are for the main server settings.
Edit the file “/etc/php-fpm.conf” set the following :

log_level = notice
emergency_restart_threshold = 10
process_control_timeout = 10s

Next you need to fix up the worker config file :
Edit the file” /etc/php-fpm.d/www.conf” and set the following:

user = nginx
group = nginx

You also need to fix the permissions for the php-fpm log directory.
Run the following command :

chown nginx:nginx -R /var/log/php-fpm/

Enable services to start on boot :

# service php-fpm start
# chkconfig php-fpm on

3)
Now its time for Mysql ( You could try MariaDB if your feeling lucky). For now I will stick with Mysql.

First you need to start mysql and while your at it, set it to start on boot :

# service mysqld start
# chkconfig mysqld on

Now run teh first time install wizard :

/usr/bin/mysql_secure_installation

Set a root password to something secure.
Answer the questions with the following responses :

Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

4)
Since your going to use the tarball install rather then the RPM package your going to need to create your databases and privileges for owncloud.

Log into mysql as the root user :

# mysql -u root -p"

Give it the root password you set during the start up script.

Now run the following SQl to create the database and assign privileges:

mysql> create database owncloud;
mysql> GRANT ALL PRIVILEGES ON owncloud.* TO "mycloud"@"localhost"  IDENTIFIED BY "password";
mysql> flush privileges;
mysql> quit

DO set a better password. DO NOT use the same password as the root account or any other account. This password will be stored in plain text !

4)
Now its time to unroll the owncloud files into the server.
Install the latest OwnCloud distribution (Select Tar or Zip File) from
http://owncloud.org/install/

At the time of this article I used the command :

# wget http://download.owncloud.org/community/owncloud-5.0.3.tar.bz2

Extract the tarball into your web servers www directory ( or where ever you configured it). In my case :

# tar -xvf owncloud-5.0.3.tar.bz2 -C /cloud/www"

I will configure nginx to serve files form this directory later.

You will also need to set the correct permissions :

chown -R nginx:nginx /cloud/www/

5)
You could skip this section and run everything in plain text but that would be stupid. I will be using NameCheep's Comodo PositiveSSL certificate, as I've used them many times

First up create the ssl working directory for nginx

# mkdir /etc/nginx/ssl

Now change into that directory, its time to create the key and csr request.

# cd  /etc/nginx/ssl
# openssl genrsa -des3 -out DOMAIN_NAME.COM.key 2048

Enter a password when prompted by the above command, the password is not important  we will remove it soon. Replace DOMAIN_NAME.COM with your fully qualified server domain name.

Now generate the CSR :

#  openssl req -new -key DOMAIN_NAME.COM.key -out DOMAIN_NAME.COM.csr

Answer the questions and make sure the server common name matches your fully qualified domain name. You don't need to enter the "extra" attributes.
The contents of the .csr file is what I will give to my certificate issuer.

Remove the password from the key with the following commands :

# mv DOMAIN_NAME.COM.key DOMAIN_NAME.COM.org
# openssl rsa -in  DOMAIN_NAME.COM.org -out  DOMAIN_NAME.COM.key

Enter the password for the last time, now the .key file will have no password.

Now upload the contents of the .csr file to NameCheep, select server type of "Other". Then wait for the approval email from NameCheep.

Once you have zip file that contains the certificate, root certificate and intermediate certificate. You need to bundle them into a .pem file for nginx. Unzip the bundle anywhere we will copy pem file to the correct location later.
Create the .pem bundle with the following commands :

# cat DOMAIN_NAME.COM.crt > DOMAIN_NAME.COM.pem
# cat PositiveSSLCA2.crt >  DOMAIN_NAME.COM.pem
# cat AddTrustExternalCARoot.crt > DOMAIN_NAME.COM.pem

Now copy the DOMAIN_NAME.COM.pem file into /etc/nginx/ssl directory.

6)
Finally its time to configure nginx it self.
The first file your going to set up will be the main server config file. You can find it at "/etc/nginx/nginx.conf"
Open it and replace all the contents with the below :

## Server Config
user				nginx;
worker_processes  		1;

error_log  			/var/log/nginx/error.log warn;
pid        			/var/run/nginx.pid;

events {
worker_connections 	 	1024;
multi_accept                  on;
use 				epoll;
}

## Server Config END

http {
## Types mapping
include       		/etc/nginx/mime.types;
default_type  		application/octet-stream;

## Types mapping END

## Main Server log settings
log_format  main  		'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log  			/var/log/nginx/access.log  main;
## Main Server log settings END

## MISC server settings
sendfile        		on;
server_names_hash_bucket_size 64;

## MISC server settings END

## GZIP Settings
gzip  			on;
gzip_static       		on;
gzip_vary         		on;
## GZIP Settings END

## Security Settings
# Turn off srv version
server_tokens 		off;
# Set client requst body buffer
client_body_buffer_size  	1K;
# set client header buffer
client_header_buffer_size 	1k;
# Max size of client body request
client_max_body_size 		1k;
# Max large size of header/buffer to read from client
large_client_header_buffers 	2 1k;
# Read timeout for client body
client_body_timeout   	10;
# Timeout to read client header
client_header_timeout 	10;
# timeout for keepalive andheader keep alive
keepalive_timeout     	5 5;
# Timeout for client responce
send_timeout          	10;
## Security Settings END

## Include Server Blocks
include /etc/nginx/conf.d/*.conf;
## Include Server Blocks END

The next file defines the server blocks and there settings.
Create a file "/etc/nginx/conf.d/" Give it a name like DOMAIN_NAME.COM.conf. The following was mostly taken from the owncloud install guide . With a few modifications for my needs.

server {
  listen               [::]80;
  server_name          DOMAIN_NAME.COM;
  rewrite              ^ https://$server_name$request_uri? permanent;
}

server {
  listen       	       [::]:443;
  server_name 	       DOMAIN_NAME.COM;
  access_log 	       /var/log/nginx/access.log main;
  error_log	       /var/log/nginx/error.log warn;
  root 		       /cloud/www/owncloud;
  ssl 		       on;
  ssl_certificate      /etc/nginx/ssl/DOMAIN_NAME.COM.pem;
  ssl_certificate_key  /etc/nginx/ssl/DOMAIN_NAME.COM.key;
  client_max_body_size 10G;
  fastcgi_buffers 64   4K;
  rewrite              ^/caldav((/|$).*)$ /remote.php/caldav$1 last;
  rewrite              ^/carddav((/|$).*)$ /remote.php/carddav$1 last;
  rewrite              ^/webdav((/|$).*)$ /remote.php/webdav$1 last;
  index                index.php;
  error_page 403 =     /core/templates/403.php;
  error_page 404 =     /core/templates/404.php;

  location ~           ^/(data|config|\.ht|db_structure\.xml|README) {
  deny                 all;
}

location               / {
  rewrite              ^/.well-known/host-meta /public.php?service=host-meta last;
  rewrite              ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
  rewrite              ^/.well-known/carddav /remote.php/carddav/ redirect;
  rewrite              ^/.well-known/caldav /remote.php/caldav/ redirect;
  rewrite              ^(/core/doc/[^\/]+/)$ $1/index.html;
  try_files            $uri $uri/ index.php;
}

location = 	       /favicon.ico {
  return 	       204;
  access_log           off;
  log_not_found        off;
}
  
location ~             ^(.+?\.php)(/.*)?$ {
  try_files            $1 = 404;  
  include              fastcgi_params;
  fastcgi_param        SCRIPT_FILENAME /cloud/www/owncloud$fastcgi_script_name;
  fastcgi_param        HTTPS on;
  fastcgi_pass         127.0.0.1:9000;
}

location ~* 	       ^.+\.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
  expires              30d;
  access_log           off;
  }
}

Ensure you change all the "DOMAIN_NAME.COM" to your real servers fully qualified domain name.

Restart nginx after changing the above to config files.

7)
To be able to upload any files bigger then 1MB you need to edit the php.ini file.

Open the file "/etc/php.ini" and set the following :

upload_max_filesize = 8G
post_max_size = 10G

This will allow you to upload an 8GB file, Set the vales to something that makes sense to you.

8)
So very close now. Browse to your servers DNS name.
Enter a username and password for the owncloud admin account.
Try make this different too.
Next select the "advance install" drop down item.
Select "mysql" and enter the DB user,pass and DB name.
The above details are what you set up in step 4.

After that, create some users and have fun!.

There are obviously more things that can/could be done. Server Harding, mysql tuning better data structure placement etc but I will leave that up to you.
The above guide will get you a functional owncloud install with Nginx m Mysql and php-fpm.
Enjoy!

Sleep I miss thee

Posted in Personal on 12/01/2013 by Undersys

A Book???

A book and no sleep :D

Shenzhen Electronics Market

Posted in Personal on 03/09/2012 by Undersys

This will be my last post for a while as I have a big side project on the go. More on that much later on approx early 2013.

Today I went to visit the Shenzhen Electronics Market in China. Its only 40mins away from where I live so its not hard to get to.
If you are ever in China do stop by the Shenzhen Electronics Market. You want the Huaqiang Rd stop on the
Luobao Line line, take exit “A” .
My favorite two shopping centers are the SEG plaza and the Huaqiang electronics world. Seg is a massive 12 story building that has everything from small components all the way up to full PC’s and laptops. (careful about fake goods). Huaqiang electronics world is in the Huaqiang building and has an amazing range of every component and chip VGA chips, MCH’s, DRAM everything you wanted and did not want! Its also quite tall at five stories.

Some DRAM by the tray..

MOAR!

Hear is SEG, well part of it it huge.
Some reels of components:-
And small stores of LCD:-

You can see all the pictures on my flicker

Cowan iAudio x5 repair

Posted in HowTo on 26/07/2012 by Undersys

I use an Cowon iAudio x5 with Rockbox  to play my ogg vorbis files.

Its quite an old player now, but it fits my needs and I don’t see the point of buying new stuff when this works.
As expected I’ve had to replace a few batteries in it not a big deal.
I’ve also fixed the headphone jack as it had come loss some time a go. ( you can see the white pad on top to give it more pressure in the images below)

All of the x5 owners know about the little joy stick and how quickly it fails.
Mine had been on the way out for around a year now(pretty good given its close to 5 years old), back stopped working then down, then select now its useless.

Me been me, I guessed I could fix it! Your going to need to find a replacement joystick. No idea who made the original or what the part number is. After a lot of reading I found the “TPA511GLFS” made by ck components.

You can buy this online via Mouser or Digikey. I got mine via Digikey. There part number is 401-1130-6-ND Digikey will sell in one lot quantities so that works for me.

Your going to need a decent Soldering Iron, personalty I recommend Hakko. I used the FX-888 for this work.

So hear we go!

1)
Undo the four screws at the back of the unit. Remove the tape holding down the wires. Keep the tape.
2)
Remove the HDD by sliding the front edge of the battery (where the connector is) forward and up its a little tight! Unclip the HDD from the main PCB by gently lifting upwards on the connector.
Now remove the headphone and FM assembly along the top of the unit. Undo two black screws and lift gently from the opposite side to the headphone jack.
Remove the black HDD  protector.
Your player should look like this :-

3)
Now unscrew all the black screws you can find, there are lot! Also remove the two silver screws at the base of the unit holding down the metal HDD clip.
At this point I also un solder the  battery to get it out of the road and as a safety measure. Note the pad with the box is the positive wire and the  far side is the negative wire the middle pad is not used.
Now your ready to remove the main PCB. Undo the tape and keep it. Remove the black support  near the white plug on the top of the unit.
Now lifting gently from the side with the USB port at the top of the unit. Lift upwards take care of the switches they are very fragile.  If you need to bend the plastic a bit near the switches and the USB port. Once you have cleared that pull the board towards the top of the player and out of the case. Turn the main board over it should look like this.
The silver joystick cover can now be popped off. along with the sticky sponge.
Hear is the bare switch:-
4)
De-solder the switch. I like to use de soldering braid but what ever method works for you.
Switch removed, need to clean the pads lots of flux :-
5)
Position the new switch as close to where the old one was a possible. The pads allow for a lot of moment and if your to far left or right you’re joystick will miss the hole! The pins line up exactly as the old switch.
New switch on :-
5)
Reassemble the unit and test all functions. The main PCB be be fiddly to get back in. I like to insert the bottom connector first then push the USB plug down and slowly push down on the side with the switches taking good take to not brake the switches.

Your done!

References :-
Data sheet for the switch.
My Flicker (full size images)

HP’s PCI web console card a5858a — setup guide

Posted in HowTo on 22/07/2012 by Undersys

Well after a few years oh my web console card in my HP J6750 running fine.  After the move to HK it stopped responding on its IP.

Ok years have passed  and I have no idea what the default IP was or even how to reset this thing back to factory defaults.

Do recall this is a factory install option only on the rp24xx series. So documentation is a little sparse.
If your wondering how to power it see this post I wrote about how to power the card.

To reset the unit back to factory defaults do this :-
1) Press and hold Switch two (this is the switch closest to the serial port)
2) Press and hold Switch one (this is the switch closest to the LAN port)
3) Let go of Switch two, the lights should flash then let go out Switch one.

Default IP is always 192.0.0.192.
Browse to that IP address and you will be greeted with a setup page for the web console.
After your done access the web console on your new IP.

I have a few pages on the web console you can download it hear.

New system!

Posted in Personal, Projects on 17/05/2012 by Undersys

Well its done.

The last few months I’ve been working on a new system to replace my laptop.

Specs :-
* Asus  Maximus IV GENE-Z/GEN3
* Intel Core i7 2600s
* 16GB DDR 3
* 1x Corsair M3pro 256gb SSD SATA 6g
* 2x Hitachi 2.5″ 500gb 7200RPM SATA 6G HDD’s
* Zotac Geforce 460se
* Seasonic X series 650w

Cooling :-
* XSPC raystorm
* XSPC Full cover block for Geforce 460
* Black ice SR 2×120 Radiator
* Swiftech DDC 2.3 with XSPC top
* Bitspower multi res
* Tygon 3/8ID hose
* late-loom fans

On Desk :-
* Dell U3011 , Wall mounted
* Asus SBW-06D2X-U USB bluray BDXL writer
* Ducky 82key mechanical keyboard (brown switches)
*  Logitech Marathon cordless mouse
* Pair of Genelec 8020a

Running Gentoo of course !
Idle Temps are CPU 38c | GPU 34c Celsius.
Conky set up to monitor temp’s fan and pump RPM’s and HK current weather including warnings
You can see the images of the build on my flicker

Hears a teaser..

 

Hears a shot of my Conky  :-

 

 

 

 

 

 

 

 
Leave me a note if you want the scripts and conkyrc.

Arduino 1.0 and Gentoo

Posted in HowTo on 14/04/2012 by Undersys

It has been a while since I used my Arduino.
Of course when I go to use it there is a new version of the software out 1.0.
As expected it won’t work out of the box on Gentoo.
Make sure you give my existing article a read though if you have other issues.

I had to change two things.

1)

I got the following error :-


~/arduino-1.0/hardware/arduino/cores/arduino/Print.cpp: In member function ‘size_t Print::print(const __FlashStringHelper*)’:
~/arduino-1.0/hardware/arduino/cores/arduino/Print.cpp:44:9: error: ‘prog_char’ does not name a type
~/arduino-1.0/hardware/arduino/cores/arduino/Print.cpp:47:23: error: ‘p’ was not declared in this scope

It appears that Print.ccp is using depricated typedef.
avr-libc v1.8.0 and up have deprecated the “prog_char” type def and now its recommended to use of “char PROGMEM”.

So lets fix that…
Bash open the the “Print.ccp” file for me this is located at :-
~/arduino-1.0/hardware/arduino/cores/arduino/Print.cpp

On line 42 you will find the offending secion :-

size_t Print::print(const __FlashStringHelper *ifsh)
{
 const prog_char *p = (const prog_char *)ifsh;
 size_t n = 0;
 while (1) {
 unsigned char c = pgm_read_byte(p++);
 if (c == 0) break;
 n += write(c);
 }
 return n;
}

Lets replace that section with one that supports new versions of avr-libc :-

size_t Print::print(const __FlashStringHelper *ifsh)
{
 const char PROGMEM *p = (const char PROGMEM *)ifsh;
 size_t n = 0;
 while (1) {
 unsigned char c = pgm_read_byte(p++);
 if (c == 0) break;
 n += write(c);
 }
 return n;
}

2)
After that I now got the following error :-
/usr/libexec/gcc/avr/ld: cannot open linker script file ldscripts/avr5.x: No such file or directory

Hmm we’ve seen this shit before, check my existing article.
Easy fix as root create the following symlink:-
# ln -s /usr/x86_64-pc-linux-gnu/avr/lib/ldscripts /usr/avr/lib/ldscripts

Done. If your lucky it should work correctly now!

Network/SQL multi host Emerge for Gentoo

Posted in Code on 09/03/2012 by Undersys

I have a lot of Gentoo hosts. Going to each one of them and running emerge xxxx what ever is really annoying.
Its also a waste of my time.  I set out to fix that.

Design goals are :-
1) Can query a SQL DB to find out what hosts need updating.
2) Can run against a single host or many hosts.
3) Can preform emerge sync, revdev- rebuld, emerge packages and tell me what needs uptating in etc.
4) Can run from a central host.
5) Can run from a crontab and generate a log file for me to inspect later.

Currently I can do this :-

./genhstutil.rb
Preform maintenance on mutiple Gentoo hosts over the network

Usage:
 [options] {host} or {package}
 where {package} is the name of a gentoo package atom
 where {host} is the dns name of a host
 where [options] are:
 --esync, -e: Run emerge sync on {host}
 --breif, -b: Get a one line package update summary on {host}
 --detail, -d: Get a detailed package update list on {host}
 --world, -w: Emerge world on {host}
 --system, -s: Emerge system on {host}
 --revdep, -r: Run revdep rebuild on {host}
 --ipkg, -i: Install {package} on a {host}
 --etcup, -t: Check a host for etc-updates
 --esync-all, -y: Run 'esync' on all Gentoo hosts
 --breif-all, -f: Run 'breif' on all Gentoo hosts
 --detail-all, -a: Run 'detail' on all Gentoo hosts
 --ipkg-all, -p: Install package on all Gentoo hosts
 --world-all, -o: Run emerge world on all Gentoo hosts
 --system-all, -m: Run emerge system on all Gentoo hosts
 --revdep-all, -v: Run revdep-rebuild on all Gentoo hosts
 --echall-all, -c: Check all Gentoo hosts for etc-updates
 --help, -h: Show this message

There a few things that need to be done before this code will work.
1) you need to have an user set up on each host, in my example I have called the use “maint” currently I use a password to access the hosts rather then ssh keys.
2) sudo to be installed anc configured like this :-

maint ALL = NOPASSWD: /usr/bin/emerge, /usr/bin/rsync, /usr/bin/revdep-rebuild, /usr/bin/find

3) A SQL database that can be accessed over the network, see the attached schema.

You will need to rename the files from .doc to to .rb and .sql as wordpress won’t allow me upload anything else.
Gentoo Host ruby script
Gentoo Host sql schema