Linux Zone


Page Last Updated: 17 July 2010

Intro

This page contains some Linux notes. It relates to Fedora 12. This works on my system. It may not all work on yours but hopefully some of it will be useful.

RPM Fusion Repo

Many applications are in the RPMfusion repository which isn't set up by default. This can be added graphically via Firefox. Go to http://rpmfusion.org/Configuration and click on the link for Fedora 12 to enable access to the free repository. Repeat using the link to the nonfree repository.

Hauppauge PVR150

The Hauppauge PVR150 is a linux friendly video capture card with an mpeg2 hardware encoder. The PVR250 and PVR350 are similar but with a higher spec. I bought a second hand PVR150 from ebay very cheaply. What follows relates to using a Hauppauge PVR150 on Fedora.

Connect up the card by connecting a device (e.g. digibox) to the composite input and/or by plugging a TV aerial into the RF socket.

Once it's connected install the software:

yum install ivtv-utils
yum install ivtv-firmware

You can now control the card using the v4l2-ctl command. Enter 'v4l2-ctl --list-ctrls-menus' to see the settings explained.

I have a shell script called pvr150_init to initialise my card to the correct settings which I invoke prior to using it:

#!/bin/sh
# pvr150_init - initialise PVR150 capture card prior to use

# PAL-I for UK
v4l2-ctl -s pal-I

# MPEG-2 Program Stream
v4l2-ctl -c stream_type=0

v4l2-ctl -c insert_navigation_packets=0
v4l2-ctl -c stream_vbi_format=0

# 16x9
v4l2-ctl -c video_aspect=2
# 4x3
#v4l2-ctl -c video_aspect=1

v4l2-ctl -c video_bitrate=8000000
v4l2-ctl -c video_peak_bitrate=8000000
v4l2-ctl -c video_b_frames=2
v4l2-ctl -c video_gop_closure=1

# 48 kHz
v4l2-ctl -c audio_sampling_frequency=1

# MPEG-1/2 Layer II
v4l2-ctl -c audio_encoding=1

# 384 kbps
v4l2-ctl -c audio_layer_ii_bitrate=13

# Stereo
v4l2-ctl -c audio_stereo_mode=0

# No Emphasis
v4l2-ctl -c audio_emphasis=0

# No CRC
v4l2-ctl -c audio_crc=0

# set to composite input
v4l2-ctl -i 2

#87%
v4l2-ctl --set-ctrl=volume=57016

This sets the card to capture from the composite input. Note that this will also set the card to PAL 16:9 and you may need different settings.

Issue the command 'pvr150_init' as root to initialise the card.

If you are capturing a source that has a 4:3 aspect ratio then enter this command after pvr150_init:

v4l2-ctl -c video_aspect=1

Next add your user account (whatever you normally login as) to the group 'video'.

To do this:

    Go into system/administration/users and groups in the gnome menu
    Double click on your user name to bring up user properties
    Click on the groups tab to show the groups that the user is a member of
    Scroll down and check the box for the video group

You may have to logout and back in for this to take effect.

Now test it works:

mplayer /dev/video0

You should now see the video on the PC screen corresponding to the composite input of th PVR150.
Enter 'q' to quit mplayer

To record it as a file issue the command:

mplayer -dumpstream -dumpfile recording.mpg /dev/video0

Press ctrlc-c to quit when you are finished

This will create an MPEG-2 file called recording.mpg.

If you want proper PVR functionality you will need to install some software such as MythTV.

Encoding Videos Using HandBrake

You can use HandBrake to encode videos into MPEG-4 files.

Download the Fedora 12 HandBrake CLI and GUI rpms from http://handbrake.fr/downloads.php

Install Handbrake:

rpm -i HandBrake-0.9.4-Fedora_CLI_x86_64.rpm
rpm -i HandBrake-0.9.4-Fedora_GUI_x86_64.rpm

HandBrake can be used via its gui or via the command line (using HandBrakeCLI).

To encode an mpeg2 file with HandBrakeCLI into an mp4 file you could use the command:

HandBrakeCLI -i inputfile.mpg -o outputfile.mp4 --preset="Normal"

If you prefer to create matroska (mkv) files then use this command instead:

HandBrakeCLI -i inputfile.mpg -o outputfile.mkv --preset="Normal"

This will create a file called outputfile.mp4 (or outputfile.mkv) with h264 video track and aac audio track from an input file called inputfile.mpg. It will automatically crop the file to remove black bands. The input file doesn't have to be an mpg file. You can also use HandBrake to encode other files (e.g. avi files) or your DVDs for backup purposes. To read DVDs you may need to install the libdvdcss2 package. You can get this from http://rpm.pbone.net/.

If you need to edit an mpeg2 file before encoding it with HandBrake you can use dvbcut. To install it enter 'yum install dvbcut'. Edit the file and save it as a new mpg file.

Mpeg Video Files

Software Tools

These are some tools that will be useful:

    Mediainfo (download the rpm from http://mediainfo.sourceforge.net/en/Download/Fedora)
    MP4Box (yum install gpac)
    Matroska tools (yum install mkvtoolnix mkvtoolnix-gui)
    MediaTomb UPnP MediaServer (yum install mediatomb)
    Mplayer (yum install mplayer)
    dvbcut (yum install dvbcut)
    HandBrake (download the rpms from http://handbrake.fr/downloads3.php)
    DeVeDe (yum install devede)

These examples are for files which have 1 track of h264 video and 1 track of aac 2 channel audio.

How to convert mp4 to mkv

Use mkvmerge GUI. Click the add button, navigate to the mp4 file, open it, then click start muxing. Using this method is lossless (doesn't reduce quality). It will demux (extract tracks from old container) and then remux (add tracks to new container) and will take only a couple of minutes.

How to convert mkv to mp4

Use mkvextract to extract the tracks from the mkv file.
Optionally convert the audio track to aac.
Use mp4box to combine into an mp4.

Example:

mkvextract tracks file.mkv 1:temp.h264 2:temp.aac
MP4Box -add temp.h264 -add temp.aac file.mp4

If the mkv contained an ogg vorbis track we wanted to convert to aac we could have added a convert step after the mkvextract:

ffmpeg -i temp.ogg -ab 160k temp.aac

How to fix the aspect ratio of an mp4 without re-encoding

If you've encoded a file using source PAL 16:9 (par 1.422) and it should have been PAL 4:3 (par 1.067) then you can fix it without re-encoding by using mp4box to change the par.

Example of setting PAR to 16:15 on an mp4 file:

# extract h264 video file track 1
MP4Box -raw 1 file.mp4 -out temp.h264

# extract aac audio file track 2
MP4Box -raw 2 file.mp4 -out temp.aac

# combine back together with corrected par
MP4Box -add temp.h264 -add temp.aac -par 1=16:15 file_new.mp4

Or you can combine it in to one command:

MP4Box -add file.mp4#1:par=16:15 -add file.mp4#2 file_new.mp4

More generally you can set the aspect ratio to anything you want using the formula PAR = desired aspect ratio / (width / height). Decide what aspect ratio you want then use Mediainfo to find the width and height. If you don't know the correct aspect ratio then try mplayer with the -aspect switch to see which looks right. Common aspect ratios are 16:9, 2.35:1, 4:3.

How to create a DVD from an mp4 file

You need to convert the mp4 to a DVD compatible mpeg.
You can use DeVeDe for this. This will produce an ISO image from the mp4 file. You can then burn the ISO image to DVD using Brasero or K3b. Check the aspect ratio is correct in 'Advanced options/video format' and check the output using 'preview' before creating the DVD image.

Using Mediainfo

You can use Mediainfo to display information about your files. Use -f to get full information.

For example if you use 'mediainfo -f file.mpg' to get information on an mpeg2 file captured by a Hauppauge PVR150 card you will see:.

    TV stdDARSizePAR
    PAL16:9720 x 5761.422 (64:45)
    PAL4:3720 x 5761.067 (16:15)
    NTSC16:9720 x 4801.185 (32:27)
    NTSC4:3720 x 4800.889 (8:9)

What you see will depend on what aspect ratio (DAR) and TV standard you used to initialise your card.

PAR stands for pixel aspect ratio and you will see that they are non square (also known as anamorphic).

PAR and DAR are related by the formula:

    DAR = (width / height) * PAR

So for PAL 16:9:

    DAR = (720 / 576) * (64/45)
    = 1.778 (or 16:9)

If you use 'mediainfo -f file.mp4' to get information on an mpeg4 file created by HandBrakeCLI from an mpeg2 file you will see for example:

    DAR = 2.289, size = 702 x 436, PAR = 1.422

The size and DAR may have changed since the image will have been cropped to remove black bands. If you used HandBrakeCLI with preset normal the PAR will have stayed the same as the source.

Non-Anamorphic Encodings

The files created by the capture card are anamorphic (non-square pixels). HandBrakeCLI with preset normal keeps the same PAR as the source file so the resulting mpeg4 file is also anamorphic.

If you prefer you can create non-anamorphic files (i.e. with PAR of 1:1). To do this use HandBrake GUI , click picture settings and set Anamorphic to 'off'. When creating the mpeg4 file HandBrake will automatically resize it so that the aspect ratio is correct.

For example:

    anamorphic file: DAR = 2.289, size = 702 x 436, PAR = 1.422
    non-anamorphic file: DAR = 2.289, size = 998 x 436, PAR = 1.000

The PAR of the non-anamorphic file has changed to 1:1 and HandBrake has resized the file to 998 x 436 to maintain the correct aspect ratio.

Managing Video Files

If you have a movie collection you can use Griffith to catalogue them. You enter the name of your movie and it will get all the information from the the IMDB and add it to the database. You can then search the database on actor, director, title etc. To install it 'yum install griffith PyXML'.

Services

Using the webserver service httpd as an example.

Start the service:

service httpd start

Stop the service:

service httpd stop

Restart the service:

service httpd restart

Show service status:

service httpd status

Show status of all services:

service --status-all

Set the service to start automatically at boot time:

chkconfig httpd on

Set the service to start automatically at boot time in run levels 3 and 5 only:

chkconfig --level 35 httpd on

Set the service to not start automatically at boot time:

chkconfig httpd off

Set the service to not start automatically at boot time in run level 3 only:

chkconfig --level 3 httpd off

Display the runlevels the service will automatically start in at boot time:

chkconfig --list httpd

To control the services via the gui:

yum install system-config-services

Setting Up MediaTomb

MediaTomb is a UPnP MediaServer. You can use it to stream your media files to a UPnP compatible device, in my case an LG BD390 blu-ray home networking hub.

To setup MediaTomb:

Install it:
    yum install mediatomb

Now edit /etc/mediatomb.conf and change the MT_INTERFACE line to:
    MT_INTERFACE="eth0"

Now type 'mediatomb' to start it. It should display the ip address and port it's listening on for example http://192.168.0.2:49152/
Now type ctrl-c to stop it.

If you want to play Matroska (mkv) files then edit ~/.mediatomb/config.xml and add this line in the extension-mimetype section:
    <map from="mkv" to="video/x-matroska"/>

change firewall:
    allow UDP port 1900 (required for SSDP)
    allow UDP/TCP port of MediaTomb (49152).
    By default MediaTomb will select a free port starting with 49152, however you can specify a port of your choice in the configuration file.

Now start mediatomb:
    mediatomb

Can then add media in firefox:
    Enter http://192.168.0.2:49152/ in the Firefox URL
    Click on Filesystem
    Navigate to the folder that contains your media files and select that folder
    Click on the plus sign at the top right of the screen
    Now click on database (you should see new folders including a video folder)
    Click on the video folder and you should see your your videos in the database

NB. The MediaTomb web interface allows any user to browse all of your files. If this is a concern then disable the UI. See MediaTomb documentation.

Now set up the LG BD390:

    Select setup
    Select network
    Select connection setting
    Set connection type to wired
    Select connection status - it should show 'wired network' and the MAC/IP address showing it is connected
    Select My Media
    It should then scan and detect the MediaTomb server. If it doesn't check your firewall
    Select MediaTomb, then the video folder, then select a file and it should play it
    when you are finished stop mediatomb with ctrl-c

Setting up MediaTomb as a Service

    From a terminal su into root
    enter 'service mediatomb start'
    then 'service mediatomb stop'
    If you want to play Matroska (mkv) files then edit /etc/mediatomb/config.xml and add this line in the extension-mimetype section:
        <map from="mkv" to="video/x-matroska"/>
    enter 'service mediatomb start'
    Enter http://192.168.0.2:50500/ in the Firefox URL
    Click on Filesystem
    Navigate to the folder that contains your media files and select that folder
    Click on the plus sign at the top right of the screen
    Now click on database (you should see new folders including a video folder)
    Click on the video folder and you should see your your media files in the database

Note that the port when starting mediatomb as a service is 50500 not 49152.
Change firewall to allow UDP/TCP port 50500 and UDP port 1900 .
See /var/log/mediatomb for messages output by mediatomb
You can change the port in /etc/mediatomb.conf

Now set the service to start at bootup in runlevels 3 and 5:

    chkconfig --list mediatomb
    chkconfig --level 35 mediatomb on
    chkconfig --list mediatomb

If you find that the mediatomb service doesn't start at boot time then:

    Change the load order so that the mediatomb service starts after NetworkManager:
        mv /etc/rc.d/rc5.d/S20mediatomb /etc/rc.d/rc5.d/S85mediatomb

    Edit /etc/init.d/mediatomb and add a 'sleep 10' command at the beginning so it waits 10 seconds

NFS

Use NFS to setup fileshares between the Linux computers on your network.

On the PC where you want the NFS share setup the /etc/exports file with the data to share and the machines allowed to access it.

Here is an example which allows a machine on your network with ip address 192.168.0.3 to access a folder called /data/shared:

#
# Allow 192.168.0.3 to access nfs shared folders
#
# Allow rw access to the /data/shared folder
/data/shared 192.168.0.3(rw,sync,no_root_squash)

You can specify a range of ip addresses allowed access using a hyphen e.g. 192.168.0.3-192.168.0.10

Next install nfs-utils:

yum install nfs-utils

Then start the services:

service rpcbind start
service nfs start

Configure the service to start automatically in runlevels 3 & 5:

/sbin/chkconfig --list nfs
/sbin/chkconfig --level 35 nfs on
/sbin/chkconfig --list nfs

Edit the file "/etc/sysconfig/nfs" and add the following lines at the end:

STATD_PORT=4001
LOCKD_TCPPORT=4002
LOCKD_UDPPORT=4002
MOUNTD_PORT=4003

Edit the file "/etc/services" and add the following lines at the end:

rquotad 4004/tcp # rpc.rquotad tcp port
rquotad 4004/udp # rpc.rquotad udp port

Open these ports in the firewall:

    111:tcp, 111:udp
    2049:tcp, 2049:udp
    4001:tcp, 4001:udp
    4002:tcp, 4002:udp
    4003:tcp, 4003:udp
    4004:tcp, 4004:udp

Restart the nfs services

On the client that wants to access the share:

Prepare the client:

yum install nfs-utils
service rpcbind start
service nfslock start
mkdir /mnt/shared 

Mount the share:

mount -t nfs 192.168.0.2:/data/shared /mnt/shared

This assumes the server with the data to be accessed has ip address 192.168.0.2.

Samba

Use Samba to setup fileshares between the Linux and windows computers on your network.

Install samba (yum install samba).

set samba as trusted service in the firewall.

Edit /etc/samba/smb.conf and add an entry for a share called 'shared':

# jc samba shares
[shared]
comment = shared
browseable = yes
path = /data/shared
writable = yes
public = yes

Do SE Linux changes (see notes at top of smb.conf):

setsebool -P samba_domain_controller on

#label as samba share
chcon -t samba_share_t /data/shared

#check it worked
ls -ldZ /data/shared

setsebool -P samba_export_all_ro on

start samba service:

/etc/init.d/smb start

start it in runlevels 3 & 5 at boot time:

/sbin/chkconfig --list smb
/sbin/chkconfig --level 35 smb on
/sbin/chkconfig --list smb

Add a samba user:

smbpasswd -a john
password xxx

restart samba service:

/etc/init.d/smb restart

On the client that wants to access the share enter a command to mount the share:

mount -t cifs //192.168.0.2:/shared /mnt/shared -o user=john,passwd=xxx

This assumes the server with the data to be accessed has ip address 192.168.0.2.

Sharing a Printer with Samba

This relates to an HP Deskjet D2360 printer.

Add the printer in the [printers] section of etc/samba/smb.conf:

[printers]
comment = All Printers
path = /var/spool/samba
browseable = no
guest ok = no
writable = no
printable = yes
#jc
printer name = Deskjet-D2300-series
printer = Deskjet-D2300-series
public = yes
guest ok = yes

On the client that wants to use the printer:

yum install samba-client

# For HP printer
yum install hpijs

In the firewall check the box for samba client to allow 137/udp, 138/udp

Now add the printer on the client:

    System/administration/printing
    click the 'new' button
    select Windows Printer via SAMBA
    enter the printer as
        smb://192.168.0.2/Deskjet-D2300-series
    press the 'verify' button'
    it should say 'the print share is accessible'
    click 'forward' button
    select printer from database
    select Deskjet D2300
    select print a test page

Remote Desktop

Go into System/preferences/remote desktop and check 'Allow other users to control your desktop'.
Check 'require user to enter a 'password'.
In the firewall open TCP/UDP ports 5900.

On the PC that wants to control your desktop:

yum install tigervnc
vncviewer ipaddr

where ipaddr is the ip address of the machine you want to control.
Use F8 to get the menu and go into fullscreen.

Wake On LAN

Here is a Perl script to suspend your PC and allow it to be woken by a wol magic packet.

#!/usr/bin/perl -w
# suspend.pl
# This program suspends the PC and allows it
# to be woken with a WOL magic packet
#
use strict;

#ensure wol enabled
system("/sbin/ethtool -s eth0 wol g");

my $wakeup = `/bin/cat /proc/acpi/wakeup|grep PCI0`;

#
# PCI0 must be enabled.
# This command toggles the enabled status
# so only issue it if currently disabled.
#
if (index($wakeup,"disabled") != -1) {
   print "setting wakeup to enabled";
   system("/bin/echo -n PCI0 >> /proc/acpi/wakeup")
}

# suspend the PC
system("/usr/sbin/pm-suspend");

Your PC must be wol capable for this to work. If you type 'ethtool eth0' then it should display 'wake on g' or something similar. If the g is missing then your PC doesn't support it. Also you may have to enable it in your BIOS.

To wake the PC remotely from another PC use the 'etherwake' command.

Development

C Programming

Packages needed:

# C compiler
yum install gcc

# C++ compiler
yum install gcc-c++

# GNU build tools
yum install make autoconf automake

# RPM building
yum install rpm-build

# To create patches
yum install patch diffutils

We will create a Hello World example application. Create a directory called hello-0.1 and cd into it.
Type in a program and save it as hello.c:

#include <stdio.h>
int main(void)
{
    printf("Hello, world!\n");
    return 0;
}

Compile it to create an executable file called hello:

gcc hello.c -o hello

Run it to print "Hello, world!":

./hello

Using GNU Build Tools

For bigger applications you can use GNU Build Tools.

To use GNU build tools to build the hello world application:

Change directory into hello-0.1

Create a file called Makefile.am containing these 2 lines:

bin_PROGRAMS = hello
hello_SOURCES = hello.c

Next create the configure.ac file:

# enter 'autoscan' to create configure.scan file
autoscan

# rename configure.scan to configure.ac
mv configure.scan  configure.ac    

Now edit the configure.ac file.
Change the AC_INIT line and add the package name (hello) and version(0.1).
Add the line 'AM_INIT_AUTOMAKE' after the AC_INIT line.
Your configure.ac file should look something like this:

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.63])
AC_INIT(hello, 0.1)
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CC

# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

AC_CONFIG_FILES([Makefile])
AC_OUTPUT

Now create the file config.h.in using the autoheader command:

autoheader

Now create the file aclocal.m4 using the aclocal command:

aclocal

Now add files required by automake:

touch NEWS README AUTHORS ChangeLog

Now use automake to create the file Makefile.in:

automake --add-missing --copy

Now use autoconf to create the configure script:

autoconf

Now run the configure script to create the Makefile file and config.h file:

./configure

Now build it:

make

Install it:

# as root
make install

Make a source tarball called hello-0.1.tar.gz:

make clean
cd ..
tar -zcf hello-0.1.tar.gz hello-0.1/   

This source tarball can be built with the usual commands:

./configure
make
make install

Creating an RPM File

Applications on Linux are often distributed as a source tarball which can be built on any distro. From this you can create packages for specific distros. Fedora uses RPM packages so to build a Fedora package we need to create an RPM.

You should build RPMs as a normal user (not root) so there is no chance of overwriting live system files.

First setup the rpm build environment:

# do these 2 commands as normal user
mkdir -p ~/rpmbuild/{BUILD,RPMS,S{OURCE,PEC,RPM}S}
echo "%_topdir $HOME/rpmbuild" > ~/.rpmmacros

# as root user
yum install rpm-build

Now let's take the source tarball hello-0.1.tar.gz that we made previously and create an RPM file from it.

First copy hello-0.1.tar.gz into the rpmbuild sources folder:

cp ~/hello-0.1.tar.gz ~/rpmbuild/SOURCES/

Next create a spec file:

Name:           hello
Version:        0.1
Release:        1%{?dist}
Summary:        Hello World RPM example

Group:          Applications/Text
License:        GPL
URL:            http://localhost/projects/linuxzone/
Source0:        hello-0.1.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) 

%description 
Hello World example RPM

%prep
%setup -q

%build
%configure
make %{?_smp_mflags} 

%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT %find_lang %{name}
rm -f $RPM_BUILD_ROOT%{_infodir}/dir 

%files
%defattr(-,root,root,-)
%{_bindir}/hello
    
%changelog
* Sun May 16 2010 - jc
- Initial implementation

Save this file as ~/rpmbuild/SPECS/hello.spec

Next change directory into the rpmbuild folder:

cd ~/rpmbuild/

Issue the command to build the rpms:

rpmbuild -ba SPECS/hello.spec

This should create the binary rpm as ~/rpmbuild/RPMS/x86_64/hello-0.1-1.fc12.x86_64.rpm and the source rpm as ~/rpmbuild/SRPMS/hello-0.1-1.fc12.src.rpm. When creating an RPM from a source tarball you should not change the tarball. The source tarball is pristine source. If you need to change it then you should create a patch file and apply that when building the RPM.

Creating a Patch

If you have a project folder called hello-0.1 and you want to make changes and then create a patch file:

Copy the folder hello-0.1 to hello-0.1-orig.
Make the changes in the hello-0.1 folder.
When you are finished issue a command to create the patch file:

diff -Naur -x '*~' hello-0.1-orig hello-0.1 > hello-0.1.patch

This will create a patch file containing all the changes you made to files in the project folder and subfolders.
Use -x to exclude files you don't want in the patch.
You can distribute this and users can apply it to their hello-0.1 folder using the command:

patch -p0 <hello-0.1.patch

You can also apply it when building an RPM. To do this put the patch file in the SOURCE folder with the source tarball and add a line in the spec file to apply the patch.

Compiling Hints

When you want to compile a source tarball the first thing you usually do is type './configure'. This usually fails because there will be prerequisite packages missing on your system. If the ./configure error message says that 'foo is required to build the package' then you need to install foo and then try ./configure again.

If you can't find the package then try typing:

yum whatprovides foo

or:

yum whatprovides */foo

or:

yum search foo

This will list the packages that might provide the missing item. If there are 2 packages with one ending in -devel then it's the devel package you need.

Install the package:

yum install foo-devel

Do ./configure again and repeat until it completes OK.


Python Programming

Packages needed:

yum install python-devel

We will create a Hello World example application. Create a directory called hello-0.1 and cd into it.
Type in a program and save it as hello.py:

#!/usr/bin/python
print "Hello, World!"

To run it:

python hello.py

or you can make the file executable and run it by typing its name:

chmod a+x hello.py
./hello.py

Using Distutils

For bigger applications you can use Distutils.

To create a source distribution create a file called setup.py:

from distutils.core import setup
setup(name='hello',
      version='0.1',
      py_modules=['hello'],
      )

Create the source distribution:

python setup.py sdist

This will create a folder called dist containing a source tarball called hello-0.1.tar.gz.

To create an RPM:

python setup.py bdist_rpm

This will create source and binary RPMs in the dist folder.

To install the application from the source tarball the user will type:

python setup.py install

and then run it with:

python
import hello

In practice you would probably provide a script to start the application.

GTK Programming

Packages needed:

yum install gtk2-devel

You can use GTK to create GUI programs.

Here is a C hello world example using GTK:

#include <gtk/gtk.h>

// hellogtk.c - GTK Hello World 

int main( int   argc, char *argv[] )
{
    GtkWidget *window;
    GtkWidget *label;
    
    gtk_init(&argc, &argv);    

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect
      (window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
    label = gtk_label_new("Hello, World!");
    gtk_container_add(GTK_CONTAINER (window), label);
    gtk_widget_show_all(window);
    
    gtk_main();
    
    return 0;
}

To compile it:

gcc hellogtk.c -o hellogtk `pkg-config --cflags --libs gtk+-2.0`

To run it:

./hellogtk

Here is a Python hello world example using PyGTK:

#!/usr/bin/python
# hellopygtk.py - pyGTK Hello World

import pygtk
pygtk.require('2.0')
import gtk

window = gtk.Window()
window.connect("delete-event", gtk.main_quit)
label = gtk.Label("Hello World!")
window.add(label)
window.show_all()
gtk.main()

To run it:

python hellopygtk.py 

Cryptsetup

You can use cryptsetup to encrypt your data. You can encrypt a partition or set up a file system on a file using a loop device. I'll use the second method. This creates a file that can be easily backed up or copied to a USB stick.

First create the file:

dd if=/dev/urandom of=encfile bs=1M count=500

This creates a 500M file called encfile.

Now associate it with a loop device:

losetup /dev/loop0 encfile 

Now initialise a LUKS partition:

cryptsetup --verify-passphrase luksFormat --cipher aes --key-size 256 /dev/loop0

This will ask you for a passphrase. Pick a secure one (not too short, not one other people might guess).

Now open the LUKS partition and set up a mapping name:

cryptsetup luksOpen /dev/loop0 encmap

Format the partition:

mkfs -t ext3 -j /dev/mapper/encmap

Close the LUKS partition:

cryptsetup luksClose encmap

and detach the file from the loop device:

losetup -d /dev/loop0

That's it.

Now setup a couple of scripts to make it easy to use.

This will mount the file system on /mnt/secure (it will ask for the passphrase):

#!/bin/sh
# mntsec - mount encrypted file 
losetup /dev/loop0 /data/encfile
cryptsetup luksOpen /dev/loop0 encmap
mount /dev/mapper/encmap /mnt/secure

This will unmount the file system:

#!/bin/sh
# umntsec - unmount encrypted file 
umount /mnt/secure
cryptsetup luksClose encmap
losetup -d /dev/loop0 

VirtualBox

How to use VirtualBox to set up a virtual Machine.
This example has Fedora 64 bit OS (the host) running a Fedora 32 bit VM (the guest).

First install VirtualBox:

yum install VirtualBox-OSE

Reboot.

You can install the guest VM yourself or if you are lazy you can download a prebuilt one. I will download a prebuilt one from VirtualBoxes. Navigate to the images download section for Fedora and download the Fedora 12 image (Fedora-12-i686-gnome.7z).

Next extract the image. It's a 7zip image so you'll need to install that.

# install 7zip
yum install p7zip

# extract the image
7za x Fedora-12-i686-gnome.7z

You should now have the virtual disk image Fedora-12-i686.vdi.

Now set up the guest VM:

Start virtual box.

Select new

Name it 'Fedora 12'

Set operating system to Linux and version to Fedora.

Select 'use existing disk' and select the one you've just extracted (Fedora-12-i686.vdi).

start the vbox and finalise the guest setup

Change root password in the guest from the default using the 'passwd' command (default password is fedora).

You now have a guest VM.

To enhance it further install guest additions. This will allow better screen resolutions and file sharing.

To install guest additions:

In the guest:

yum install kernel-headers kernel-devel gcc dkms
yum update kernel

reboot the guest (so running kernel matches kernel-devel)

Now enter:

yum list kernel*

Check that the version numbers of the kernel, kernel-headers and kernel-devel are the same.

Now do devices/install guest additions from the VirtualBox menu bar.
This downloads it and mounts it.

Now do:

cd /media/VBOXADDITIONS_3.1.4_57640
./VBoxLinuxAdditions-x86.run

Tips:

  • If you get an error when starting a guest after updating to a newer kernel (with a message 'kernel driver not installed') then you need to do 'yum update kmod-VirtualBox-OSE' so the virtual box module version matches the kernel version.
  • If you are installing a Fedora 12 guest yourself from the live/install CD increase the memory of the guest to 512MB or more. If you use the default of 384MB it will hang when you click on the 'install to hard drive' icon.

RPMs

This section contains Fedora RPM packages.
It has moved to its own page.


Valid XHTML 1.1   Valid CSS!

Copyright © 2008-2013 John Cheetham
Disclaimer