LinuxQuestions.org
Review your favorite Linux distribution.
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 09-30-2013, 09:17 AM   #1
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, CentOS, Ubuntu, Fedora, Timesys, Linux From Scratch
Posts: 1,777
Blog Entries: 20

Rep: Reputation: 115Reputation: 115
package NAMING scheme


I could not find a document that would confirm this, though I did see many examples by various individuals that contradicted this. But I'm basically interested in what is used by Slackware and maybe SBo. My purpose is so I can make a tool that will translate a package name with a version to a package name without a version, for matching a version-less reference.

The base version-less package name may have any number of "-" characters separating parts of the name. A version string is constructed that does not include any "-" characters. It is appended to the name separated by "-", followed by some kind of sequence number (what is this called, "packaging version"), also separated by "-".

I have seen package names with as many as 4 "-" separated parts before the version number, such as "font-adobe-utopia-100dpi".

So the following awk command could input the full versioned name and output the version-less name:
Code:
awk -F- '{m=NF-2;s="";for(i=1;i<m;++i){s=s "-" $i;};print substr(s,2);}'
Is this correct or do I need to know more about this than I figured so far?
 
Old 09-30-2013, 09:45 AM   #2
NoStressHQ
Member
 
Registered: Apr 2010
Location: Lausanne - Switzerland ( Bordeaux - France / Montreal - QC - Canada)
Distribution: Slackware Leet - 32/64bit
Posts: 278

Rep: Reputation: 94
Try using regular expressions instead of parsing the string with bare hands.
 
Old 09-30-2013, 09:54 AM   #3
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 3,410

Rep: Reputation: 835Reputation: 835Reputation: 835Reputation: 835Reputation: 835Reputation: 835Reputation: 835
If you google for slackware package naming convention, this is the top hit. http://www.slackware.com/~mozes/docs...esentation.pdf
Is this what you mean?
Code:
bash-4.2$ echo "icedtea-web-1.4-x86_64-2alien.txz" | rev | cut -d'-' -f4- | rev
icedtea-web
 
1 members found this post helpful.
Old 09-30-2013, 10:01 AM   #4
TommyC7
Member
 
Registered: Mar 2012
Distribution: Slackware, CentOS, OpenBSD, FreeBSD
Posts: 437

Rep: Reputation: Disabled
If I'm understanding this correctly, you're trying to get just the package name (or package name with version)?

I don't know a whole lot of awk, so I use this (for package name only):
Code:
rev | cut -f 4- -d "-" | rev
So if I wanted a list of installed packages without their version name:
Code:
ls -1 /var/log/packages | rev | cut -f 4- -d "-" | rev
Personally I'm not a huge fan of the whole: `rev | cut | rev' thing but I haven't figured out a way to do it without rev in shell so I've stuck with it.

If you want package names with version, you just need to change the field list to "3-" so it looks like:
Code:
ls -1 /var/log/packages | rev | cut -f 3- -d "-" | rev
You can of course, use the one with the package name and a version, then just take off the version with another `cut' probably.

Last edited by TommyC7; 09-30-2013 at 10:03 AM.
 
1 members found this post helpful.
Old 09-30-2013, 10:11 AM   #5
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, CentOS, Ubuntu, Fedora, Timesys, Linux From Scratch
Posts: 1,777
Blog Entries: 20

Original Poster
Rep: Reputation: 115Reputation: 115
Quote:
Originally Posted by NoStressHQ View Post
Try using regular expressions instead of parsing the string with bare hands.
I could not figure out such an expression for this.
 
Old 09-30-2013, 10:15 AM   #6
Didier Spaier
Senior Member
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slackware{,64}-{14.1,current} on a Lenovo Thinkpad T61 6457-4XG
Posts: 4,189

Rep: Reputation: 1023Reputation: 1023Reputation: 1023Reputation: 1023Reputation: 1023Reputation: 1023Reputation: 1023Reputation: 1023
Why reinvent the wheel? Just have a look at functions package_base() and package_name() in /sbin/{install,remove,upgrade}pkg

ERRATUM read pkgbase(), not package_base()

Last edited by Didier Spaier; 09-30-2013 at 11:10 AM. Reason: ERRATUM
 
Old 09-30-2013, 10:18 AM   #7
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, CentOS, Ubuntu, Fedora, Timesys, Linux From Scratch
Posts: 1,777
Blog Entries: 20

Original Poster
Rep: Reputation: 115Reputation: 115
Quote:
Originally Posted by TommyC7 View Post
If I'm understanding this correctly, you're trying to get just the package name (or package name with version)?

I don't know a whole lot of awk, so I use this (for package name only):
Code:
rev | cut -f 4- -d "-" | rev
So if I wanted a list of installed packages without their version name:
Code:
ls -1 /var/log/packages | rev | cut -f 4- -d "-" | rev
Personally I'm not a huge fan of the whole: `rev | cut | rev' thing but I haven't figured out a way to do it without rev in shell so I've stuck with it.

If you want package names with version, you just need to change the field list to "3-" so it looks like:
Code:
ls -1 /var/log/packages | rev | cut -f 3- -d "-" | rev
You can of course, use the one with the package name and a version, then just take off the version with another `cut' probably.
Actually, the "whole" 'rev | cut | rev' thing makes sense. For me "rev" just wasn't in my mental toolkit so I never thought to try it (I don't think I've ever used it for anything). I guess my background of lots of "by hand" parsing in C bent my mind in the direction of doing it "by hand" in shell with awk.

I was focused more on "is this really the naming scheme" (my google search just didn't come up with anything, perhaps because I did not use the term "convention"), rather than "how could one parse this" (I have no trouble with that ... I just do it by hand).
 
Old 09-30-2013, 10:25 AM   #8
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, CentOS, Ubuntu, Fedora, Timesys, Linux From Scratch
Posts: 1,777
Blog Entries: 20

Original Poster
Rep: Reputation: 115Reputation: 115
Quote:
Originally Posted by Didier Spaier View Post
Why reinvent the wheel? Just have a look at functions package_base() and package_name() in /sbin/{install,remove,upgrade}pkg
I didn't see "package_base()" in there. I did see "pkgbase()" but it's just removing the extension (not something I need ... at least not yet).

I did see "package_name()" but it seems to be more complex and I don't really follow it. Can the name scheme be described in English? (or French or German or Norwegian is OK)
 
Old 09-30-2013, 10:32 AM   #9
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,752

Rep: Reputation: 463Reputation: 463Reputation: 463Reputation: 463Reputation: 463
If you are using bash, then simply:
PKG=full-name-version-arch-build #(with or without *.txz)
echo NAME=${PKG%-*-*-*}
You are correct, the separator is the '-' character and fields should be viewed from right to left. In other words, if you have a version number(or arch or build) with a '-' in them, then installpkg will be confused. Names can have any number of '-' chars in them as you like.
 
Old 09-30-2013, 10:43 AM   #10
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, CentOS, Ubuntu, Fedora, Timesys, Linux From Scratch
Posts: 1,777
Blog Entries: 20

Original Poster
Rep: Reputation: 115Reputation: 115
Here is PART of what I am going to be doing with this. I want a search mechanism where an exact package can be found, rather than a prefix (that would be tempting but for what I'm doing would cause problems). If I did a prefix type search then "sysvinit" could match all of "sysvinit-2.88dsf-i486-3.txz" and "sysvinit-functions-8.53-i486-2.txz" and "sysvinit-scripts-2.0-noarch-15.txz". But I really want "sysvinit" to match "
sysvinit-2.88dsf-i486-3.txz". To get "sysvinit-functions-8.53-i486-2.txz" then "sysvinit-functions" should be used. This is because of the way I am building a list of packages that will be used to select package files for installation (it will also allow specifying the package with the version).

I don't need help on how this will be done. I was just looking for confirmation of the name scheme, that the last 3 parts separated by "-" are not part of the name itself.
 
Old 09-30-2013, 10:49 AM   #11
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, CentOS, Ubuntu, Fedora, Timesys, Linux From Scratch
Posts: 1,777
Blog Entries: 20

Original Poster
Rep: Reputation: 115Reputation: 115
Quote:
Originally Posted by gnashley View Post
If you are using bash, then simply:
PKG=full-name-version-arch-build #(with or without *.txz)
echo NAME=${PKG%-*-*-*}
You are correct, the separator is the '-' character and fields should be viewed from right to left. In other words, if you have a version number(or arch or build) with a '-' in them, then installpkg will be confused. Names can have any number of '-' chars in them as you like.
At this point in my code development I'm taking the full file name and coming up with just the versionless name. See my awk script. See the "rev|cut|rev" method it seems most everyone else uses. Do you have something that would be better?
 
Old 09-30-2013, 11:00 AM   #12
ruario
Senior Member
 
Registered: Jan 2011
Location: Oslo, Norway
Distribution: Slackware
Posts: 1,817

Rep: Reputation: 817Reputation: 817Reputation: 817Reputation: 817Reputation: 817Reputation: 817Reputation: 817
Quote:
Originally Posted by NoStressHQ View Post
Try using regular expressions instead of parsing the string with bare hands.
Quote:
Originally Posted by Skaperen View Post
I could not figure out such an expression for this.
Here it is as a possible regex:

Code:
$ ls /var/log/packages | sed -r 's/^([[:graph:]]+)(-[[:alnum:]\.\+_]+){3}$/\1/'
EDIT: P.S. I checked and it gives the same result as the earlier command with rev:

Code:
$ diff -s <(ls /var/log/packages | rev | cut -f 4- -d "-" | rev) <(ls /var/log/packages | sed -r 's/^([[:graph:]]+)(-[[:alnum:]\.\+_]+){3}$/\1/')
Files /dev/fd/63 and /dev/fd/62 are identical

Last edited by ruario; 09-30-2013 at 11:08 AM.
 
Old 09-30-2013, 11:13 AM   #13
GazL
Senior Member
 
Registered: May 2008
Posts: 3,383

Rep: Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913
This is what I use in one of my scripts. It generates a list of available packages using the following approach
Code:
gazl@ws1:~$ function reformat_available() {    sed -e 's:^\(.*/\)\(.*\)-\([^-]*\)-\([^-]*\)-\([0-9]\+\)\(.*\)\(\.t.z\)$:\2 \2-\3-\4-\5\6 \1\2-\3-\4-\5\6\7:'; }
gazl@ws1:~$ find /local/slackware/slackware64-current/slackware64/ -name "*.t?z" | sort | reformat_available
The output is formatted into 3 fields: base package name, versioned package name and the full filepath of the package on disk.

If you want to look-up a specific package it's just a case of tightening the grep using the appropriate anchors.
Code:
gazl@ws1:~$ find /local/slackware/slackware64-current/slackware64/ -name "*.t?z" | reformat_available | grep sysvinit 
sysvinit-functions sysvinit-functions-8.53-x86_64-2 /local/slackware/slackware64-current/slackware64/a/sysvinit-functions-8.53-x86_64-2.txz
sysvinit-scripts sysvinit-scripts-2.0-noarch-15 /local/slackware/slackware64-current/slackware64/a/sysvinit-scripts-2.0-noarch-15.txz
sysvinit sysvinit-2.88dsf-x86_64-3 /local/slackware/slackware64-current/slackware64/a/sysvinit-2.88dsf-x86_64-3.txz
gazl@ws1:~$ find /local/slackware/slackware64-current/slackware64/ -name "*.t?z" | reformat_available | grep "^sysvinit "
sysvinit sysvinit-2.88dsf-x86_64-3 /local/slackware/slackware64-current/slackware64/a/sysvinit-2.88dsf-x86_64-3.txz
gazl@ws1:~$
 
Old 09-30-2013, 11:43 AM   #14
Lennie
Member
 
Registered: Aug 2012
Location: Sweden
Distribution: LFS, built with pacman
Posts: 301

Rep: Reputation: 60
You need to store all candidates in an array, and loop through them until you find the package you want.
A simple example to illustrate it:
Code:
$ pkgs=$(find . -name "sysvinit*")
$ echo ${pkgs[@]}
./sysvinit-2.88dsf-x86_64-2 ./sysvinit-functions-8.53-x86_64-2 ./sysvinit-scripts-2.0-noarch-13
$ for i in ${pkgs[@]}; do
> i=${i##*/}
> i=${i%-*-*-*}
> echo $i
> if [[ "$i" == sysvinit ]]; then
> echo "found it: $i"
> fi
> done
sysvinit
found it: sysvinit
sysvinit-functions
sysvinit-scripts
$
 
Old 09-30-2013, 12:27 PM   #15
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, CentOS, Ubuntu, Fedora, Timesys, Linux From Scratch
Posts: 1,777
Blog Entries: 20

Original Poster
Rep: Reputation: 115Reputation: 115
Quote:
Originally Posted by GazL View Post
This is what I use in one of my scripts. It generates a list of available packages using the following approach
Code:
gazl@ws1:~$ function reformat_available() {    sed -e 's:^\(.*/\)\(.*\)-\([^-]*\)-\([^-]*\)-\([0-9]\+\)\(.*\)\(\.t.z\)$:\2 \2-\3-\4-\5\6 \1\2-\3-\4-\5\6\7:'; }
gazl@ws1:~$ find /local/slackware/slackware64-current/slackware64/ -name "*.t?z" | sort | reformat_available
The output is formatted into 3 fields: base package name, versioned package name and the full filepath of the package on disk.

If you want to look-up a specific package it's just a case of tightening the grep using the appropriate anchors.
Code:
gazl@ws1:~$ find /local/slackware/slackware64-current/slackware64/ -name "*.t?z" | reformat_available | grep sysvinit 
sysvinit-functions sysvinit-functions-8.53-x86_64-2 /local/slackware/slackware64-current/slackware64/a/sysvinit-functions-8.53-x86_64-2.txz
sysvinit-scripts sysvinit-scripts-2.0-noarch-15 /local/slackware/slackware64-current/slackware64/a/sysvinit-scripts-2.0-noarch-15.txz
sysvinit sysvinit-2.88dsf-x86_64-3 /local/slackware/slackware64-current/slackware64/a/sysvinit-2.88dsf-x86_64-3.txz
gazl@ws1:~$ find /local/slackware/slackware64-current/slackware64/ -name "*.t?z" | reformat_available | grep "^sysvinit "
sysvinit sysvinit-2.88dsf-x86_64-3 /local/slackware/slackware64-current/slackware64/a/sysvinit-2.88dsf-x86_64-3.txz
gazl@ws1:~$
This is very close to what I want to do. But this is going to be something that repeats the search for all packages from a given list. So my idea is to generate the list that maps the non-version basename and version basename to full path just once and store that in a file. Then I can run grep to do the search ... many times.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Fedora 15 - Changing Eth Device Naming Scheme! zer0signal General 10 01-26-2011 06:46 PM
[SOLVED] Ubuntu Karmic: How do I use the sdX naming scheme instead of UUID? lupusarcanus Linux - Newbie 7 03-15-2010 11:52 PM
Ubuntu Package Naming Suggestion Mr. Swillis Linux - General 14 08-02-2008 09:07 PM
Is there a way to have grub translate its own naming to naming scheme under Linux zhjim Linux - Software 6 05-28-2006 08:09 AM
Mandrake adopts new roadmap and naming scheme TravisOSF Linux - News 7 03-28-2005 10:30 AM


All times are GMT -5. The time now is 09:19 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration