LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 01-12-2007, 05:22 AM   #1
acummings
Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 615

Rep: Reputation: 50
create a slack-desc file also learning in prep for use of makepkg


Hi,

Some nice threads are onboard here and at linuxpackages -- I've been studying them about getting it together (accomplish the needed steps) so that makepkg can then be run to get the package created.

I wanted an auto sort of a way to get a slack-desc file created.

I made a Perl script that works for this task. I'm not particularly proud of it. It could be shorter than what it is. It's my first crack at it. But it does works good though.

The script has no (me or you, the computer operator) error checking. Therefore the script should still be considered as being in the experimental stage (do not issue the wrong command to this script).

Anyways, I thought I'd share the script as well as propose how do others get their slack-desc file properly formatted?

I wouldn't call this from a build script -- but just for me tinkering around and learning the mechanics of the needed ingredients and the needed steps to accomplish in order to run makepkg and get a built Slackware package.

Here's the Perl script slack-desc maker/formatter

use it at your own risk and/or don't use it unless you at least somewhat understand the under-pinnings of what is going on.

If anyone tries the script -- have I correctly grasped what a slack-desc file needs to look like?

source_file.txt only needs your description (nothing else) -- since the formatting and inserting of

pkg_name:

at the beginning of each line are done by the Perl script. Also your name is inserted by the Perl script.

Code:
#!/usr/bin/perl
use warnings;
use strict;
# use diagnostics;
use Text::Wrap qw(wrap $columns $huge);

# formats and outputs an 11 lines slack-desc file
# given that you've put this code into a file named txtwrap
# and that txtwrap is executable and in a folder in $PATH
# then, from the folder where source_file.txt resides
# just run the next command
# txtwrap source_file.txt pkg_name > slack-desc

my $your_name = 'Your Name here';
  $columns = 72;
  $huge = "wrap";
my $source = shift;
my $pkg_nam = shift;
$pkg_nam .= ': ';
open my $src, '<', $source or die "could not open '$source' $!";
my @text;
while ( <$src> ) {
push @text, $_;
}

my $out = wrap("$pkg_nam", "$pkg_nam", @text);
my @out = split(/\n/, $out);
my $fillr = "$pkg_nam" . "pkg by $your_name\n$pkg_nam";
$fillr .= "\n$pkg_nam\n$pkg_nam\n$pkg_nam\n$pkg_nam";
$fillr .= "\n$pkg_nam\n$pkg_nam\n$pkg_nam\n$pkg_nam";
my @addendum = split(/\n/, $fillr);
push @out, @addendum;
my $i=1;
foreach ( @out ) {
$_ .= "\n";
print;
$i++;
if ( $i == 11 ) {
s/\n//;
print;
last;
}
}
# print @out, "\n";
--
Alan.
 
Old 01-13-2007, 01:58 AM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
I like your little script -I sure would like to see this is in BASH...
First, you got it right that it should be 11 lines. It may be better to not have a space after the ':' on lines which have no comments.
The first line is okay, but the second line should have no comments.
And the pkg signature should go on the last line.

Here's an example:
linpopup: LinPopUp-1.2.0 WinPopUp for Linux
linpopup:
linpopup: LinPopUp is an X window port of Winpopup, running over
linpopup: Samba. It permits communication with a Windows computer
linpopup: that runs Winpopup, sending or receiving messages. (It
linpopup: also provides an alternative way to communicate between
linpopup: Linux computers that run Samba).
linpopup: Note that LinPopUp is not only a port, as it includes
linpopup: several enhanced features not in the Windows program.
linpopup:
linpopup: Packaged by amigolinux.org

I may use your code in PkgBuild, my package building software. It includes routines which try to validate an existing slack-desc or create one for you. I started once to include some code to do what you are doing and just the last few days started getting the urge again to do so.

Most people don't realize just how important it is for the slack-desc to be exactly right. When you install with installpkg, the slack-desc gets read and the description lines are added to the package database file in /var/log/packages. But,if the name in the slack-desc doesn't match that of the package, these lines do not get written. There can be problems also if there are lines without comments that have spaces (particularly if more than one). You wind up with a database file with lines missing.
This is important because when you remove the package using removepkg it expects those 11 lines to be in the database file. expects to skip over those lines to find the start of the list of installed files. When those lines are not there, removepkg will fail to properly remove the listed files, but it will remove the database file making you think the package was deleted.
You might look at anything special needed in order to get the text from standard description files such as debian control files or rpm .spec files.
 
Old 01-13-2007, 04:16 AM   #3
acummings
Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 615

Original Poster
Rep: Reputation: 50
Quote:
Most people don't realize just how important it is for the slack-desc to be exactly right.
I *was* one of those. Thank you sir. So, now I know.

Well, I admit, I do have fun with Perl. This script is OK. But I can do even better. I was having a rough night the other night when I first hacked it out. Sometimes everything just falls together from the beginning. Other times it's fight fight fight, debug debug debug. It was the latter when I first hacked out this one. Sometimes *brain* rocks and rolls -- other times it seems like *brain_dead*.

Or, perhaps it is that sometimes brain gets out of the way and creativity takes over (rock n roll) while at other times brain doesn't get out of the way (fight fight fight, debug debug debug).

Anyways, whatever is going on -- it is all fun.

I did mods to the script. It now outputs exactly as per your shared example slack-desc. I likely will do further improvements, mods, error checking, etc.

But for now, here's the script again it's now as I've just said that I have updated it so far. Perl is fun (for me).

Code:
#!/usr/bin/perl
use warnings;
use strict;
# use diagnostics;
use Text::Wrap qw(wrap $columns $huge);

# (minus each line's preceding hashSPACE in the next)
# A sample format of the source_file.txt begins next line
# LinPopUp-1.2.0 WinPopUp for Linux
# Description here beginning on 2nd line of source_file.txt
# in any format all run together as one line is ok. The format
# doesn't matter. The only thing that matters is your first
# line is critical. Your first line must depict the same format
# as this sample's first line. From the 2nd line on can be
# wrapped at 125 for the line length, or not wrapped at all.
# Your first line is grabbed separately by this script whilst
# the 2nd through the ending line(s) are grabbed and properly
# formatted as the description. To make things easy, we output
# a no-description as the 2nd line.  IOW, formatted description
# begins on the third line of the output.
# The sample format of the source_file.txt ends on previous line

# This script formats and outputs an 11 lines slack-desc file
# given that you've put this code into a file named txtwrap
# and that txtwrap is executable and in a folder in $PATH
# then, from the folder where source_file.txt resides
# just run the next command
# txtwrap source_file.txt pkg_name > slack-desc

my $your_name = 'Your Name here';
  $columns = 72; # line width edit 72 if needed
  $huge = "wrap";
my $source = shift;
my $pkg_nam = shift;
$pkg_nam .= ': ';
open my $src, '<', $source or die "could not open '$source' $!";
my @text;
while ( <$src> ) {
push @text, $_;
}

my $first_line = shift @text; # first_line ungroups from @text
chomp($first_line);
my $out = wrap("$pkg_nam", "$pkg_nam", @text); # wrap @text
my @out = split(/\n/, $out);
my $fillr = "$pkg_nam\n" . "$pkg_nam";
$fillr .= "\n$pkg_nam\n$pkg_nam\n$pkg_nam\n$pkg_nam";
$fillr .= "\n$pkg_nam\n$pkg_nam\n$pkg_nam\n$pkg_nam";
my @addendum = split(/\n/, $fillr);
push @out, @addendum;
unshift @out, $pkg_nam; # put a no-descrip as 2nd line
my $i=1;
foreach ( @out ) {
print "$pkg_nam$first_line\n" if $i==1; # print first_line
s/\s$// if /^\Q$pkg_nam\E$/; # rmv trailing space when no-descrip
$_ .= "\n";
print;
$i++;
if ( $i == 10 ) {
s/\n//;
print $pkg_nam, "Packaged by ", $your_name;
last;
}
}
--
Alan.
 
Old 01-13-2007, 11:21 AM   #4
dunric
Member
 
Registered: Jul 2004
Distribution: Void Linux, former Slackware
Posts: 498

Rep: Reputation: 100Reputation: 100
Quote:
Originally Posted by gnashley
...
Most people don't realize just how important it is for the slack-desc to be exactly right. When you install with installpkg, the slack-desc gets read and the description lines are added to the package database file in /var/log/packages. But,if the name in the slack-desc doesn't match that of the package, these lines do not get written. There can be problems also if there are lines without comments that have spaces (particularly if more than one). You wind up with a database file with lines missing.
This is important because when you remove the package using removepkg it expects those 11 lines to be in the database file. expects to skip over those lines to find the start of the list of installed files. When those lines are not there, removepkg will fail to properly remove the listed files, but it will remove the database file making you think the package was deleted.
I think it's not true what you've said about improper slack-desc file causing not all package files are removed.
Removepkg doesn't rely on fixed 11 lines long header of installed package record but seeks for the file-list by line starting with "./" string or by "FILE LIST:" record. So checks are very sane and slack-desc may be empty or contain almost anything

From removepkg (Slackware 11.0):
Code:
   if fgrep "./" $ADM_DIR/packages/$PKGNAME 1> /dev/null 2>&1; then
    TRIGGER="^\.\/"
   else
    TRIGGER="FILE LIST:"
   fi
...
   sed -n "/$TRIGGER/,/^$/p" < $ADM_DIR/packages/$PKGNAME | \
    fgrep -v "FILE LIST:" | sort -u > $TMP/delete_list$$
 
Old 01-20-2007, 09:53 PM   #5
acummings
Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 615

Original Poster
Rep: Reputation: 50
My goal is I'm investigating/learning right now about the description file(s) ingredient of when it comes to later on the use of pkgbuild.

So, about just the one ingredient to a package that involves the description, on the next am I missing something? Or do I have it correct about that there's the two mentioned files involved with the description?

1.

http://slackware.mirrors.tds.net/pub...1.0/extra/k3b/

k3b-0.12.17-i486-1.tgz

Inside that, in the .tgz package is a file named slack-desc

slack-desc must be a template because it begins with the next:

# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description. Line
<snip>

but it also has the next:

|-----handy-ruler------------------------------------------------------|
k3b: k3b (The CD Creator)
k3b:
k3b: K3b makes writing cds under Linux easy. It has an easy to use
<snip>

2.

http://slackware.mirrors.tds.net/pub...1.0/extra/k3b/

k3b-0.12.17-i486-1.txt

That file has only the eleven lines description. (BTW that file also has a *12th line* which is a *blank* or empty line).

Is the latter file listed at #2 the actual description file while the slack-desc mentioned at #1 above is the template?
--

And I now see that two files need to be created, the pkg_name.txt *and* the slack-desc

I did not realize until now that there's two files that are involved with the description inside a Slackware package.

(I'm still learning, inch by inch) but formerly I'd (and evidently mistakenly) thought that when preparing to build a package that there's to be one description file that needs to be created.

--
Alan.
 
Old 01-20-2007, 09:57 PM   #6
acummings
Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 615

Original Poster
Rep: Reputation: 50
Quote:
of when it comes to later on the use of pkgbuild.
makepkg

not pkgbuild

Thanks. Alan.
 
Old 01-20-2007, 10:42 PM   #7
acummings
Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 615

Original Poster
Rep: Reputation: 50
http://www.linuxpackages.net/pkg_details.php?id=10695

That's the package named "units"

I just now DL it. And in it has only one slack-desc

units: Units - Unit conversion and calculation
units:
units: The program converts quantities expressed in various scales to
units: their equivalents in other scales. The units are defined
units: externally in an extensive, well annotated data file that
units: defines over 2000 units. You can also provide your own data
units: file.
units:
units: Package created by Miha Ulanov
units:
units:

So, all I need is a slack-desc containing a format like the above (my Perl script listed up above in this thread already creates this for me).

I don't know what those other files of the official (k3b in the extra folder) Slackware 11.0 are for. Sorry for the confusion.

Once again, learning. Thanks.

--
Alan.
 
Old 01-21-2007, 12:44 AM   #8
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Lines that begin with '#' are comments and ignored. Usually there's a line or two including a 'handy ruler' for formatting the text in the description lines.
Supposedly the slack-desc can contain from 9-13 description lines (name, but official ones always have 11.
NAME.txt files you see are just copies of the slack-desc description lines. They are for directory browsing convenience and don't have anything to do with installpkg.

I tried using your script with some long lines of text and it didn't parse them quite right, though the slack-desc would be valid.
 
Old 01-27-2007, 05:27 AM   #9
acummings
Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 615

Original Poster
Rep: Reputation: 50
See at bottom of code how to the source_file.txt

$ txtwrap source_file.txt

is the new (less typing) command that creates a slack-desc file.

my $source = 'source_file.txt';

I may put that at the top of the script which would reduce the command to:

$ txtwrap

I also did some other mods.

if the former slack-desc hadn't been deleted in between invocations of the script then sometimes the slack-desc might not updated.

I just tried the next code on a two line source_file.txt where the second line is 719 characters long and it properly formatted a slack-desc file.

Supported first lines of source_file.txt now include:

pkg_name_here for Linux

pkg_name_here-1.2.1 for Linux

pkg_name_here1.2.1 for Linux

pkg_name_here.1.2.1 for Linux

The for Linux part can be substituted with typical slack-desc 1st line text.

The script leaves that 1st line intact and inserts pkg_name: at the beginning of said 1st line in the slack-desc

I'm wondering if this is simple/practical enough: to support the stripping of dash digit or dot which results in the pkg_name: in the left hand column of the slack-desc -- or if a part of those are not need to be supported.

Other impressions/ideas/suggestions?

Code:
#!/usr/bin/perl
use warnings;
use strict;
# use diagnostics;
use Text::Wrap qw(wrap $columns $huge);

# to create/format a slack-desc file run the next command
# txtwrap source_file.txt
# ./txtwrap source_file.txt
# given that if this code is in a file named txtwrap
# there's just a few prerequisites for source_file.txt
# see at bottom for how to and for example source_file.txt

my $outfil = 'slack-desc'; # name of outputted file
my $your_name = 'Your Name here'; # name of pkg creator
  $columns = 72; # line width edit 72 if needed

  $huge = "wrap";
my $source = shift;
open my $src, '<', $source or die "could not open '$source' $!";
my @text;
while ( <$src> ) {
s/\n+//; # rid source of blank lines
push @text, $_;
}

my $first_line = shift @text; # first_line ungroups from @text
chomp($first_line);
my $pkg_nam = $first_line;

# 1st word of 1st line into $pkg_nam
$pkg_nam =~ s/(-|\d|\.).+//; # dash digit or dot
$pkg_nam = lc $pkg_nam; # lower case it

$pkg_nam .= ': ';
# print $pkg_nam, "\n\n\n\n";
my $out = wrap("$pkg_nam", "$pkg_nam", @text); # wrap @text
my @out = split(/\n/, $out);
my $fillr = "$pkg_nam\n" . "$pkg_nam";
$fillr .= "\n$pkg_nam\n$pkg_nam\n$pkg_nam\n$pkg_nam";
$fillr .= "\n$pkg_nam\n$pkg_nam\n$pkg_nam\n$pkg_nam";
my @addendum = split(/\n/, $fillr);
push @out, @addendum;
unshift @out, $pkg_nam; # put a no-descrip as 2nd line
open my $outf, '>', $outfil or die "could not open '$outfil' $!";
my $i=1;
foreach ( @out ) {
print $outf "$pkg_nam$first_line\n" if $i==1; # print first_line
s/\s$// if /^\Q$pkg_nam\E$/; # rmv trailing space when no-descrip
$_ .= "\n";
print $outf $_;
$i++;
if ( $i == 10 ) {
# s/\n//;
print $outf $pkg_nam, "Packaged by ", $your_name, "\n";
last;
}
}
__END__
source_file.txt must contain at least 2 lines

Here are 3 example, supported 1st lines of source_file.txt

LinPopUp-1.2.0 WinPopUp for Linux

LinPopUp1.2.0 WinPopUp for Linux

LinPopUp.1.2.0 WinPopUp for Linux
        ^
dash, digit, or dot currently supported

it grabs pkg name up to but not dash digit or dot

pkg name is put into the $pkg_nam variable in lower case
--

An example source_file.txt is next to end

LinPopUp-1.2.0 WinPopUp for Linux
Description here beginning on 2nd line of source_file.txt
in any format all run together as one line is ok. The format
doesn't matter. The only thing that matters is your first
line is critical. Your first line must depict the same format
as this sample's first line. From the 2nd line on can be
wrapped at 125 for the line length, or not wrapped at all.
Your first line is grabbed separately by this script whilst
the 2nd through the ending line(s) are grabbed and properly
formatted as the description. To make things easy, we output
a no-description as the 2nd line.  IOW, formatted description
begins on the third line of the output.
--
Alan.
 
Old 01-27-2007, 10:49 AM   #10
jong357
Senior Member
 
Registered: May 2003
Location: Columbus, OH
Distribution: DIYSlackware
Posts: 1,914

Rep: Reputation: 52
Not that it overly matters but I don't think the slack-desc file has to have 11 lines anymore. installpkg and/or makepkg had some changes about a year ago that allows for a lower line count. It does have to be X number of lines tho. I forget how many. Saw a comment in one of the pkgtool scripts that said as much if I'm not mistaken.
 
Old 01-27-2007, 12:01 PM   #11
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Yes, there can be from 9-13 lines, but all Pat's have 11 description lines.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Learning makepkg binarybob0001 Linux - Software 7 04-05-2006 01:36 AM
Makepkg and slack-desc mirto Slackware 7 10-15-2005 03:17 PM
opt software, file hierarchy & prep. packages pross AIX 1 04-14-2004 01:33 PM
Can't get intallpkg to display contents of slack-desc in custom packages. jtX Slackware 4 03-16-2004 02:22 PM
Format of slack-desc file Azmeen Slackware 6 07-11-2003 02:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 01:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration