<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<?xml-stylesheet type="text/css" href="http://linuxevolution.org/styles/feed.css"?>


<title type="html">Linux Evolution dot org and the NSLU2</title>
<subtitle type="html"></subtitle>
<link rel="alternate" type="text/html" href="http://linuxevolution.org"/>
<link rel="self" type="application/atom+xml" href="http://linuxevolution.org/atom.xml"/>
<updated>2010-07-30T18:00:04-04:00</updated>
<author>
<name>orvtech</name>
<uri>http://linuxevolution.org</uri>
</author>
<id>http://linuxevolution.org/</id>
<generator uri="http://nanoblogger.sourceforge.net" version="3.4">
NanoBlogger
</generator>

<entry>
<title type="html">Limit the space of a samba share without using disk quotas</title>
<author>
<name>orvtech</name>
</author>
<link rel="alternate" type="text/html" href="http://linuxevolution.org/archives/2010/07/26/limit_the_space_of_a_samba_share_without_using_disk_quotas/index.html"/>

<id>http://linuxevolution.org/archives/2010/07/26/limit_the_space_of_a_samba_share_without_using_disk_quotas/index.html</id>
<published>2010-07-26T11:31:54-04:00</published>
<updated>2010-07-26T11:31:54-04:00</updated>

<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">

<p>
Recently a friend of mine asked me if it was possible to limit the amount of space taken up by a user on a 
samba share without using disk quotas. I assumed it could be done through the smb.conf but since I have 
never worked with samba I wasn't sure. A bit of research here and there came to nothing so I decided to 
write a script and solve this problem the dirty way. My friend manages a small network where users run 
workstations with <abbr title="Microsoft">MS</abbr> Windows.
</p>

<p>
First things first, let's create a file containing the usernames and the amount of space we want to give 
them. Something like this:
</p>
<pre># cat /tmp/smbusers.txt 
maria.perez,5
arnaldo.hernandez,5
gustavo.flores,10
jesus.boss,5
marta.hernandez,5
wilkneman.pascoski,5
tatiana.siu,5
alexandra.delarosa,5</pre>
<br />

<p>
Using this information I need to create the configuration to be appended to the smb.conf; it needs to have 
the following format:
</p>
<pre>[alexandra.delarosa]
comment = alexandra.delarosa with 5MB
path = /mnt/smb_discs/alexandra.delarosa
read only = no
browseable = yes
guest ok = yes

[arnaldo.hernandez]
comment = arnaldo.hernandez with 5MB
path = /mnt/smb_discs/arnaldo.hernandez
read only = no
browseable = yes
guest ok = yes

[gustavo.flores]
comment = gustavo.flores with 10MB
path = /mnt/smb_discs/gustavo.flores
read only = no
browseable = yes
guest ok = yes</pre>
<br />
<p>
Here is the script which basically reads the list of users and how much space they are allowed to use and 
creates disk images using the command dd, then it mounts each of these images as loop back devices and 
creates a file with the information that has to be appended to the smb.conf file.
</p>
<pre>LISTASMBUSERSS=`cat /tmp/smbusers.txt|sort`
PATH_TO_DISKS="/smb_disks/smb_drives"
MOUNT_SMB="/mnt/smb_discs"
TMPSAMBACONF="/tmp/samba.virt.conf"
echo &gt; $TMPSAMBACONF
mkdir -p `echo $PATH_TO_DISKS`
for X in $LISTASMBUSERSS
do echo $X | awk -F , '{print "assigning " $2 "MB to smb_user "$1}'
  SMBUSERS=`echo $X | awk -F , '{print $1}'`
  PRE_SMBQUOTA=`echo $X | awk -F , '{print $2}'`
  let SMBQUOTA=`echo $PRE_SMBQUOTA`*1024
  dd if=/dev/zero of=$PATH_TO_DISKS/$SMBUSERS.img bs=1024 count=$SMBQUOTA
  /sbin/mke2fs -L $SMBUSERS -j $PATH_TO_DISKS/$SMBUSERS.img 
  mkdir -p $MOUNT_SMB/$SMBUSERS
  mount -t ext3 $PATH_TO_DISKS/$SMBUSERS.img -o loop $MOUNT_SMB/$SMBUSERS
  echo "[$SMBUSERS]
    comment = `echo $SMBUSERS" with "$PRE_SMBQUOTA"MB"`
    path = /mnt/smb_discs/$SMBUSERS
    read only = no
    browseable = yes
    guest ok = yes
    " &gt;&gt; $TMPSAMBACONF
done
echo "Used space in $PATH_TO_DISKS: "
du -smh $PATH_TO_DISKS/*.img
du -smh $PATH_TO_DISKS/
mount -l | grep $MOUNT_SMB
echo "CHECK $TMPSAMBACONF AND ADD IT TO YOUR /etc/samba/smb.conf"</pre>

<br />
<p>
My friend would just have to add the output of the script located in <i>/tmp/samba.virt.conf</i> to his 
<i>/etc/samba/smb.conf</i> and restart the service.
</p>

<p>
Please note that I have never worked with Samba before so if you know a better way to do this without using 
disk quotas please let me know.
</p>
<br />
<br />
<p><i>
<b title="Spanish version">Original Article (spanish version):</b> <a href="http://www.orvtech.com/archives/2010/06/25/limitar_el_espacio_de_una_carpeta_sin_usar_cuotas_en_samba/index.html" hreflang="es" rev="alternate">Limitar el espacio de una carpeta sin usar cuotas en Samba.</a>
</i></p>
</div>
</content>

</entry>
<entry>
<title type="html">Shell script to backup NanoBlogger to a remote server </title>
<author>
<name>orvtech</name>
</author>
<link rel="alternate" type="text/html" href="http://linuxevolution.org/archives/2010/06/09/shell_script_to_backup_nanoblogger_to_a_remote_server/index.html"/>

<id>http://linuxevolution.org/archives/2010/06/09/shell_script_to_backup_nanoblogger_to_a_remote_server/index.html</id>
<published>2010-06-09T16:23:49-04:00</published>
<updated>2010-06-09T16:23:49-04:00</updated>
<category term="Scripts" />
<category term="Linux" />
<category term="nanoblogger" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>This is a simple script that creates full backups of our NanoBlogger blog by compressing our DocumentRoot directory and upload it to a remote server via SCP.</p>

<p>Lets take a look at it:<br />
<pre>#!/bin/bash
BLOG_PATH="/path/to/the/directory/that/contains/your/blog.conf/"
BLOG_NAME="orvtech.com"
DATE=`date +%d%b%Y-h%Hm%M`
NO_BAKUP="cache/*"
SCP_SERVER="<your_server_here>"
SCP_USER="<your_ssh_login_here>"
SCP_PORT="22"

cd $BLOG_PATH
tar -czpsf ~/$BLOG_NAME-nanoblogger.$DATE.tar.gz --exclude "$NO_BAKUP" *
ls -lah  ~/$BLOG_NAME-nanoblogger.$DATE.tar.gz
scp -P$SCP_PORT ~/$BLOG_NAME-nanoblogger.$DATE.tar.gz $SCP_USER@$SCP_SERVER:~/</pre>
</p>
<br />
<p><i>
<b>Spanish version:</b> <a href="http://www.orvtech.com/archives/2010/06/10/respaldar_nanoblogger/index.html">Respaldar NanoBlogger.</a>
</i></p>
</div>
</content>

</entry>
<entry>
<title type="html">Find the biggest file or folder inside a directory.</title>
<author>
<name>orvtech</name>
</author>
<link rel="alternate" type="text/html" href="http://linuxevolution.org/archives/2010/05/18/find_the_biggest_file_or_folder_inside_a_directory/index.html"/>

<id>http://linuxevolution.org/archives/2010/05/18/find_the_biggest_file_or_folder_inside_a_directory/index.html</id>
<published>2010-05-18T10:57:05-04:00</published>
<updated>2010-05-18T10:57:05-04:00</updated>
<category term="OneLiners" />
<category term="Scripts" />
<category term="NSLU2" />
<category term="Linux" />
<category term="iPhone" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>
By using the `du` command we can find the biggest file or directory inside a folder. The next example shows how to list the 10 most biggest files and floders inside 'HOME'
</p>

<pre>du -a ~/ | sort -n -r | head -n 10</pre>

<br />

<p>
If we use the `find` command we can list the 10 biggest files inside a directory, even if they are inside sub-folders.
</p>

<pre>find ~/ -type f -exec ls -ls {} \; | awk '{print $6"\t"$9}' | sort -k1 -n -r | head -n 10</pre>
</div>
</content>

</entry>
<entry>
<title type="html">Web interface for NanoBlogger: Add entries.</title>
<author>
<name>orvtech</name>
</author>
<link rel="alternate" type="text/html" href="http://linuxevolution.org/archives/2010/04/21/web_interface_for_nanoblogger_add_entries/index.html"/>

<id>http://linuxevolution.org/archives/2010/04/21/web_interface_for_nanoblogger_add_entries/index.html</id>
<published>2010-04-21T15:55:50-04:00</published>
<updated>2010-04-21T15:55:50-04:00</updated>
<category term="Scripts" />
<category term="NSLU2" />
<category term="nanoblogger" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>
Please bare in mind that this is a proof of concept (that works) but here it is a web interface that allows you to submit entries to NanoBlogger through a BASH CGI. The script is rather simple, it just takes the fields title, description and body then writes it to a text file, you can latter process it through a cronjob or just leave it there for then you get a chance parse it by nb.
</p>

<p>
For this we will be using 3 code segments, the first would be the HTML form that will allow us to enter the content and pass those values to the CGI besides those two we have a javascript segment that allow us to preview the actual article that we are submitting.

</p>

<p>
<b>The Form.</b><br />
In other to have a bit of eye-candy i decided to use the heather and cascade style sheet from the actual style i am using for NanoBlogger. I found that the easiest way was to create a file by running `nb -b /path/of/the/blog/ make-file nb_send_entry.txt`. This will create a template that we can use to add the form HTML inside the 'BODY' section.
</p>


<textarea  style="height: 140px"  class="bashcode">
<form name="nb_entrada_send" method="post" ACTION="http://www.orvtech.com/send_nb_entry.cgi"><table border="0" width="600">
<tr>
<td width="100px">Titulo:</td>
<td width="500px"><input type="text" size="60" maxlength="50" id="title" name="entrada_title" value="Enter Title Here"></td>
</tr>
<tr>
<td width="100px">Descripcion:</td>
<td width="500px"><input type="text" size="60" maxlength="100" id="description" name="entrada_description" value="Enter Description Here"></td>
</tr>
<tr>
<td colspan=2>Contenido:<br />
< textarea cols="75" rows="30" id="body" name="entrada_body">
HTML esta permitido.
</ textarea>
</td>
</tr>
<tr>
<td width="600" colspan="2">
<div align="center "style="margin: auto; align: center; width: 600px;">
<input type="button" name="preview" value="Vista Previa" onclick="return openPreview();" />
&nbsp;&nbsp;<input type=submit value="Enviar" />&nbsp;&nbsp;
<input type="reset" value="Cancelar" />
</div>
</td>
</tr>
</table></form></textarea>


<p>
The product of this code is a web page with the same look and feel that the blog has. Here is a sample from our Spanish site:
</p>
<div><img src="http://www.orvtech.com/images/entry_form_screensho1.png" /></div>
<p>
<b>The JavaScript.</b><br />
If you take a look at above source code we have a 'preview' button; this button calls the function openPreview. The idea of this function is to show how would the HTML that we are codding look using the current style. You can get a good idea on how would this entry look before you submit it. Here is the code:
</p>



<textarea  style="height: 140px"  class="bashcode">
<script language="JavaScript">
function openPreview()
{
features = 'width=800, height=600, toolbar=no, menubar=no, resizable=no, location=no, directories=no, status=no';
var popWin = window.open ('','Preview_Entry', features);

var popTitleText = popWin.document.getElementById("title");
var titleText = document.getElementById("title");
var popBodyText = popWin.document.getElementById("body");
var bodyText = document.getElementById("body");

popWin.document.writeln('<head><title>Submit an Entry | Linux y el NSLU2</title><link rel="stylesheet" href="/styles/nb_default.css" type="text/css" media="all" /><link rel="shortcut icon" href="/favicon.ico" /></head><body> <div class="border"> <div class="container">  <div id="topmenu">  <ul>  <li><a href="/index.html" title="Inicio"><span>Inicio</span></a></li>  <li><a href="/gallery.html" title="Galería"><span>Galería</span></a></li>  <li><a href="/archives/scripts/index.html" title="BASH Scripts"><span>Scripts</span></a></li>  <li><a href="/articles/el_nslu2/" title="El NSLU2"><span>El NSLU2</span></a></li> <li><a href="/archives/scripts/index.html" title="Linux"><span>Linux</span></a></li> <li><a href="http://www.orvtech.com/index.html" title="orvtech.com in english"><span>In English</span></a></li>  </ul>  </div> <div id="header"></div><div class="container"><div class="archives"><div class="blogbody"> <h3 class="title">' + titleText.value + '</h3>' + bodyText.value + '</div></div></div></div></div></body>');

popTitleText.value = titleText.value;
popWin.document.close();
}
</script></textarea>



<p>
As you can see we are defining a new window and opening it with the content we entered on the form, it uses the nb_default.css. Most of the customizations can be done on in popWin.document.writeln in case you want to adapt it to your blog.
Remember that this is a proof of concept and that it can still be improved, perhaps we can latter make it to read the blog.conf file. Here is a screenshot of how it looks. 
</p>
<div><img src="http://www.orvtech.com/images/entry_form_screensho1.png" /></div>

<p>
<b>All you need is BASH.</b><br />
A CGI codded in bash to create the new entry for the blog. Here is the source code of send_nb_entry.cgi
</p>



<textarea  style="height: 140px"  class="bashcode">

#!/bin/bash

echo "Content-type: text/html"
echo -e "Status: 200 \n"
echo -e "<html><head><meta http-equiv=\"refresh\" content=\"2;url=http://orvtech.com\"></head><body><p>ENTRY ACCEPTED IN FOR QUEUE</p></body></html>"

DRAFT_ENTRY_DIRECTORY="/tmp"
POST_DATA=$(</dev/stdin)
TEMP_FILE="/tmp/nb_cgi_send_nb_entry.tmp"

nb_entrada_title=`echo $POST_DATA | sed -n 's/^.*entrada_title=\([^&]*\).*$/\1/p' | sed -e 's/%20/ /g'| sed 's/+/ /g'| sed 's/\%0[dD]//g' | awk '/%/{while(match($0,/\%[0-9a-fA-F][0-9a-fA-F]/)) {$0=substr($0,1,RSTART-1)sprintf("%c",0+("0x"substr($0,RSTART+1,2)))substr($0,RSTART+3);}}{print}'`
nb_entrada_description=`echo $POST_DATA | sed -n 's/^.*entrada_description=\([^&]*\).*$/\1/p' | sed -e 's/%20/ /g'| sed 's/+/ /g'| sed 's/\%0[dD]//g' | awk '/%/{while(match($0,/\%[0-9a-fA-F][0-9a-fA-F]/)) {$0=substr($0,1,RSTART-1)sprintf("%c",0+("0x"substr($0,RSTART+1,2)))substr($0,RSTART+3);}}{print}'`
name_entrada_tmp=`date +%Y-%m-%dT%H_%M_%S.tmp`
echo "TITLE: $nb_entrada_title" > $TEMP_FILE
echo "AUTHOR:" >> $TEMP_FILE
echo "DATE:" >> $TEMP_FILE
echo "DESC: $nb_entrada_description" >> $TEMP_FILE
echo "FORMAT: raw" >> $TEMP_FILE
echo "-----" >> $TEMP_FILE
echo "BODY:" >> $TEMP_FILE

echo $POST_DATA | sed -n 's/^.*entrada_body=\([^&]*\).*$/\1/p' | sed -e 's/%20/ /g'| sed 's/+/ /g'| sed 's/\%0[dD]//g' |\
   awk '/%/{while(match($0,/\%[0-9a-fA-F][0-9a-fA-F]/))\
       {$0=substr($0,1,RSTART-1)sprintf("%c",0+("0x"substr(\
       	      $0,RSTART+1,2)))substr($0,RSTART+3);}}{print}' >> $TEMP_FILE

	      echo "END-----" >> $TEMP_FILE
	      mv `echo -e $TEMP_FILE` `echo -e $DRAFT_ENTRY_DIRECTORY/$name_entrada_tmp`</textarea>




<p>
We can latter import the file defined by $DRAFT_ENTRY_DIRECTORY/$name_entrada_tmp issuing the command:
</p>


<textarea  style="height: 14px"  class="bashcode">
nb -b /path/to/your/blog import entry /tmp/2010-03-02T15_02_01.tmp</textarea>


<p>
This will add the entry to our blog. I though about automating this in the CGI but at this point i prefer to create a central control panel and keep things separated.
</p>
<br /><br />
<p><i>
<b>Spanish version:</b> <a href="http://www.orvtech.com/archives/2010/04/06/interfaz_web_para_agregar_entradas_a_nanoblogger/index.html">Interfaz web para agregar entradas a NanoBlogger.</a>
</i></p><br />
</div>
</content>

</entry>
<entry>
<title type="html">ZNC IRC Bouncer start up script.</title>
<author>
<name>orvtech</name>
</author>
<link rel="alternate" type="text/html" href="http://linuxevolution.org/archives/2010/04/21/znc_irc_bouncer_start_up_script/index.html"/>

<id>http://linuxevolution.org/archives/2010/04/21/znc_irc_bouncer_start_up_script/index.html</id>
<published>2010-04-21T12:52:16-04:00</published>
<updated>2010-04-21T12:52:16-04:00</updated>
<category term="Scripts" />
<category term="IRC" />
<category term="NSLU2" />
<category term="Linux" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>
A few weeks a go I published an article about how to have push notifications to your iPhone from an IRC channel events. After installing and configuring ZNC I was a bit disappointed that it didn't had a start up script so I decided to write one. 
</p>
<p>
This script allows you to start, stop, reload the configuration and restart the service. lets take a look at /etc/init.d/zncd
</p>
<textarea class="bashcode"> 
#!/bin/bash
 
 ZNC_FOLDER="/usr/bin"
 ZNC_OWNR="your_user_here"
 
 if [ ! -f $ZNC_FOLDER/znc -o ! -d $ZNC_FOLDER ]
 then
 echo "ZNC startup: cannot start, it appears that it is not installed"
 exit 1
 fi
 
 case "$1" in
 start)
 echo -n "Starting ZNC: "
 su - $ZNC_OWNR -c "$ZNC_FOLDER/znc"
 touch /var/lock/subsys/ZNC
 echo "OK"
 ;;
 stop)
 echo -n "Shutdown ZNC: "
 kill -9 `ps -C znc | awk '{print $1}' | grep ^[0-9]`
 rm -f /var/lock/subsys/ZNC
 echo "OK"
 ;;
 reload)
 echo -n "Reloading ZNC:"
 kill -HUP `ps -C znc | awk '{print $1}' | grep ^[0-9]`
 echo "OK"
 ;;
 status)
 if ps -C znc > /dev/null
 then 
 echo "ZNC Bouncer is running"
 else 
 echo "ZNC Bouncer is not running"
 fi
 ;;
 restart)
 $0 stop
 sleep 2
 $0 start
 ;;
 *)
 echo "Usage: $0 start|stop|restart|reload|status"
 exit 1
 esac
 exit 0</textarea> 
<br /><p>
If your NSLU2 is running gentoo you could add it to the default run level like this:
</p>
<textarea style="height: 18px" class="bashcode"> 
rc-update add zncd default</textarea>
<br /><p>
The output should be something like this:
</p>
<textarea style="height: 18px" class="bashcode"> * zncd added to runlevel default</textarea> 
<br />
<p><i>
<b>Spanish version:</b> <a href="http://www.orvtech.com/archives/2010/04/16/script_de_arranque_para_znc_bouncer/index.html">script de arranque para ZNC bouncer.</a>
</i></p>
</div>
</content>

</entry>
<entry>
<title type="html">Bluetooh Audio Through the NSLU2.  </title>
<author>
<name>orvtech</name>
</author>
<link rel="alternate" type="text/html" href="http://linuxevolution.org/archives/2010/04/11/bluetooh_audio_through_the_nslu2/index.html"/>

<id>http://linuxevolution.org/archives/2010/04/11/bluetooh_audio_through_the_nslu2/index.html</id>
<published>2010-04-11T19:11:00-04:00</published>
<updated>2010-04-11T19:11:00-04:00</updated>
<category term="Scripts" />
<category term="NSLU2" />
<category term="Linux" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">

<p>
<a href="http://twitter.com/POTUSCamacho" rev="Original author of this guide">@POTUSCamacho</a> has an interesting article about how to use the NSLU2 in combination with a USB bluetooth adapter as an audio server. POTUSCamacho explains how to do it with a mono audio adapter but clarifies that it should be possible to do it using a stereo adapter.
</p>

<p>Lets take a look at this interesting howto:</p>

<blockquote cite="http://potuscamacho-industries.blogspot.com/2010/04/linksys-nslu2-utilizing-bluetooth-audio.html">

<p>Once you have installed Ubuntu, log in and update your packages:
</p>
<textarea style="height: 18px"  class="bashcode">
sudo -i apt-get update</textarea>
<p>
Then install the following packages:
</p>
<textarea style="height: 35px" class="bashcode">
sudo -i apt-get install linux-sound-base bluetooth bluez bluez-alsa bluez-btsco bluez-compat bluez-utils python python-bluez vlc</textarea>
<p><i>
Note: I do alot of other development stuff on my unit. I may have left off something, and if so let me know if you try it and it doesn't work.
</i><br />

Now that the needed packages are installed, an .asoundrc needs to be created in your user home directory. An example:
</p>
<textarea style="height: 50px" class="bashcode">
pcm.bluetooth {
type bluetooth
device 00:00:00:00:00:00
}</textarea>
<p>
Edit the device section with the MAC address of your bluetooth headset. To find this, issue a reset of the bluetooth adapter by issuing the command:
</p>
<textarea style="height: 18px" class="bashcode">
hciconfig hci0 reset</textarea>
<p>
Then place your headset in pairing mode and issue the following command:
</p>
<textarea style="height: 18px"  class="bashcode">
sdptool browse</textarea>
<p>
Now copy the following python script into a file named pair.py:
</p>
<textarea style="height: 480px" class="bashcode">
#!/usr/bin/python

import gobject

import sys
import dbus
import dbus.service
import dbus.mainloop.glib

class Rejected(dbus.DBusException):
_dbus_error_name = "org.bluez.Error.Rejected"

class Agent(dbus.service.Object):
exit_on_release = True

def set_exit_on_release(self, exit_on_release):
self.exit_on_release = exit_on_release

@dbus.service.method("org.bluez.Agent",
in_signature="", out_signature="")
def Release(self):
print "Release"
if self.exit_on_release:
mainloop.quit()

@dbus.service.method("org.bluez.Agent",
in_signature="os", out_signature="")
def Authorize(self, device, uuid):
print "Authorize (%s, %s)" % (device, uuid)
authorize = raw_input("Authorize connection (yes/no): ")
if (authorize == "yes"):
return
raise Rejected("Connection rejected by user")

@dbus.service.method("org.bluez.Agent",
in_signature="o", out_signature="s")
def RequestPinCode(self, device):
print "RequestPinCode (%s)" % (device)
return raw_input("Enter PIN Code: ")

@dbus.service.method("org.bluez.Agent",
in_signature="o", out_signature="u")
def RequestPasskey(self, device):
print "RequestPasskey (%s)" % (device)
passkey = raw_input("Enter passkey: ")
return dbus.UInt32(passkey)

@dbus.service.method("org.bluez.Agent",
in_signature="ou", out_signature="")
def DisplayPasskey(self, device, passkey):
print "DisplayPasskey (%s, %d)" % (device, passkey)

@dbus.service.method("org.bluez.Agent",
in_signature="ou", out_signature="")
def RequestConfirmation(self, device, passkey):
print "RequestConfirmation (%s, %d)" % (device, passkey)
confirm = raw_input("Confirm passkey (yes/no): ")
if (confirm == "yes"):
return
raise Rejected("Passkey doesn't match")

@dbus.service.method("org.bluez.Agent",
in_signature="s", out_signature="")
def ConfirmModeChange(self, mode):
print "ConfirmModeChange (%s)" % (mode)

@dbus.service.method("org.bluez.Agent",
in_signature="", out_signature="")
def Cancel(self):
print "Cancel"

def create_device_reply(device):
print "New device (%s)" % (device)
mainloop.quit()

def create_device_error(error):
print "Creating device failed: %s" % (error)
mainloop.quit()

if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object("org.bluez", "/"),
"org.bluez.Manager")

if len(sys.argv) > 1:
path = manager.FindAdapter(sys.argv[1])
else:
path = manager.DefaultAdapter()

adapter = dbus.Interface(bus.get_object("org.bluez", path),
"org.bluez.Adapter")

path = "/test/agent"
agent = Agent(bus, path)

mainloop = gobject.MainLoop()

if len(sys.argv) > 2:
if len(sys.argv) > 3:
device = adapter.FindDevice(sys.argv[2])
adapter.RemoveDevice(device)

agent.set_exit_on_release(False)
adapter.CreatePairedDevice(sys.argv[2], path, "DisplayYesNo",
reply_handler=create_device_reply,
error_handler=create_device_error)
else:
adapter.RegisterAgent(path, "DisplayYesNo")
print "Agent registered"

mainloop.run()

#adapter.UnregisterAgent(path)
#print "Agent unregistered"</textarea>

<p>
Now place your headset into pairing mode again and issue the follow command:
</p>
<textarea style="height: 18px" class="bashcode">sudo -i python pair.py hci0 00:00:00:00:00:00</textarea>

<p>
Once again replacing the address above with your headsets MAC.
The last step involves editing the vlcrc. To do this, issue the command:
</p>

<textarea style="height: 18px" class="bashcode">
pico .vlc/vlcrc
</textarea>

<p>
Scroll down and replace:
</p>

<textarea style="height: 18px" class="bashcode">
alsadev=(default soundcard) </textarea>

<p>To:</p>

<textarea style="height: 18px" class="bashcode">
alsadev=bluetooth</textarea>

<p>
If it does not exist then create it.
</p>

<p>
Now you should be ready to listen to audio. To listen to the audio from NASA TV's online video stream, issue the command:
</p>

<textarea style="height: 18px" class="bashcode">
cvlc --aout-rate 8000 --novideo http://www.nasa.gov/55644main_NASATV_Windows.asx</textarea>

<p>
If everything is working you should hear audio. Keep in mind that the sample rate needs to be 8000Hz since that is the sample rate the headset can handle.
</p>

<p>
To pair another headset, or to re-pair the current, the /var/lib/bluetooth/(your MAC)/linkkeys file must be deleted. It will regenerate once you have paired the devices. Also remember that the .asoundrc file must be edited to match a different headset as the MAC will be different.
</p></blockquote>

<p>
To find out more info about this article, please visit <a href="http://potuscamacho-industries.blogspot.com/2010/04/linksys-nslu2-utilizing-bluetooth-audio.html">POTUSCamacho Industries</a> blog.
</p>
<br />
<p><i>
<b>Spanish version:</b> <a href="http://www.orvtech.com/archives/2010/04/12/audio_via_bluetooh_desde_el_nslu2/index.html">Audio vía bluetooh desde el NSLU2.</a>
</i></p>
</div>
</content>

</entry>
<entry>
<title type="html">A BASH CGI as a workaround to .htaccess files on lighttpd</title>
<author>
<name>orvtech</name>
</author>
<link rel="alternate" type="text/html" href="http://linuxevolution.org/archives/2010/03/26/a_bash_cgi_as_a_workaround_to__htaccess_files_on_lighttpd/index.html"/>

<id>http://linuxevolution.org/archives/2010/03/26/a_bash_cgi_as_a_workaround_to__htaccess_files_on_lighttpd/index.html</id>
<published>2010-03-26T12:49:32-04:00</published>
<updated>2010-03-26T12:49:32-04:00</updated>
<category term="Scripts" />
<category term="NSLU2" />
<category term="Linux" />
<category term="nanoblogger" />
<category term="lighttp" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>
As you might remember, in a previous post I explained how to maintain a permanent link which always points 
to the latest submission on your nanoblogger website. Since I decided to migrate from apache to lighttp I 
lost the ability to use .htacees files thus .htacees file based redirects do not work anymore.
</p>
<p>
<br /><b>The workaround.</b><br />

We will keep using the /latest url for the redirects the only thing is that we will use a CGI written in 
BASH to accomplish the redirect. The script will parse our RSS feed (rss.xml) to check which is the latest 
post and redirect to that url. The redirect is accomplished by sending the HTTP headers 'Location' and 
'Status'. Let's take a look at the script:
<br />
<i>latest.cgi</i><br />

<textarea style="height: 80px" class="bashcode">
#!/bin/bash
DocummentRoot="/var/www/linuxevolution.org/htdocs"
Latest=`cat $DocummentRoot/rss.xml | grep link | grep archives | head -n1 | sed -e :a -e 's/<[^>]*>//g;/</N;//ba'`
echo "Status: 302 Moved"
echo -e "Location: $Latest\n"</textarea>
</p>
<p>
Here we are sending the Status header to prevent search engines from associating more than one url to the 
same content (this will give us a lower score in some search engines' systems) and then we send the 
Location header to do the actual redirect.
</p>
<p>
<br /><b>Lighttp and CGIs.</b><br />

In other to execute this CGI we need to make some minor modifications to our VirtualHostost configuration. 
Lets add these two lines to it:
<br />

<textarea style="height: 26px" class="bashcode">
cgi.assign = ( ".cgi" => "/bin/bash" )
url.redirect =( "^/latest/(.*)" => "http://www.linuxevolution.org/latest.cgi")</textarea>


</p>
<p>
In the first line we are telling lighttpd to use /bin/bash to execute any *.cgi file (you can change this 
to anything like *.sh, *.bash). In the second line we redirect all requests to /latest/ to the url 
/latest.cgi. You can either use /latest.cgi or /latest/ for these urls in your signature at the forums; 
personally I like to use /latest/<name of the forum here> to keep track of where is my traffic coming from 
even if I don't get the HTTP referrer.
</p>
<br />
<p><i>
<b>Spanish version:</b> <a href="http://www.orvtech.com/archives/2010/03/23/un_cgi_en_bash_para_mantener_tu_firma_al_d%C3%ADa_en_todos_los_foros_en_que_participas/index.html">Un CGI en BASH para mantener tu firma al dia en todos los foros en que participas.</a>
</i></p>
</div>
</content>

</entry>
<entry>
<title type="html">From Picasaweb Albums to BBCode</title>
<author>
<name>orvtech</name>
</author>
<link rel="alternate" type="text/html" href="http://linuxevolution.org/archives/2010/03/19/from_picasaweb_albums_to_bbcode/index.html"/>

<id>http://linuxevolution.org/archives/2010/03/19/from_picasaweb_albums_to_bbcode/index.html</id>
<published>2010-03-19T11:03:40-04:00</published>
<updated>2010-03-19T11:03:40-04:00</updated>
<category term="Scripts" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>
This script has the same function as the <a href="http://linuxevolution.org/archives/2010/03/16/from_flickr_to_bbcode_script/index.html" title="Flickr2BBCode script">Flickr script</a>, it takes a Picasaweb album and gets the BBCode to allow you to share it on a forum, the urls that we are going to work with have the picasaweb.google.com/<user>/<album_name> structure, for example this URL: 
<br /><i>http://picasaweb.google.com/orvtech/Hdd</i>
</p>
<br />
<p>
Lets take a look at the code:<br />
<textarea  style="height: 140px"  class="bashcode">
#!/bin/bash
SIZE=400

echo $1 | \
curl -s `awk --field-separator=/ '{print "http://picasaweb.google.com/data/feed/api/user/"$4"/album/"$5}'` |\
sed -e 's/\"/\ /g' -e s/\'/\ /g |\
tr ' ' '\n' |\
grep  s72 |\
awk '{print "[url='$1'][img]"$0"[/img][/url]\n"}' |\
sed s/s72/s$SIZE/g
</textarea>
</p>
<br />
<p>
Lets name this script Picasa2BBCode.sh, we can execute it like this:<br />
<textarea  style="height: 17px"  class="bashcode">
sh Picasa2BBCode.sh http://picasaweb.google.com/orvtech/Hdd</textarea>
</p>
<br />
<p>
We can modify the constant SIZE in this script, it can take the values 72px, 144px, 288px, 320px, 400px, 512px, 576px, 640px, 800px or 1024px but if the image is smaller than 800px we might have some problems. Running the script will produce an output like this:<br />

<textarea  style="height: 130px"  class="bashcode">
[url=http://picasaweb.google.com/orvtech/Hdd#][img]http://lh6.ggpht.com/_WwtoUQV8M_8/S5kBtkqKAdI/AAAAAAAAPbM/I0LCPdB-qpQ/s400/IMG_7457.JPG[/img][/url]

[url=http://picasaweb.google.com/orvtech/Hdd#][img]http://lh3.ggpht.com/_WwtoUQV8M_8/S5kBtwXW08I/AAAAAAAAPbQ/Y636HBHOxEo/s400/IMG_7458.JPG[/img][/url]

[url=http://picasaweb.google.com/orvtech/Hdd#][img]http://lh5.ggpht.com/_WwtoUQV8M_8/S5kBtzPQLrI/AAAAAAAAPbU/ZOWfnh4uGuA/s400/IMG_7459.JPG[/img][/url]

[url=http://picasaweb.google.com/orvtech/Hdd#][img]http://lh5.ggpht.com/_WwtoUQV8M_8/S5kBuJEzUPI/AAAAAAAAPbY/qxTGuFR_EbA/s400/IMG_7461.JPG[/img][/url]

[url=http://picasaweb.google.com/orvtech/Hdd#][img]http://lh3.ggpht.com/_WwtoUQV8M_8/S5kBupiHjqI/AAAAAAAAPbc/FShn8ryEr54/s400/IMG_7462.JPG[/img][/url]

[url=http://picasaweb.google.com/orvtech/Hdd#][img]http://lh5.ggpht.com/_WwtoUQV8M_8/S5kCW9ags7I/AAAAAAAAPbw/wFYET5XlgkQ/s400/IMG_7463.JPG[/img][/url]

[url=http://picasaweb.google.com/orvtech/Hdd#][img]http://lh5.ggpht.com/_WwtoUQV8M_8/S5kCXA_XujI/AAAAAAAAPb0/WDc3N1tLDCw/s400/IMG_7464.JPG[/img][/url]

[url=http://picasaweb.google.com/orvtech/Hdd#][img]http://lh4.ggpht.com/_WwtoUQV8M_8/S5kCXDnyhkI/AAAAAAAAPb4/SWuagR3LA8c/s400/IMG_7465.JPG[/img][/url]

[url=http://picasaweb.google.com/orvtech/Hdd#][img]http://lh5.ggpht.com/_WwtoUQV8M_8/S5kCXTt6vaI/AAAAAAAAPb8/i1RmMrL5slg/s400/IMG_7466.JPG[/img][/url]

[url=http://picasaweb.google.com/orvtech/Hdd#][img]http://lh5.ggpht.com/_WwtoUQV8M_8/S5kCX8hUk-I/AAAAAAAAPcA/YzOe_0bO0Jw/s400/IMG_7468.JPG[/img][/url]
...</textarea>
</p>
<br />
<p><i>
<b>Spanish version:</b> <a href="http://www.orvtech.com/archives/2010/03/17/de_picasa_a_bbcode/index.html">De Picasa a BBCode.</a>
</i></p>
</div>
</content>

</entry>
<entry>
<title type="html">From flickr to bbcode script</title>
<author>
<name>orvtech</name>
</author>
<link rel="alternate" type="text/html" href="http://linuxevolution.org/archives/2010/03/16/from_flickr_to_bbcode_script/index.html"/>

<id>http://linuxevolution.org/archives/2010/03/16/from_flickr_to_bbcode_script/index.html</id>
<published>2010-03-16T10:27:06-04:00</published>
<updated>2010-03-16T10:27:06-04:00</updated>
<category term="Scripts" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>
As you know I participate a lot in internet forums and most of these use <a href="http://en.wikipedia.org/wiki/BBCode">BBCode</a> to let us pulish photos, youtube videos,
links, etc. Since I like to share photos and dont want to copy the url of each image on a set of 60 or more images on flickr
I decided to automate this and wrote a simple script that will generate the <a href="http://en.wikipedia.org/wiki/BBCode">BBCode</a> from a flickr set url.
</p>
<p>
Lets take a look at this script, lets call it flickr2bbcode.sh
</p>
<textarea  style="height: 60px"  class="bashcode">
#!/bin/bash
curl -s $1 | tr ' ' '\n' | grep '_s.jpg' |\
sed "s/\"/\ /g" |sed -e 's/_s\.jpg/\.jpg/g'|\
awk '{print "[url='$1'][img]"$2"[/img][/url]\n"}'</textarea>
<p>
If you want to run this script you will need to pass the url of the set of photos that you want to
publish, for example <i>http://www.flickr.com/photos/tatadbb/sets/72157606893687387/</i> so your command line will look like this:
</p>
<textarea  style="height: 20px"  class="bashcode">
sh flickr2bbcode.sh http://www.flickr.com/photos/tatadbb/sets/72157606893687387/
</textarea>
<p>
The out put of this command would be something like this:
</p>
<textarea  style="height: 130px"  class="bashcode">
[url=http://www.flickr.com/photos/tatadbb/sets/72157606893687387/][img]http://farm4.static.flickr.com/3075/2787828382_10ea6d0924.jpg[/img][/url]

[url=http://www.flickr.com/photos/tatadbb/sets/72157606893687387/][img]http://farm4.static.flickr.com/3017/2806875776_fa4f208409.jpg[/img][/url]

[url=http://www.flickr.com/photos/tatadbb/sets/72157606893687387/][img]http://farm4.static.flickr.com/3145/2817776689_ffc218e9e8.jpg[/img][/url]

[url=http://www.flickr.com/photos/tatadbb/sets/72157606893687387/][img]http://farm4.static.flickr.com/3329/3280872113_722ff06df8.jpg[/img][/url]

[url=http://www.flickr.com/photos/tatadbb/sets/72157606893687387/][img]http://farm4.static.flickr.com/3636/3280920431_f257aaec90.jpg[/img][/url]

...</textarea>

<br />
<p><i>
<b>Spanish version:</b> <a href="http://www.orvtech.com/archives/2010/03/16/de_flickr_a_bbcode/index.html">De Flickr a BBCode.</a>
</i></p>
</div>
</content>

</entry>
<entry>
<title type="html">The end of public access to my NSLU2? </title>
<author>
<name>orvtech</name>
</author>
<link rel="alternate" type="text/html" href="http://linuxevolution.org/archives/2010/03/14/the_end_of_public_access_to_my_nslu2/index.html"/>

<id>http://linuxevolution.org/archives/2010/03/14/the_end_of_public_access_to_my_nslu2/index.html</id>
<published>2010-03-14T20:01:57-04:00</published>
<updated>2010-03-14T20:01:57-04:00</updated>
<category term="NSLU2" />
<category term="Twitter" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>
I just found out that the 'datacenter' where I have my NSLU2 will be shooting down soon. When I say datacenter I mean the house of a friend that have a public IP, this will happen within the next 2 months so I need to start thinking on what to do to keep this site alive and maintained by a NSLU2. 
<br />
<br />
<img src="http://www.linuxevolution.org/images/jailed_nslu2.png" align=left> Right now I thing the best option is just to bring it to my house and use it as a backend or publisher and use the VPS as my frontend. I am still contemplating other ideas but I think the easiest option is to just publish trough my NSLU2 and  rsync the content to my VPS. My home ISP is u-verse and I dont know how friendly are they about hosting services. 
</p>
<p>
If you have any suggestion please dont hesitate to let me know via twitter ( <a href="http://twitter.com/m1n1m3">@m1n1m1</a> ) or just leave  a comment... also if you are hosting any kind of service via u-verse please let me know how has been your experience. 
</p>
<br />
<p><i>
<b>Spanish version:</b> <a href="http://www.orvtech.com/archives/2010/03/14/ha_llegado_el_fin_del_acceso_publico_a_mi_nslu2/index.html">Ha llegado el fin del acceso publico a mi NSLU2.</a>
</i></p>
</div>
</content>

</entry>

</feed>
