LFS Version SVN-20070926 - Perl Script for getting all packages

Mag. Leonhard Landrock 1977-Hamlet at gmx.at
Fri Oct 26 05:28:46 PDT 2007


In August 2006 I successfully completed my first and (so far) only one LFS.

Allready back at that time I made myself bash scripts to make life easier. Now 
I started a new attempt with LFS for some special reason.

To obtain all packages I want to use an perl script and a bash script. The 
idea is quite simple.

The perl script extracts the package names and locations and generates a bash 
script file. In fact it's just an text file with definitions that gets 
sourced by a bash script.

The files used look like this:


# All Packages

# The download URL for the needed packages


# Import the LFS definitions
source ../build-LFS-definitions
source ../../include/build-LFS-packages.shell

# 6.) Download or otherwise obtain the following packages:




#!/usr/bin/perl -w

use strict;

my $cwd = "/home/leo/LFS/packages";

my $read = open(FILEHANDLE_READ,"$cwd/packages.html");

if(not defined($read)) {
    die "Fehler beim Oeffnen der Datei \"packages.html\": $!\n";

my $write = open(FILEHANDLE_WRITE,"> $cwd/packages.tmp");

if(not defined($write)) {
    die "Fehler beim Oeffnen der Datei \"packages.tmp\": $!\n";

while(defined(my $line = <FILEHANDLE_READ>)) {
# get only lines with "http://" or "ftp://"
    if ($line =~ m/(?:http:\/\/)|(?:ftp:\/\/)/i) {
# No lines with HTML Syntax
        if (!($line =~ m/(?:\.dtd|xmlns)/)) {

# no spaces
            my $url = $line;
            $url =~ s/^\s+//;

# A line may look like this:
# "http://www.gnu.org/software/autoconf/">http://www.gnu.org/software/autoconf/</a>
            $url =~ s/.*(?<=\"\>)(.*)(?=\<\/a\>).*/$1/;

# this lines are possible too
# Download: <a class="ulink" href=
# "http://download-east.oracle.com/berkeley-db/db-4.6.19.tar.gz">
# http://download-east.oracle.com/berkeley-db/db-4.6.19.tar.gz</a>
# line 2 must be deleted and line 3 must be adopted
            $url =~ s/.*(?<=\"\>)(?:\n|\r)//;
            $url =~ s/(.*)(?:\<\/a\>.*)/$1/;

# there are even this kind of lines
# Home page: <a class="ulink" href=
# "http://www.oracle.com/technology/software/products/berkeley-db/index.html">
# We need to delete these ones
           $url =~ s/.*\.html?(?:\n|\r)//;

# We have to distinct between the place of the package and the package
# name
# first we get the full package name (including version number and file 
            our $package_name;
            if ($url =~ m/.*\/(.*(?:\.tar\.(?:bz2|gz))|(?:\.tgz))(\n|\r)/) {
                $package_name = "$1"."$2";
            our $package_name_variable;
            $package_name_variable = "$package_name";
            $package_name_variable =~ s/(.*)(?:\.tar\.(?:bz2|gz))|(?:

# next we want just the name of the package
            $package_name_variable =~ s/([-_a-zA-Z]*)-\d+(?:(?:\.|-)?\d*)*(\n|
# There is also something special with "TCL" as for example "tcl8.4.15-src".
            $package_name_variable =~ s/([-_a-zA-Z]*)\d+(?:(?:\.|-)?
= "LFS_PACKAGE_".uc($package_name_variable);

### Check the result now. [ To be removed later! ]
            print "$package_name_variable"."="."$package_name";

            print FILEHANDLE_WRITE $url


    or die "Fehler beim SchlieÃen von './packages/packages.tmp': $! \n"

The perl script opens a copy 
of "http://www.linuxfromscratch.org/lfs/view/development/chapter03/packages.html". 
In the end it shall create my "build-LFS-packages.shell" file.

My "packages.pl" quite good works already, but it still has it mistakes. For 
example it prints every package two or three times. I know, that there are 
others who do have there own scripts to automate LFS. Maybe one or another 
has good knowledge of perl and can take a look at my script.

NOTE: I'm an absolut beginner with perl.

Kind regards,

More information about the lfs-support mailing list