Hi!

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:


build-LFS-packages.shell:
===============

# All Packages
LFS_PACKAGE_AUTOCONF=autoconf-2.61.tar.bz2
LFS_PACKAGE_AUTOMAKE=automake-1.10.tar.bz2
LFS_PACKAGE_BASH=bash-3.2.tar.gz

# The download URL for the needed packages
LFS_PACKAGE_URL_AUTOCONF=http://ftp.gnu.org/gnu/autoconf/${LFS_PACKAGE_AUTOCONF}
LFS_PACKAGE_URL_AUTOMAKE=http://ftp.gnu.org/gnu/automake/${LFS_PACKAGE_AUTOMAKE}
LFS_PACKAGE_URL_BASH=http://ftp.gnu.org/gnu/bash/${LFS_PACKAGE_BASH}


packages_and_patches.cmd:
==================

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

# 6.) Download or otherwise obtain the following packages:
LFS_DOWNLOAD_DIR=${LFS_MOUNT_POINT}/${LFS_DIR_SOURCES}/${LFS_DIR_PACKAGES}

lwp-download ${LFS_PACKAGE_URL_AUTOCONF} 
${LFS_DOWNLOAD_DIR}/${LFS_PACKAGE_AUTOCONF}

lwp-download ${LFS_PACKAGE_URL_AUTOMAKE} 
${LFS_DOWNLOAD_DIR}/${LFS_PACKAGE_AUTOMAKE}


packages.pl:
========

#!/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";>
# 
http://www.oracle.com/technology/software/products/berkeley-db/index.html</a>
#
# 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 
extension)
            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))|(?:
\.tgz)/$1/;

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

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

            print FILEHANDLE_WRITE $url
        }
    }
}

close(FILEHANDLE_READ);

close(FILEHANDLE_WRITE)
    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,
Leonhard.
-- 
http://linuxfromscratch.org/mailman/listinfo/lfs-support
FAQ: http://www.linuxfromscratch.org/lfs/faq.html
Unsubscribe: See the above information page

Reply via email to