Useful commands #3: Deleting files with special characters in their filenames

Leave a comment

Successfully tested on Ubuntu Server 12.04 LTS 64-bit

Ever been stuck with a weird file you wanted to delete? You know, those lock files with special characters in their filenames left all over your Samba shares by some Windows applications (for instance)? Today’s post will help you get rid of them in a snap.

First of all, make sure your current directory is the one where your annoying file is located:

cd directory_containing_weird_file

 
Next, list directory’s content using the –inode option:

ls -i

 
You should now see a listing with a number at the beginning of each line. This number corresponds to the unique inode ID of each file and we’ll use it as identifier for the deletion, instead of our bizarre filename. Just do:

find . -inum inode_ID_of_your_file -exec rm -i {} \;

 
The recalcitrant IS wiped out for good this time!

That’s all Folks!


For further reading, you can take a look at ls and rm man pages which detail some other interesting options.

Advertisements

Installing Serviio media streaming server on Ubuntu

Leave a comment

Successfully tested on Ubuntu Server 12.04 LTS 64-bit

Having a home server to centralize and share documents over your network, publish websites or run your own mail server is pretty cool in fact, but today is time to have more fun with your computer rig. Let’s talk about multimedia sharing, streaming and transcoding with the installation of a DLNA server: Serviio.

First of all, head to Serviio website, look for the link to the latest archive for Linux and download it:

wget link_to_latest_serviio_archive

 
Create the /opt/serviio directory and unpack the file to it:

mkdir -p /opt/serviio && tar -C /opt/serviio -xvzf serviio_archive.tar.gz --strip-components=1

 
Then, create a serviio system user:

adduser --system --home /opt/serviio serviio

 
and assign the installation folder ownership to him:

chown serviio:nogroup -R /opt/serviio

 
Create another specific folder which will be used by Serviio to temporarily store the transcoded files (choose the path you prefer but make sure it points to a partition with sufficient free space as multimedia files can be huge):

mkdir /media/md0/.tmp

 
change its access permissions:

chmod 1777 /media/md0/.tmp

 
and then modify the /opt/serviio/bin/serviio.sh script to point to this folder by adding the following parameter at the end of the JAVA_OPTS= line:

-Dserviio.defaultTranscodeFolder=/media/md0/.tmp

 
Now, install all the third party applications needed to have a fully working Serviio: First, install Java if it’s not already installed:

apt-get install default-jre

 
Then, build and install FFmpeg according to the instructions you’ll find in Serviio and FFmpeg Wikis (FFmpeg Wiki contains useful specific instructions dedicated to server/headless machines).

Finally, install dcraw if you need RAW images support:

apt-get install dcraw

 
We’re close to the end now. Let’s just make sure the DLNA server will be launched at startup. To do this, simply create an init script /etc/init/serviio.conf with the following content:

# Serviio - Media Streaming Server
#
# Serviio is a free media server. It allows you to stream your media files
# (music, video or images) to renderer devices (e.g. a TV set, Bluray
# player, games console or mobile phone) on your connected home network.

description "Serviio - Media Streaming Server"

env USER=serviio
env LANG=fr_FR.UTF-8

start on started networking
start on mounted DEVICE=[/UL]*
stop on shutdown

respawn

exec start-stop-daemon --start --make-pidfile --pidfile /var/run/serviio.pid -c $USER --exec /opt/serviio/bin/serviio.sh

(the LANG setting is optional and can be used to define a specific locale)

You can now start the DLNA server (also stop or restart) using the service command:

service serviio start

 
As everything went fine (of course!), you should soon see the server on any UPnP/DLNA device connected to the same subnet. If not, look for suspicious entries in /opt/serviio/log/serviio.log. If you need a more verbose log, modify the org.serviio category as follows in /opt/serviio/config/log4j.xml:

<category name="org.serviio">
   <priority value="DEBUG"/>
</category>

 
and restart Serviio. Now, you should have some clues to help you solve the problem.

One last useful tip: Unfortunately, Serviio lacks a web console in our headless setup. You can find some, proposed by users on Serviio forum, but the easiest solution, for now, is still to install the console on a local Windows client to remotely manage your server settings. Before launching this console, make sure to edit the C:\Program Files\Serviio\bin\ServiioConsole.exe.vmoptions file on the client, add the following line:

-Dserviio.remoteHost=serviio_server_ip_address

 
and everything should be fine.

That’s all Folks!


For further reading, see Serviio very informative wiki and forum.

Useful commands #2: Removing old kernels

Leave a comment

Successfully tested on Ubuntu Server 12.04 LTS 64-bit

In a recent post, I explained how important it is to keep your operating system up to date. If you followed my advices, you may have noticed that Ubuntu’s package manager does not delete any old kernel when upgrading to a new one. It’s on purpose, just to have a known good kernel around in case the upgrade fails. While this is a rather reassuring behavior, you could also want to get rid of these old kernels (to free up some space on your hard disk for example). Let’s see how.

Before doing any cleaning, first write down your current kernel release. You’ll find it by running:

uname -r

 
Next, simulate the old kernels removal:

dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get --dry-run remove

 
Here, the –dry-run parameter allows to see the events that would occur during real removal but no change is actually done to the system. Check all the informations displayed on screen to make sure there was no error and verify that your current kernel release was not listed anywhere.

If everything looks fine, you can run the command for real:

dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get -y purge

 
Old kernels are history now.

That’s all Folks!


For further reading, see the Ubuntu wiki to understand why this removal is not so easy to automate.

Installing a CA certificate on Ubuntu

4 Comments

Successfully tested on Ubuntu Server 12.04 LTS 64-bit

SSL/TLS certificates are everywhere. Whether you connect to your online bank account, setup an FTPS server or sign your applications, you use SSL/TLS certificates. All these certificates have been issued by a certification authority (CA) which your operating system must recognize as a trusted third party. This recognition relies on the CA certificate installation.

In the following example, we’ll install the Class 1 Primary Intermediate Server CA certificate from StartCom, a CA particularly known to supply free domain validated certificates (see StartSSL website for more information). As StartCom Root CA certificate is already installed by default in /usr/share/ca-certificates/mozilla, we’ll use the same path for its intermediate CA certficate.

First, download the certificate:

sudo wget https://www.startssl.com/certs/sub.class1.server.ca.pem -O /usr/share/ca-certificates/mozilla/StartCom_Class_1_Primary_Intermediate_Server_CA.crt

 
Then, add the path to this new certificate (relative to /usr/share/ca-certificates) in /etc/ca-certificates.conf:

mozilla/StartCom_Class_1_Primary_Intermediate_Server_CA.crt

 
Finally, now that everything is in place, just launch:

sudo update-ca-certificates

 
to complete the installation. During this process, /etc/ssl/certs folder’s content will be updated to hold the SSL certificates and ca-certificates.crt, a concatenated single-file list of certificates.

That’s all Folks!


For further reading, refer to Ubuntu manuals.

Useful commands #1: Preventing the update of a package

Leave a comment

Successfully tested on Ubuntu Server 12.04 LTS 64-bit

Doing frequent updates of your favorite OS and programs is always recommended. Not only does it allow you to take advantage of new features but it also minimizes the security risks by correcting the possible flaws spotted since the installation or the previous update.

In Ubuntu, software updates can be either automatic (see Automatic Updates in the official documentation for details) or… manual. If you choose to go the manual way, you’ll have to make sure to do the updates by yourself on a regular basis (Ubuntu’s welcome screen advises you of updates availability) using two commands:

sudo apt-get update

 
first, to re-synchronize the package index files from their sources (the repositories are listed in /etc/apt/sources.list), followed by:

sudo apt-get upgrade

 
to finally install the newest versions of all packages currently installed on the system.

This full update in one shot is very handy of course, but what to do if you don’t want to update a specific package? For instance, let say you patched and rebuilt a program for whatever reason and you don’t want it to be replaced by the new latest official version. What to do? This is where today’s useful command comes in:

sudo apt-mark hold package_name

 
Now, this package will never be updated automatically as well as manually as long as it is on “hold” status. To display this status, you can use:

dpkg --get-selections | grep "package_name"

 
Finally, the day you decide to allow the upgrade to the latest version available in the official repository, just type:

sudo apt-mark unhold package_name

 
to put the package back on “install” status.

That’s all Folks!


For further reading, take a look at Package Management in Ubuntu’s official documentation.

Using scanner buttons on Ubuntu with scanbd (part 2/2)

8 Comments

Successfully tested on Ubuntu Server 10.04 LTS 64-bit

Few days ago, I described how to build and install scanbd. Now, it needs to be configured to perfectly suit the scanner it’s used with. As you’ll see, you have some very interesting possibilities with a four buttons scanner such as the EPSON Perfection V200 Photo.

First, install xinetd which will allow to use scanbd as a wrapper:

apt-get install xinetd

 
Create a sane-port service configuration file /etc/xinetd.d/sane-port with the following content:

service sane-port
{
socket_type = stream
server = /usr/local/bin/scanbd
server_args = -m -c /usr/local/etc/scanbd/scanbd.conf
protocol = tcp
user = saned
group = saned
wait = no
disable = no
}

 
Stop saned service

service saned stop

 
and disable it as it will now be launched through xinetd/scanbd. Just modify /etc/default/saned as follows:

RUN=no

 
Now, restart xinetd:

service xinetd restart

 
It should return:

 * Stopping internet superserver xinetd                             [ OK ]
 * Starting internet superserver xinetd                             [ OK ]

 
Next, create your own /usr/local/etc/scanbd/scanbd.conf file (keep the original file, just in case…) to describe the available actions (buttons) on your scanner model. The configuration file I created for the EPSON Perfection V200 Photo is available here.
 
Copy the scanbd.debian initialisation script located in scanbd source directory to /etc/init.d/scanbd and install its link using the following command:

update-rc.d scanbd defaults

 
Make sure all the backends except the SANE network backend are commented out in /etc/sane.d/dll.conf:

net

 
Uncomment the following line at the end of /etc/sane.d/net.conf:

localhost

 
Comment out the SANE backend for EPSON scanners in /etc/sane.d/dll.d/iscan:

#epkowa

 
Create a /usr/local/etc/scanbd/dll.conf file including the following line:

epkowa

 
Copy (don’t move!) /etc/sane.d/epkowa.conf to /usr/local/etc/scanbd/epkowa.conf.

Copy /etc/sane.d/saned.conf to /usr/local/etc/scanbd/saned.conf.

Then, verify that you have no access list entry configured in /etc/sane.d/saned.conf and add one in /usr/local/etc/scanbd/saned.conf to restrict access to local subnet hosts only (adapt to your own network configuration):

192.168.253.0/24

 
Now that scanbd is configured for both local and LAN hosts access, let’s continue with the most interesting part of the configuration: The script executed when each button is pressed. You’ll find here the one I use to manage the 4 buttons “Start”, “Copy”, “Email” and “Pdf” available on the EPSON Perfection V200 Photo. Save it as /usr/local/etc/scanbd/actions.sh and make it executable with a chmod 755 command.

In association with my scanner model, this script offers the following functions:
– Single page scan to JPEG
– Instant copy (scan to printer)
– Email creation with JPEG or multi-page PDF attachment
Multi-page PDF creation
All this using only the scanner front buttons!

The buttons usage is explained at the beginning of the script file, along with some variables (such as SCANDIR and PRINTER) you’ll have to modify according to your needs. Also make sure to have imagemagick and mpack packages installed. If not, install them:

apt-get install imagemagick mpack

 
Scanbd setup is complete now but I added a last refinement. Having xinetd always running on the server, just because of the scanner buttons, bothered me (I don’t have any other service depending on xinetd). I updated the existing udev rule (previously added to assign the scanner to the saned group) to automatically start/stop the internet superserver when turning on/off the scanner, respectively. All you have to do is to replace your existing “scanner” udev rule (mine was /etc/udev/rules.d/40-saned.rules) with the following file and disable xinetd, scanbd and saned startup scripts using the following three commands:

update-rc.d xinetd disable
update-rc.d scanbd disable
update-rc.d saned disable

 
If ever you have other services depending on xinetd and only want to stop the scanbd service, take a look at the chkconfig package.

That’s all Folks!

(Thanks for the help, bro. You’re da man!)


For further reading, see scanbd website and Gentoo udev Guide.

Using scanner buttons on Ubuntu with scanbd (part 1/2)

Leave a comment

Successfully tested on Ubuntu Server 10.04 LTS 64-bit

After the successful installation of my scanner, I discovered with frustration that the four hard buttons of the device were not supported by the default backend. Few days later, after thorough searches, I installed an old scanner buttons polling daemon called scanbuttond and found out it was conflicting with saned, the daemon used to share the scanner over the network.

I was about to give up when I came across the scanbd project. This clever daemon opens, polls, locks the scanner and then acts as a kind of proxy which manages all further access to the device by any other application, thus avoiding possible conflicts.

I had a hard time installing and configuring scanbd but it was worth it. I’ll describe the steps I followed in two separate posts. Today’s post will explain how to compile scanbd with EPSON Perfection V200 Photo support and my next post will be about its complete configuration, including a nice script which perfectly manages the scanner four buttons.
 
So, let’s start by downloading the latest source code from scanbd project website:

wget link_to_latest_scanbd_source_code

 
Make sure the /usr/local/src directory exists and is writable by your primary user account. Then, unpack the file:

tar xf scanbd_source.tgz -C /usr/local/src

 
Scanbd can use SANE or scanbuttond backends. Unfortunately, the epkowa (SANE) backend which is used to control the EPSON Perfection V200 Photo does not fully support the front buttons. Therefore, I had to look for a compatible backend… and I found one, thanks to www.linotux.ch.

To patch scanbd to use this specific backend, cd to the directory where you extracted scanbd source code and modify scanbuttond/backends/Makefile by adding references to epson_vphoto as follows:

all: epson_vphoto.so mustek.so plustek.so plustek_umax.so snapscan.so ...

epson_vphoto.so: epson_vphoto.c epson_vphoto.h

 
Then, download the epson_vphoto backend and extract it to the same current scanbuttond/backends directory.

Finally, add the following line at the end of scanbuttond/backends/meta.conf:

epson_vphoto

 
OK, we’re almost ready to compile but, as Ubuntu does not come by default with the compilation tools required, we’ll need to install them first:

apt-get install build-essential checkinstall

 
And while we’re at it, let’s also install some specific packages needed to compile or use scanbd:

apt-get install libconfuse-dev libusb-dev libudev-dev libdbus-1-dev dbus

 
Now, build

USE_SCANBUTTOND=yes make -e clean all

 
and install:

USE_SCANBUTTOND=yes checkinstall --deldesc=yes

 
When asked for, you can enter the following packaging informations (modify according to your version):

This package will be built according to these values:

0 -  Maintainer: [ Wilhelm Meier <wilhelm.meier@fh-kl.de> ]
1 -  Summary: [ Scanner button daemon ]
2 -  Name:    [ scanbd ]
3 -  Version: [ 1.2 ]
4 -  Release: [ 1 ]
5 -  License: [ GPL ]
6 -  Group:   [ Misc ]
7 -  Architecture: [ amd64 ]
8 -  Source location: [ scanbd-1.2 ]
9 -  Alternate source location: [  ]
10 - Requires: [  ]
11 - Provides: [ scanbd ]

Enter a number to change any of them or press ENTER to continue:

 
VoilĂ ! Package is built and install is done. We’ll take care of the complete configuration in part 2.

That’s all Folks!


For further reading, see scanbd website and CompilingEasyHowTo of the Community Ubuntu Documentation.

Older Entries