Categories
Kindle Linux Posts Ubuntu

Auto Sync Kindle in Ubuntu

For Christmas I got a Kindle 3 and it was instantly filled with Free eBooks (http://www.gutenberg.org/wiki/Main_Page) and research papers (PDFs). I found myself wanting to be able to automatically synchronize it with a folder on my desktop when it was plugged in and found no one else had posted online how to do this, so I began researching into udev and rsync to get something working.

Setting up udev rules to run a script when the Kindle is plugged in.

Firstly, we need to find some parameters of the Kindle which are unique to it so that udev can identify that it is the Kindle being plugged in and not another USB mass storage device. We’ll need to find out where the device is mounted in /dev/ which can be a little tricky because this folder is pretty full.

An easier way to do this is to first, without the Kindle plugged in do the following command (list the directory and pipe the output to a file called dev1 in the home dir):

ls /dev/ > ~/dev1

Now plug the Kindle in and redo the command, changing the destination output:

ls /dev/ > ~/dev2

The difference between the two files will show what has changed in the /dev/ directory:

 sdiff ~/dev1 ~/dev2

The output for mine (show in the image below) shows that 3 things changed when I plugged in the Kindle, sdb, sdb1 and sg2 directorys were added (shown by the > sign to the left). The folder I am looking for is the sdb1, this is where the mass storage device is found.

Write down where it’s found in /dev/ and then you can clean up those two files you previously made:

rm ~/dev1 | rm ~/dev2

The next thing we want to do is use udevadm to collect some useful information about the device which we can do by the following command (I have chosen to pipe the output to a file called kindle in the home dir, because the output was pretty big. If you don’t want to remove the > ~/kindle from the end of the command):

udevadm info -a -p $(udevadm info -q path -n /dev/sdb1) > ~/kindle

WARNING: This can look pretty daunting but, (in the words of Douglas Adams) Don’t Panic.

  looking at device '/devices/pci0000:00/0000:00:1d.0/usb2/2-2/2-2:1.0/host21/target21:0:0/21:0:0:0/block/sdb/sdb1':
    KERNEL=="sdb1"
    SUBSYSTEM=="block"
    DRIVER==""
    ATTR{partition}=="1"
    ATTR{start}=="16"
    ATTR{size}=="6410672"
    ATTR{alignment_offset}=="0"
    ATTR{discard_alignment}=="4294959104"
    ATTR{stat}=="     151     3389     4239     3776        0        0        0        0        0     2424     3776"
    ATTR{inflight}=="       0        0"

  looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-2/2-2:1.0/host21/target21:0:0/21:0:0:0/block/sdb':
    KERNELS=="sdb"
    SUBSYSTEMS=="block"
    DRIVERS==""
    ATTRS{range}=="16"
    ATTRS{ext_range}=="256"
    ATTRS{removable}=="1"
    ATTRS{ro}=="0"
    ATTRS{size}=="6410688"
    ATTRS{alignment_offset}=="0"
    ATTRS{discard_alignment}=="0"
    ATTRS{capability}=="51"
    ATTRS{stat}=="     156     3389     4279     3808        0        0        0        0        0     2456     3808"
    ATTRS{inflight}=="       0        0"

  looking at parent device '/devices/pci0000:00/0000:00:1d.0/usb2/2-2/2-2:1.0/host21/target21:0:0/21:0:0:0':
    KERNELS=="21:0:0:0"
    SUBSYSTEMS=="scsi"
    DRIVERS=="sd"
    ATTRS{device_blocked}=="0"
    ATTRS{type}=="0"
    ATTRS{scsi_level}=="3"
    ATTRS{vendor}=="Kindle  "
    ATTRS{model}=="Internal Storage"
    ATTRS{rev}=="0100"
    ATTRS{state}=="running"
    ATTRS{timeout}=="30"
    ATTRS{iocounterbits}=="32"
    ATTRS{iorequest_cnt}=="0xe1"
    ATTRS{iodone_cnt}=="0xe1"
    ATTRS{ioerr_cnt}=="0x1"
    ATTRS{modalias}=="scsi:t-0x00"
    ATTRS{evt_media_change}=="0"
    ATTRS{dh_state}=="detached"
    ATTRS{queue_depth}=="1"
    ATTRS{queue_type}=="none"
    ATTRS{max_sectors}=="240"

While this many look daunting, what you want to do if find some attributes from the output which mean only your Kindle will be found when looking for them all, the problem I have found is that, with udev rules you cannot go too far down in the parent tree which stops me being able to use the Kindles serial to identify it. This could mean that my computer will sync any Kindle that’s plugged into it but I don’t have 2 to check. The following are the attributes I chose:

KERNEL=="sd?", ATTRS{vendor}=="Kindle  ", ATTRS{modalias}=="scsi:t-0x00"

Now you’ll want to write the udev rule in /etc/udev/rules.d/

cd /etc/udev/rules.d/

According to the readme the numbers represent the priority of the rule (higher overriding lower) followed by a descriptive name and it must end in .rules eg (xx-description.rules).

sudo gedit 81-kindle-sync.rules

The following is the whole line I used for the udev rule, the only addition to the above is the RUN+=”/home/alex/.scripts/kindlesync.sh” which will run the script in that directory, this script contains the rsync command.

KERNEL=="sd?", ATTRS{vendor}=="Kindle  ", ATTRS{modalias}=="scsi:t-0x00", RUN+="/home/alex/.scripts/./kindlesync.sh"

Save and close the file and then restart the udev service:

sudo service udev restart

Writing a script to sync a folder on the Desktop with a folder on the Kindle using rsync:
Change the first directory from “/home/alex/ebooks/kindle_sync” to the directory on your computer where you want to keep the files that will be synced onto your Kindle and the second from “/media/Kindle/documents/sync/” to the location on your mounted Kindle where you want the files to be stored, save this file as kindlesync.sh. This is the script you call from the udev rules so for mine it’s saved as “/home/alex/.scripts/kindlesync.sh”.

#!/bin/bash

#Sync
rsync -av /home/alex/eBooks/kindle_sync/ /media/Kindle/documents/sync/

Go to the location of the script and make it executable with the following command:

chmod +x kindlesync.sh

Now try plugging in your Kindle and make sure it syncs up!

Problems

In the udev rule, ACTION==”add” can be used to specify when the Kindle is first plugged in, however when trying to use this Ubuntu’s auto-mounting service mounts the drive after the script is ran so the sync becomes useless. Without this it runs the script 3 times, twice before it has mounted and then once it has mounted – this is currently the best I have found but it’s extremely messy.

Categories
Blog Command Line Linux Posts Ubuntu

A More Elegant Solution to Ubuntu Wi-Fi Reconnecting Issue

Previously I was having problems with Ubuntu dropping wifi connections and failing to reconnect, to solve this I wrote a script which would kill the network-manager and then connect using iwconfig commands (here). While this works fine, it felt a little hacky, having to have a script running as sudo constantly in the background checking for a dropped connection. After a little searching I came across cron (the time based job scheduler ) and /etc/rc.local (a script which is run after all other initialization scripts have ran, allowing for scripts to be ran on startup) so from this I decided to split the old script up into connection and checking scripts which could be ran from init.d/local and cron, respectively.

Firstly my startup script in /etc/init.d/local which sets up and connects to the wireless network, open the file as sudo:

 sudo gedit /etc/rc.local

Paste in the following:

#! /bin/sh

service network-manager stop && service networking stop

iwconfig wlan0 essid NETWORKNAME
iwconfig wlan0 key WEPKEY
ifconfig wlan0 up
dhclient3 wlan0

sleep 10

if iwconfig wlan0 | grep -o "Access Point: Not-Associated"
then
	ifconfig wlan0 down
	sleep 10
	ifconfig wlan0 up

fi

exit 0

Next the script for checking the network is still connected, if not attempt to reconnect (named wirelesscheck.sh):

#!/bin/bash

if iwconfig wlan0 | grep -o "Access Point: Not-Associated"
then

	ifconfig wlan0 down
	sleep 10
	ifconfig wlan0 up
	
fi

Make sure this script is executable (from the directory of the script):

 chmod +x wirelesscheck.sh 

Note: This is setup in the sudo crontab, only because this command needs root privileges – other commands could be added to a user crontab (by removing sudo from the following.)

Now, edit (-e) the crontab for sudo:

 sudo crontab -e 

If crontab has not previously been used choose an editor (I used nano – 2) and append this line to the bottom of the file and change the frequency and directory of the script. The current settings will run it every 5 minutes (*/5) every hour, day, month and year and the file is located in “/path/to/script/wirelesscheck.sh”.

*/5 * * * * /path/to/script/wirelesscheck.sh

If you have any issues, leave a comment and I will help if I can.

Categories
HowTo Linux Posts Ubuntu

How To: Fix “Failed to download repository information Check your Internet connection.”

If you’re getting this error but you’re still connected to the internet this page might help. This error is sometimes caused by repository’s which are down or broken.

Failed to download repository information
Check your Internet connection.

From terminal run the following command:

 sudo apt-get update

If the output runs through a few repositorys but ends with something similar to the below (most probably with different repositorys failing) and ultimately stopping your updating process then there is a good chance you can fix it by just removing those failing sources from the software sources.

Err http://ppa.launchpad.net maverick/main Sources
404 Not Found
Err http://ppa.launchpad.net maverick/main amd64 Packages
404 Not Found
W: Failed to fetch http://ppa.launchpad.net/bugs-sehe/gparted/ubuntu/dists/maverick/main/source/Sources.gz 404 Not Found
W: Failed to fetch http://ppa.launchpad.net/bugs-sehe/gparted/ubuntu/dists/maverick/main/binary-amd64/Packages.gz 404 Not Found
E: Some index files failed to download, they have been ignored, or old ones used instead.

Software Sources can be found under either:

Applications > Ubuntu Software Centre > Edit > Software Sources..
OR
System > Administrator > Synaptic Package Manager > Settings > Repositorys

Click the Other Software tab.

Nnow find the repositories which caused the failure on the update and uncheck them and then close the Software Centre.

Re-run the update command and hopefully everything will work!

 sudo apt-get update

Check the example below where gparted was causing the error:

Categories
HowTo Linux Posts Ubuntu

How To: Restore Default sources.list

Having gone through several upgrades and countless repository’s added to the software sources, things can begin to get really messy really quickly and often begin to screw up when updating the system if you’re not careful. You may find yourself, like I have, wanting to restore your sources.list file back to its default in order to get things working again.

In order to do this there is a pretty handy webapp available called the “Ubuntu Sources List Generator” – http://repogen.simplylinux.ch/

By moving through each section it enables you to select your country, release and then check each repository you want to add, not only does it support all the official ones for things like security and updates, it also allows for 3rd party repos such as Banshee, Chromium, Conky and VLC amongst a bunch others. Once you have what you want hit generate and it’ll create a nice, comment, new sources.list file ready for you to replace your old one with.

You may want to backup your old sources.list just in case with the following command:

 sudo cp /etc/apt/sources.list /etc/apt/sources.list.bkup

Once you have that you can open the sources.list and simply paste the new one in from the repogen:

 sudo gedit /etc/apt/sources.list

Paste, Save and Close the file and now you should paste the generated GPG keys, found just below the generated sources.list file, into your terminal.

Everything should be back to default and allow you to once again update everything.

Categories
Command Line Linux Posts Ubuntu

How To: Install Pyrobot in Ubuntu

A quick guide for getting pyrobot running in Ubuntu, I’ve managed to get it running on 32bit and 64bit Ubuntu (10.10) so follow the guide accordingly to whichever architecture you’re using (64bit is about half way down the post).

32-bit

1. Download this file, or copy the below into a file and save it as pyroinstall.sh to your home dir.

#!/bin/sh

currentdir=$(pwd)

sudo apt-get install build-essential python2.6 python2.6-dev python-tk python-numeric libjpeg62-dev libncurses5-dev swig

wget http://pyrorobotics.org/download/pyrobot-latest.tgz

tar -zxvf pyrobot-latest.tgz

cd pyrobot

python configure.py

make

sed -ie 's/-e #!/#!/g' $currentdir/pyrobot/bin/pyrobot
sed -ie 's/-e # /# /g' $currentdir/pyrobot/system/version.py

echo 'export PATH=${PATH}:'$currentdir'/pyrobot/bin' >> $currentdir/.bashrc

Note: The ‘ in the code highlighter I have above won’t work in terminal, there isn’t much I can do about it so you’ll have to re-write it. Also if you’re doing this manually change the “$currentdir” to “~” if you are doing it in your home directory.

2. Make sure this file is in your home directory (e.g /home/alex/pyroinstall.sh) and make it executable:

 chmod +x pyroinstall.sh

3. Run the usual way (as super user because it has to install stuff etc):

 sudo ./pyroinstall.sh

4. It’ll ask you some questions, below are the answers I used – you can use other configurations if you know what you need. I also put the full output in pastebin ’cause it was bunging up the guide – http://pastebin.com/Kc5jyhja

1. 	2.6
2. 	/usr/include/python2.6
3. 	/usr/bin/python2.6
4. 	/etc/X11
5. 	none
6.01	n
6.02	n
6.03	n
6.04	n
6.05	n
6.06	n
6.07	n
6.08	n
6.09	n
6.10	n
6.11	y
6.12	y

5. Once it’s done reboot or run:

 source ~/.bashrc

6. Allow read/write/execute permissions for the pyrobot folder:

 sudo chmod -R 777 ~/pyrobot

You should all be done, try typing the following to get it running!

 pyrobot

64-bit

In order to get pyrobot running on 64bit, you basically need to add -fPIC to CFLAGS in all the relative Makefiles as explained in this mailing list post – http://www.mail-archive.com/pyro-users@pyrorobotics.org/msg00344.html – Lucky for you I’ve already gone through the effort of doing it and compressed it (download here you won’t need to if you are going to run the script though, it’ll do it for you..).

This script should download the file, configure and make and output the path to the .bashrc file for you (similar to the 32bit one does) so download this file, or copy and paste the script below into a file in your home directory:

#!/bin/sh

currentdir=$(pwd)

sudo apt-get install build-essential python2.6 python2.6-dev python-tk python-numeric libjpeg62-dev libncurses5-dev swig

wget http://dl.dropbox.com/u/307455/pyrobot-5.0.0_64bit.tar

tar -zxvf pyrobot-5.0.0_64bit.tar

cd pyrobot

python configure.py

make

echo 'export PATH=${PATH}:'$currentdir'/pyrobot/bin' >> $currentdir/.bashrc

2. Make sure this file is in your home directory (e.g /home/alex/pyroinstall64.sh) and make it executable:

 chmod +x pyroinstall64.sh

3. Run the usual way (as super user because it has to install stuff etc):

 sudo ./pyroinstall64.sh

Steps 4. 5. and 6. are the same as above..

Change Default Editor

If you want to change the default editor from emacs to anything else (this will change the default editor used in other terminal applications too..) use the following commands, just change gedit to whatever you’d like (vi, vim, kedit etc):

echo "export EDITOR=/usr/bin/gedit" >> ~/.bashrc
source ~/.bashrc

Any problems leave a comment and I’ll try and help as best as I can..

Categories
HowTo Linux Posts Ubuntu

How To: Fix “Unknown keyword in configuration file.” Ubuntu USB Boot

Attempting Boot From USB Device

SYSLINUX 3.63 Debian-2008-07-15 EBIOS Copyright (C) 1994-2008 H. Peter Anvin
Unknown keyword in configuration file.
boot:
_

After creating a USB bootable version of Ubuntu from the Startup Disk Creator (or usb-creator-gtk) and attempting to boot, I was greeted by the error above. It might look a bit scary but it’s really easy to fix, just plug the USB flash drive into a computer (windows or linux, mac too probably but I haven’t tried that.)

Solution 1:
  1. Open the the syslinux folder in the root of the flash drive.
  2. Inside is a file called syslinux.cfg you’ll want to edit that.
  3. Find the line “ui gfxboot bootlogo” and simply remove the “ui “.
  4. Save and try booting again.

Below is how my syslinux.cfg file looks after editing:

# D-I config version 2.0
include menu.cfg
default vesamenu.c32
prompt 0
timeout 50
gfxboot bootlogo


Solution 2

Alternatively it looks as though there is another way of fixing this issue if there is no “ui” in the file, this is to do as followed (as pointed out in the comments below):

  1. Type “help” and press enter
  2. Hit Enter again

This should boot correctly and shouldn’t need to be done every time.

Categories
Blog GIMP Linux Posts Windows

HowTo: Install & Use Resynthesizer for GIMP

Remember this Photoshop CS5 sneak peak showing off it’s latest and greatest feature Content-Aware Fill a couple months ago, well it turns out a reasonably old plug-in for GIMP (GNU Image Manipulation Program) named Resynthesizer seems to work just as great and because it is what it is, it’s free and open-source.

Installing on Ubuntu 9.10/10.04 install:

sudo apt-get install gimp-resynthesizer

or for the Source/Windows/Fedora Core 4 versions see the download section.

Once you have it installed, it’s simple to use really just select something on your image that shouldn’t be there and right click on the selection Filters -> Map -> Resynthesize.. and up should pop an options box, these settings are pretty standard and will get rid of most things given that they aren’t too big. It’s best if you’re not getting the results you want to play around with the settings yourself to get to know them better.

Click after the break for an example with step by step guide.

Categories
HowTo Posts Ubuntu

HowTo: Run .jar files in Ubuntu

To run a JAR file from the command line in ubuntu using the following command:

java -jar filename.jar

Otherwise it is also possible to enable double clicking to run jar files too by the following simple steps:

  1. Find the .jar file in the File Browser (a.k.a Nautilus)
  2. Right click the .jar file > Properties
  3. Click on the “Open With” tab along the top
  4. Change the bullet to be Sun Java 6 Runtime
  5. Click Close and you’re done.

Now you should be able to just double click the file and it will run just like most other files!

Categories
HowTo Linux Posts

HowTo Fix: The file ‘/path/file.exe’ is not marked as executable.

The file ‘/path/file.exe’ is not marked as executable.  If this was downloaded or copied form an untrusted source, it may be dangerous to run.  For more details, read about the executable bit.

While re-installing Spotify on my Desktop I came across this error while trying to run the .exe through wine (shown above) and here’s a really simple way of fixing it:

  1. Right click the .exe
  2. Properties
  3. Under the Permssions tab make sure “Allow executing file as program” is checked
  4. Click Close and you should be able to now run it through wine..
Categories
HowTo Posts Ubuntu

HowTo Fix: “There is a problem with your sound card. Spotify can’t play music.” (Wine)

Quite a few times I have encountered this problem, which I think is caused when the soundcard was recently used by another program and might still be busy but it means Spotify can’t play music, so a quick fix for this is to load winecfg and test your sound card which seems to force wine into tacking control of the it.

  1. Close Spotify
  2. In terminal type winecfg
  3. Click on the Audio tab (should be in the top middle)
  4. Click “Test Audio” and if you hear a sound this should work..
  5. Re-open Spotify and check a track, if it’s playing it’s worked otherwise you may have a different issue..