Wednesday, April 8, 2015

Configuring SELinux to Allow HTTPD Scripts and Modules to Establish TCP Connections

In a PHP script that establishes database connection to a PostgreSQL database via TCP socket, I encountered a SELinux denial. The message in the error log is,


SELinux is preventing /usr/sbin/httpd from name_connect access on the tcp_socket.


A quick fix is to allow HTTPD scripts and modules to connect to the network using TCP, i.e., run the following,


sudo setsebool -P httpd_can_network_connect 1

By the way, the relevant system information is as follows,

  • Operating System (output of uname -sr): Linux 3.12.9-201.fc19.x86_64
  • SELinux Policy Module: selinux-policy.noarch, version 3.12.1-74.17.fc19

Tuesday, March 31, 2015

Birds in China

I have been enjoying and fascinated by the photos of birds Craig Brelsford took in China. If you are interested in watching birds, check out his blog, the Photographic Web site of Craig Brelsford

Thursday, March 12, 2015

Converting PDF to EPS Figure for LaTeX

Sometimes we want to convert a figure in PDF format to EPS format and use the figure in a LaTex file. One important item we must take care is the bounding box of the figure. If the bounding box is not generated correctly, we would have a large area of wide space around the figure in final document.

In a Linux system, we have a set of free tools that can help us produce an appropriate bounding box and convert PDF format to EPS format.
On Ubuntu, you may install them using apt-get as follows,

sudo apt-get install \
     pdftk gv texlive-extra-utils \
     poppler-utils ghostscript ps2eps


Assume that PDF file foo.pdf contains an interesting figure in page 2 and we want to extract the figure for inserting it in a LaTex document. We would follow the steps below,
  1. Extract the page from the PDF file that contains the figure we would like to extract

    pdftk foo.pdf cat 2 output page2.pdf
    

    where foo.pdf is the input PDF file, page2.pdf  is the output PDF file, and 2 is the page number in the input PDF file.

  2. Measure roughtly the position and the dimension of a box that contains the figure using gv.
    
    gv page2.pdf
    

    We read the coordinates of the bottom left corner and the top right corner of the box from gv. Assume the readings are (61, 82) and (321, 161), respectivley.

  3. Crop the PDF file based on the box obtained in the above.
    
    pdfcrop --bbox "61 82 321 161" page2.pdf
    

    The output of this step is page2-crop.pdf.

  4. Crop the resulting PDF file from previous step to reduce white space around the figure.
    
    pdfcrop page2-crop.pdf
    

    The result is page2-crop-crop.pdf.

  5. Convert the PDF file to an EPS file.
    
    pdftops -eps page2-crop-crop.pdf page2.eps
    

    We could complete the last step using pdf2ps in Ghostscript instead of pdftops by the Poppler developers as the following two steps approach.
    
    pdf2ps page2-crop-crop.pdf 
    ps2eps page2-crop-crop.ps page2.eps
    

    However, we do not recommend pdf2ps, convinced by the argument made by Stefaan Lippens.

    As indicated by Stefaan Lippens, pdf2ps converts fonts in PDF files to bitmap fonts in resulting PS files. Some may consider this an advantage because the fonts used in the figure will always be "present" in the PDF files generated form the corresponding LaTeX files. However, as we discussed previously, it is not difficult to embedd all fonts in a PDF file.

Wednesday, February 25, 2015

Getting File Basebase without Extension in GNU Makefile

Sometimes we would like to write a generic rule in GNU makefiles.

For instance, we would like to write a rule to process a LaTex file and then process BibTex entries for any LaTeX files. We can write the rule as follows,


%.dvi: %.tex
    latex $<
    bibtex $(basename $<)
    latex $<
    latex $<

In the example, if we issue a command make example.tex, the value of $< is example.tex while $(basename $<) yields the basename without the extension. The basename without the extension is required for bibtex to work in this example.

This solution is provided by the discussion here.

Tuesday, February 24, 2015

Installing lineno.sty in Ubuntu and Fedora Linux

When we prepare a document using LaTeX, sometimes we want to include line numbers in an article. In many peer reviewed journals, it is a requirement to include line numbers in the output.

For instance, Elsevier LaTeX instructions has a LaTeX template whose LaTeX template file starts with

\documentclass[review]{elsarticle}

\usepackage{lineno,hyperref}

You system has not had the lineno package installed, if you encounter the following error when you compile your LaTex file that uses package lineno,

! LaTeX Error: File `lineno.sty' not found.

Type X to quit or  to proceed,
or enter new name. (Default extension: sty)

Enter file name:

Although you can download and install it from CTAN, you may be better off by installing the appropriate package provided by your system and let your system manage it. For instance, on Ubuntu Linux, we can install the textlive-humanities package,

sudo apt-get install texlive-humanities

For instance, on Fedora Linux, we can install the texlive-collection-humanities package,

sudo yum install texlive-collection-humanities 

The solution comes from the posts at here and here.

Creating Small Footprint Linux Virtual Machine - Revisited

Although many virtual machine appliances exist today and are conveniently to download, such as the VMWare Virtual Appliance Marketplace and the TurnKey Linux Virtual Appliance Library, it may be necessary to create a virtual machine image of your own and distribute it among the others. The issue is that a virtual machine image can easily become a monster and can be difficult to host, upload, download, and distribute such a large image. Previously, I attempted to create Linux virtual machine images with small footprint using the approach of installing the system and removing unnecessary packages. That approach leads to virtual machine images compressible to around 1GB archives.

Lately, I have opted to a second approach in which we install a bare bone Linux system and then install necessary packages. This approach, I found, often leads to smaller footprint than the previous approach.

The only caveat is that this approach may not work well with certain Linux distributions if the Linux distribution does not provide a means to install bare bone systems. If a Linux distribution does not provide a means to install the bare bone systems, it is likely to be a desktop edition, for instance, Ubuntu Linux's Desktop Edition has no option for a user to install a bare bone system during its installation process. A workaround is to create the system image using its corresponding server edition distribution, for instance, Ubuntu Linux's Server Edition allows you to install a bare bone system.

At present, I have a 64-bit Ubuntu Linux Server Edition image with PostGreSQL, Apache Web Server, and PHP but without GUI and the image is compressed to about 350MB archive.


Monday, January 26, 2015

Windows Software Licensing Management Tool (slmgr.vbs)

It has many functionality. A particular one that I am interested today is to figure out how a copy of Windows is licensed and activiated.

slmgr.vbs /dlv