Compdigitec Labs

Using dpkg in Ubuntu and Debian

By admin | July 29, 2008

For those of you who are stuck in an command line (bash) environment with no access to Synaptic, here are 9 useful and clear tips to help you to get the hang of package management with dpkg in the Ubuntu Linux and Debian Linux distributions.

  1. dpkg –install (or dpkg -i) – Installs the specified package. Example:
    sudo dpkg --install package.deb
  2. dpkg –remove (or dpkg -r) – Removes the specified package. Example:
    sudo dpkg --remove package
  3. dpkg –remove –purge (or dpkg -r -P) – Removes the specified package and purges all configuration data. Example:
    sudo dpkg --remove --purge package
  4. dpkg –unpack directory/ – Unpacks the package’s contents into directory/. Example:
    dpkg --unpack package.deb directory/
  5. dpkg –listfiles (or dpkg -L) – Lists the files that the specified package contains. Example:
    dpkg --listfiles package
  6. dpkg –list (or dpkg -l) – List the package details in great detail. Example:
    dpkg --list package
  7. dpkg –status (or dpkg -s) – Lists the package status in detail, along with version, description and architecture information. Example:
    dpkg --status package
  8. dpkg –root=/directory –install (or dpkg –root=/directory -i) – Install the package into /directory other than root. Example:
    sudo dpkg --root=/directory --install package
  9. dpkg –simulate command (or dpkg –dry-run) – Simulates what would happen if you did run the command command for real. Example:
    sudo dpkg --simulate command

So there you have it, 9 simple yet very effective tips to package management with dpkg on Ubuntu and Debian. If this article helped you, please help us spread the word!

Topics: Linux | No Comments »

Building .deb packages on Ubuntu/Debian

By admin | July 28, 2008

Ever wanted to create your very own .deb packages for Ubuntu and Debian? Well, here’s a guide to tell you how in 10 easy steps!

  1. Create the directory to hold the package by using:
    mkdir package
  2. Change into the package directory:
    cd package/
  3. Make the package file system. For example, any files you put into the usr folder in this folder will go to /usr when installed. You can create them as necessary.
    mkdir usr
    mkdir usr/bin
    mkdir usr/lib
    mkdir etc
  4. Copy the application files to the appropriate directories; For example, if you want file FooBar.sh to be installed in /usr/bin, copy FooBar.sh to the usr/bin folder. Below is a demo, assuming no dependencies.
    cp /path/to/files/a.sh usr/bin
    cp /path/to/files/a.conf etc
    cp /path/to/files/liba-4.so usr/lib
  5. (required) Create the Debian control file. There is a specification file here: http://www.debian.org/doc/debian-policy/ch-controlfields.html
    touch DEBIAN/control
    editor-of-your-choice DEBIAN/control
  6. (optional) Create the postinstall file. This file is exectuted during the installation. Note that this file should be a shell script.
    touch DEBIAN/postinstall
    editor-of-your-choice DEBIAN/postinstall
  7. (optional) Create the prerm file. This file is executed during the removal of this package. Note that this file should be a shell script.
    touch DEBIAN/prerm
    editor-of-your-choice DEBIAN/prerm
  8. You’re almost ready to create the package! Change into the parent directory to begin.
    cd ..
  9. Now we can finally begin! This may take from 2 seconds to 24 hours, depending on the size of the package and the speed of your computer.
    dpkg-deb –build package
  10. You’re done! The package is package.deb. To install it:
    dpkg –install package.deb

Topics: Linux | 7 Comments »

Install Roadsend PHP Compiler on Ubuntu – without compiling anything!

By admin | July 24, 2008

Update (2010-07-21): Due to vast interest in getting the packages to work, we have released a updated version of the Roadsend PHP compiler.

Update (2008-09-06): The binary packages are not AMD64 compatible (thanks to Tom in the comments). You may wish to compile your own packages following the instructions in this article. The binaries are compatible with x86/i386/i686/x86_64 only.

Roadsend PHP is an actively developed PHP compiler. Unfortunately, it is not available for the extremely popular Ubuntu Linux. This post will help you install Roadsend PHP on your Ubuntu Linux machine in 5 easy steps.

  1. If you have the repository (in other words, from synaptic) version of Bigloo and any roadsend packages installed, remove them now.
  2. Install the unofficial Bigloo and Roadsend PHP compiler packages: (install unofficial bigloo first)
  3. If you are setting up Roadsend PHP per-user, add this line to each user’s “~/.profile”. To set Roadsend PHP up system-wide, add it to “/etc/profile”.export LD_LIBRARY_PATH=/usr/local/lib
  4. You’re almost done! Compile a test program to test it:<?php
    echo "Hello World! - This is the Roadsend PHP test program.\n";
    ?>
    Save it in index.php . Then compile it and run it:
    pcc index.php
    ./index

    You should get this output: “Hello World! – This is the Roadsend PHP test program.”. If you get this error instead “./index: error while loading shared libraries: libphp-runtime_u-3.0c.so: cannot open shared object file: No such file or directory”, it means that you have not yet set LD_LIBRARY_PATH as in Step 3. Set it manually by executing:

    export LD_LIBRARY_PATH=/usr/local/lib

  5. To test the MicroServer backend, compile with the following command:
    pcc -s testprog --port 54321 index.php
    To avoid another fatal error, copy the PHP core runtime with the following command:
    cp /usr/local/lib/libphp-runtime_u-3.0c.so ./
    ./index
    Then browse to http://127.0.0.1:54321/ and you should see “”Hello World! – This is the Roadsend PHP test program.”

Topics: Linux, PHP | 29 Comments »

Very Suspicious Internet Robots

By admin | July 23, 2008

So far we have come across some very strange and suspicious robots hitting our site; we have identified them for you here. Feel free to use this information to block these suspicious robots from hitting/scraping your website.

This bot tried to access only the home page. It’s IP is 67.215.230.15 and tried to access our home page on 2008-07-21 06:00:57.

This bot, written in perl, tried to do an exploit of some sort by trying to GET /index.php?layout=http://kingkool2.free.fr/ezupload/ips.txt?. IPs include: 203.97.119.88, 75.101.157.249, 207.57.2.143, 89.111.176.110 and 222.233.52.18. Block the user-agents in robots.txt.

This “russian” bot appears to follow links throughout the site between intervals of 2 minutes. Blocked permanently because of an unresolvable URL. Some Google searches reveal that it follows up behind the scrapers.

This bot suspiciously scrapes all important pages at the rate of several pages per seconds. According to this post, it looks like that this bot does dirty work for the RIAA and the MPAA. Block user agent at this IP: 38.100.41.*

Good luck defeating the spambots and badbots out there!

Topics: Internet | 9 Comments »

Compiling PHP-GTK2 Applications into Win32 Executables

By admin | July 20, 2008

PriadoBlender Version 2.0 on Wine

Update (August 24, 2008): Apparently this program does not support Unicode or php-gettext supported programs; a “program name has encountered an error and needs to close” dialog appears.

A good solution for compiling (not true compiling though) PHP-GTK and PHP-GTK2 applications is the PriadoBlender (pb.impressivegames.com). Released under the PHP License (see note 1), and allowing you to even create commercial applications with it, PriadoBlender is an amazing project, although it looks like that the development of PriadoBlender has been stalled.

The good thing is that the v2 beta(?) is still available, and it does a very good job of making your CLI, PHP-GTK and PHP-GTK2 applications into standalone Win32 EXE.

You can download it here: Link to the official download. Here’s a mirror in case the official one does not work for some reason: Mirror download of PriadoBlender from Compdigitec

Hope this helped anyone looking on compiling PHP-GTK2 programs into standalone windows executables!

  1. See here: www.priadoblender.com/index.php?layout=main&cslot_1=3

Topics: PHP, Windows | 14 Comments »

Stopping syntax error, unexpected ‘;’, expecting T_FUNCTION

By admin | July 19, 2008

If you’ve ever been stumped by “Parse error: syntax error, unexpected ‘;’, expecting T_FUNCTION”, you will know that this is a very difficult bug to track. Fortunately, we have found the error for you.

This error message is very misleading, because your actual problem is that you have an extra semi-colon at the end of your functions, like the one below (see line 12):

<?php
// Demo Syntax Error Example
// Public domain

class Demo {
     var $a;
     var $b;

     function problem_here() {
          $this->a = 'Hello World!';
     }; # <-- That one
};
?>

Now, the above code looks good, but when you try to run it it PHP spits out the following parse error:

Parse error: syntax error, unexpected ‘;’, expecting T_FUNCTION in *.php on line *

So, to fix it, simply remove the offending semi-colon at the end of your functions. Hope this helped anyone who got stuck with this misleading PHP error.

Topics: PHP | 30 Comments »

Measure CPU temperature and your fan speed in Ubuntu Linux

By admin | July 18, 2008

Update (2010-10-10): If you are getting “E: Couldn’t find package sensors-applet” errors, then add universe to /etc/apt/sources.list (add or uncomment http://archive.ubuntu.com/ubuntu <dist code> universe)

lm-sensors is a very useful tool to measure your CPU temperature and your fan speed (which is not in /proc/cpuinfo) in Ubuntu Linux. In order to use it, you will first need to install it.

$ sudo apt-get install lm-sensors libsensors4
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
i2c read-edid sensord
The following NEW packages will be installed:
libsensors4 lm-sensors
0 upgraded, 2 newly installed, 0 to remove and 24 not upgraded.
Need to get 0B/250kB of archives.
After this operation, 918kB of additional disk space will be used.
Selecting previously deselected package libsensors4.
(Reading database ... 117271 files and directories currently installed.)
Unpacking libsensors4 (from .../libsensors4_1%3a3.0.0-4ubuntu1_i386.deb) ...
Selecting previously deselected package lm-sensors.
Unpacking lm-sensors (from .../lm-sensors_1%3a3.0.0-4ubuntu1_i386.deb) ...
Setting up libsensors4 (1:3.0.0-4ubuntu1) ...
udev active, devices will be created in /dev/.static/dev/</code>

Setting up lm-sensors (1:3.0.0-4ubuntu1) ...

Processing triggers for libc6 ...
ldconfig deferred processing now taking place

Now, before you can use it, you need to configure it by running sensors-detect as root. Just press Enter whenever the script asks you a question.
When it asks you “Do you want to add these lines automatically?”, type in yes and press enter.

$ sudo sensors-detect
# sensors-detect revision 5016 (2007-11-11 22:20:16 +0100)

This program will help you determine which kernel modules you need
to load to use lm_sensors most effectively. It is generally safe
and recommended to accept the default answers to all questions,
unless you know what you’re doing.

We can start with probing for (PCI) I2C or SMBus adapters.
Do you want to probe now? (YES/no):
Probing for PCI bus adapters…
Use driver `i2c-viapro’ for device 0000:00:07.3: VIA Technologies VT82C596 Apollo ACPI

We will now try to load each adapter module in turn.
Module `i2c-viapro’ already loaded.
If you have undetectable or unsupported adapters, you can have them
scanned by manually loading the modules before running this script.

To continue, we need module `i2c-dev’ to be loaded.
Do you want to load `i2c-dev’ now? (YES/no):
Module loaded successfully.

We are now going to do the I2C/SMBus adapter probings. Some chips may
be double detected; we choose the one with the highest confidence
value in that case.
If you found that the adapter hung after probing a certain address,
you can specify that address to remain unprobed.

Next adapter: SMBus Via Pro adapter at 5000 (i2c-0)
Do you want to scan it? (YES/no/selectively):
Client found at address 0x2d
Handled by driver `gl520sm’ (already loaded), chip type `gl520sm’
Client found at address 0x50
Probing for `Analog Devices ADM1033’… No
Probing for `Analog Devices ADM1034’… No
Probing for `SPD EEPROM’… Yes
(confidence 8, not a hardware monitoring chip)
Probing for `EDID EEPROM’… No
Client found at address 0x51
Probing for `Analog Devices ADM1033’… No
Probing for `Analog Devices ADM1034’… No
Probing for `SPD EEPROM’… Yes
(confidence 8, not a hardware monitoring chip)
Probing for `EDID EEPROM’… No
Client found at address 0x52
Probing for `Analog Devices ADM1033’… No
Probing for `Analog Devices ADM1034’… No
Probing for `SPD EEPROM’… Yes
(confidence 8, not a hardware monitoring chip)
Probing for `EDID EEPROM’… No

Some chips are also accessible through the ISA I/O ports. We have to
write to arbitrary I/O ports to probe them. This is usually safe though.
Yes, you do have ISA I/O ports even if you do not have any ISA slots!
Do you want to scan the ISA I/O ports? (YES/no):
Probing for `National Semiconductor LM78′ at 0x290… No
Probing for `National Semiconductor LM78-J’ at 0x290… No
Probing for `National Semiconductor LM79′ at 0x290… No
Probing for `Winbond W83781D’ at 0x290… No
Probing for `Winbond W83782D’ at 0x290… No
Probing for `Silicon Integrated Systems SIS5595’… No
Probing for `VIA VT82C686 Integrated Sensors’… No
Probing for `VIA VT8231 Integrated Sensors’… No
Probing for `IPMI BMC KCS’ at 0xca0… No
Probing for `IPMI BMC SMIC’ at 0xca8… No

Some Super I/O chips may also contain sensors. We have to write to
standard I/O ports to probe them. This is usually safe.
Do you want to scan for Super I/O sensors? (YES/no):
Probing for Super-I/O at 0x2e/0x2f
Trying family `National Semiconductor’… No
Trying family `SMSC’… No
Trying family `VIA/Winbond/Fintek’… No
Trying family `ITE’… No
Probing for Super-I/O at 0x4e/0x4f
Trying family `National Semiconductor’… No
Trying family `SMSC’… No
Trying family `VIA/Winbond/Fintek’… No
Trying family `ITE’… No

Some CPUs or memory controllers may also contain embedded sensors.
Do you want to scan for them? (YES/no):
AMD K8 thermal sensors… No
AMD K10 thermal sensors… No
Intel Core family thermal sensor… No
Intel AMB FB-DIMM thermal sensor… No

Now follows a summary of the probes I have just done.
Just press ENTER to continue:

Driver `gl520sm’ (should be inserted):
Detects correctly:
* Bus `SMBus Via Pro adapter at 5000′
Busdriver `i2c-viapro’, I2C address 0x2d
Chip `gl520sm’ (confidence: 6)

I will now generate the commands needed to load the required modules.
Just press ENTER to continue:

To load everything that is needed, add this to /etc/modules:

#—-cut here—-
# I2C adapter drivers
i2c-viapro
# Chip drivers
gl520sm
#—-cut here—-

Do you want to add these lines automatically? (yes/NO) yes

If it gives the error “You need to be root to run this script.”, then re-run it as root.

You’re done! Type sensors in the command line to run.

$ sensors
gl520sm-i2c-0-2d
Adapter: SMBus Via Pro adapter at 5000
+5V:         +5.13 V  (min =  +0.00 V, max =  +0.00 V)
+3.3V:       +3.31 V  (min =  +0.00 V, max =  +0.00 V)
+12V:       +12.03 V  (min =  +0.00 V, max =  +0.00 V)
Vcore:       +2.11 V  (min =  +0.00 V, max =  +0.00 V)
fan1:          0 RPM  (min =    0 RPM, div = 1)
fan2:          0 RPM  (min =    0 RPM, div = 1)
temp1:       +35.0 C  (high = -130.0 C, hyst = -130.0 C)
temp2:       +35.0 C  (high = -130.0 C, hyst = -130.0 C)
cpu0_vid:   +2.050 V
beep_enable:disabled

If you want a graphical applet, run this:

$ sudo apt-get install sensors-applet
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libsensors-applet-plugin0
Recommended packages:
hddtemp
The following NEW packages will be installed:
libsensors-applet-plugin0 sensors-applet
0 upgraded, 2 newly installed, 0 to remove and 24 not upgraded.
Need to get 118kB of archives.
After this operation, 713kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://us.archive.ubuntu.com hardy/universe libsensors-applet-plugin0 2.2.1-1ubuntu3 [18.5kB]
Get:2 http://us.archive.ubuntu.com hardy/universe sensors-applet 2.2.1-1ubuntu3 [99.7kB]
Fetched 118kB in 1s (74.0kB/s)
Selecting previously deselected package libsensors-applet-plugin0.
(Reading database ... 117338 files and directories currently installed.)
Unpacking libsensors-applet-plugin0 (from .../libsensors-applet-plugin0_2.2.1-1ubuntu3_i386.deb) ...
Selecting previously deselected package sensors-applet.
Unpacking sensors-applet (from .../sensors-applet_2.2.1-1ubuntu3_i386.deb) ...
Setting up libsensors-applet-plugin0 (2.2.1-1ubuntu3) ...</code>

Setting up sensors-applet (2.2.1-1ubuntu3) ...

Processing triggers for libc6 ...
ldconfig deferred processing now taking place

Then right click a panel and select “Add to Panel”. Then in the list select “Hardware Sensors Monitor” and click “Add”.

Topics: Linux | 15 Comments »

Determine the OS and version of PHP

By admin | July 16, 2008

It is very hard to determine the OS of the server/computer that is running PHP. So therefore here are two very, very useful methods to get the OS and Version of PHP.
This finds the version and OS the PHP on your server, not that person that is visiting your site.

To get the version of PHP, use phpversion(), a hidden function in PHP. However, your OS maker may have customized this so it may not be a pure number. For example, on Ubuntu Linux it returns 5.2.4-2ubuntu5.1, but on a Windows binary from php.net it returns 5.2.5, which is a pure number.

And to get the OS of PHP, use the hidden constant PHP_OS. If it doesn’t work, you could also try the following, even though the chances are very unlikely:

$_ENV['OS']
$_SERVER['OS']
$_SERVER['SERVER_SOFTWARE'] // The OS Info may be in there

Topics: PHP | 10 Comments »

OCR for PDF in Ubuntu

By admin | July 8, 2008

To get OCR in Ubuntu, you need to use the Open-Source Tesseract OCR engine. However, it can only perform OCR on the TIFF format. In order to allow it to do PDF, we also need the Evince PDF reader to allow us to export a page to TIFF to feed Tesseract with.

Install tesseract in Ubuntu:

$ sudo apt-get install tesseract-ocr

Now, get the TIFF from Evince; Right click the page and click “Save image as…” and export the file. Then, to get a good OCR we need to convert it to monochrome.


$ tesseract foo.tif bar
Unable to load unicharset file /usr/share/tesseract-ocr/tessdata/eng.unicharset

If the above bug happens, fix it by:

$ sudo apt-get install tesseract-ocr-eng

This is caused by a nasty bug in Ubuntu.

And now finally, do:

$ tesseract foo.tif bar# and without the .txt extension, or you will end up with bar.txt.txt

to complete it!

Topics: Linux | 14 Comments »

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles! Newer Entries »