You are not logged in.

#1 2011-02-15 09:18:53

ibendiben
Member
Registered: 2007-10-10
Posts: 519

[SOLVED]Howto list directories owned by package: pacman -Qo /dir

pacman -Qo cannot determine ownership of a directory but is there another way?
pacman -Qlq pkg lists system directories too, an example:

pacman -Qlq pacman
#sniplet view
/var/
/var/cache/
/var/cache/pacman/
/var/cache/pacman/pkg/
/var/lib/
/var/lib/pacman/

Now I only want to list the package specific dirs (no system dirs!):

/var/cache/pacman
/var/lib/pacman

Any ideas on how to do this?

Last edited by ibendiben (2011-02-16 09:04:20)

Offline

#2 2011-02-15 11:23:17

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED]Howto list directories owned by package: pacman -Qo /dir

Something like

[karol@black ~]$ pacman -Qlq pacman | grep /var/
/var/
/var/cache/
/var/cache/pacman/
/var/cache/pacman/pkg/
/var/lib/
/var/lib/pacman/

or

[karol@black ~]$ pacman -Qlq pacman | egrep ^/var/ | egrep pacman/$
/var/cache/pacman/
/var/lib/pacman/

Last edited by karol (2011-02-15 11:26:13)

Offline

#3 2011-02-15 12:00:23

ibendiben
Member
Registered: 2007-10-10
Posts: 519

Re: [SOLVED]Howto list directories owned by package: pacman -Qo /dir

Thanks very much for your reply. I need to clarify:
The only 'known' variable is the packagename so grep can't be used. Else I could simply use:

pacman -Qlq <pacakge> | grep -v '/$' 

But this won't help. Why? Because...
...lists both system dirs and package dirs. It lists /var/ AND /var/cache/pacman/
/var/ is a system dir, meaning it contains files and dirs of other packages also. I ónly want the dirs uniq belonging to the specified package.

I need this for a program I want to make to create an 'Applications' dir containing all files and dirs belonging to a package, similar to gobolinux or mac. If there is a good sulotution to above problem this will be a simple way to succeed. Otherwise I might have to alter to much of the standard file hierarchy which I want to avoid as much as possible.

Maybe I could use sed or awk to keep all uniq file/dir locations, comparing /var/ with the following line /var/cache and only keeping the latter:
I to look this up, but something like:

#get list of files and dirs belonging to <package>
pacman -Qlq <pacakge> | grep -v '/$' | \
#sed/awk read $line, 
#append $nextline, 
#if $nextline contains $line,
#remove $line, 
#append $nextline etc...

I belief something like that must be possible. But any kind of script to search the folders that belong to a specified package name is welcome big_smile. Something that replicates the 'supposed' behaviour from pacman -Qlq --dirs <package>.
Very hard to describe, so sorry if I made a mess wink

Offline

#4 2011-02-15 12:03:50

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED]Howto list directories owned by package: pacman -Qo /dir

OK, let's try again:

[karol@black ~]$ cat finddir
#!/bin/bash

pacman -Qlq $1 | egrep $1/$

[karol@black ~]$ ./finddir pacman
/usr/share/pacman/
/var/cache/pacman/
/var/lib/pacman/

Do you want the /usr to be searched too?

ibendiben wrote:

I need this for a program I want to make to create an 'Applications' dir containing all files and dirs belonging to a package, similar to gobolinux or mac. If there is a good sulotution to above problem this will be a simple way to succeed. Otherwise I might have to alter to much of the standard file hierarchy which I want to avoid as much as possible.

I think you should have a look at PKGBUILDs, as they tell what to install where.

Last edited by karol (2011-02-15 12:06:53)

Offline

#5 2011-02-15 12:05:42

ibendiben
Member
Registered: 2007-10-10
Posts: 519

Re: [SOLVED]Howto list directories owned by package: pacman -Qo /dir

Another way would be to generate a list of existing 'system' dirs and remove those from the query list (pacman -Qlq <package>).
Don't know if that would apply allways though. Gonna look into your second post now!

Offline

#6 2011-02-15 12:22:43

ibendiben
Member
Registered: 2007-10-10
Posts: 519

Re: [SOLVED]Howto list directories owned by package: pacman -Qo /dir

BTW here the example of the old script which creates a 'progs'  dir in /tmp containing a folder for specified package, with all the installed files.
Problem is the 'variable' files, created after install, like pacman cache, logs... that's why I want to try add those dirs.

#!/bin/bash
#createpkgdir
#set pkg to desired pkg you want to investigate
pkg=$1
#get install-roots from pacman
pacman -Qlq $pkg | \
#we only want the (complete) filepaths
grep -v '/$' | \
#per filepath, create the necesary dirs
while read -r line
do dirs=`echo $line | sed 's#^\(.*\)/[^/]*$#\1#'`
mkdir -p /tmp/progs/$pkg$dirs
#finally create a symlink
ln -s $line /tmp/progs/$pkg$line
done

Or for command line test:

pkg="pacman"; pacman -Qlq $pkg | grep -v '/$' | while read -r line; do dirs=`echo $line | sed 's#^\(.*\)/[^/]*$#\1#'`; mkdir -p /tmp/progs/$pkg$dirs; ln -s $line /tmp/progs/$pkg$line; done

In the new script I also want to experiment with bind mounts, to get rid of those ugly symlinks.
I still have to investigate your solution! Thanks for the help! (improvements on above also welcome! always learn a lot from other solutions)

Offline

#7 2011-02-15 12:35:49

ibendiben
Member
Registered: 2007-10-10
Posts: 519

Re: [SOLVED]Howto list directories owned by package: pacman -Qo /dir

karol wrote:

I think you should have a look at PKGBUILDs, as they tell what to install where.

Sorry I can't find what you mean. Can you give an example?

Offline

#8 2011-02-15 12:38:47

ibendiben
Member
Registered: 2007-10-10
Posts: 519

Re: [SOLVED]Howto list directories owned by package: pacman -Qo /dir

karol wrote:

OK, let's try again:

[karol@black ~]$ cat finddir
#!/bin/bash

pacman -Qlq $1 | egrep $1/$

[karol@black ~]$ ./finddir pacman
/usr/share/pacman/
/var/cache/pacman/
/var/lib/pacman/

Do you want the /usr to be searched too?

Haha! I like it, but I guess not every package names those custom dirs after their pkgname... but it sure is simple big_smile

Offline

#9 2011-02-15 13:04:15

ibendiben
Member
Registered: 2007-10-10
Posts: 519

Re: [SOLVED]Howto list directories owned by package: pacman -Qo /dir

I'll have a look at pacman-contrib

Offline

#10 2011-02-15 13:16:17

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED]Howto list directories owned by package: pacman -Qo /dir

You are trying to make Arch gobolinux-like, so

[karol@black ~]$ grep -A4 build /var/abs/core/pacman/PKGBUILD
build() {
  cd $srcdir/$pkgname-$pkgver
  ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-doc
  make || return 1
}

maybe you can instruct Arch to put thing where *you* want them. You will need to fix all the scripts of course, because they will search in '--sysconfdir=/etc' while you will put the files in e.g. '--sysconfdir=/foo'.
Are you familiar with 'make && make install'? After 'make', you have everything compiled, but it's sitting in your build directory - maybe you want something like that? 'Install' means copy those files to their respective destinations and set proper attributes.

[karol@black ~]$ whatis install
install (1)          - copy files and set attributes
ibendiben wrote:

I guess not every package names those custom dirs after their pkgname

Actually, I'm not sure.

Offline

#11 2011-02-15 13:29:27

ibendiben
Member
Registered: 2007-10-10
Posts: 519

Re: [SOLVED]Howto list directories owned by package: pacman -Qo /dir

karol wrote:

You are trying to make Arch gobolinux-like, so

[karol@black ~]$ grep -A4 build /var/abs/core/pacman/PKGBUILD
build() {
  cd $srcdir/$pkgname-$pkgver
  ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-doc
  make || return 1
}

maybe you can instruct Arch to put thing where *you* want them. You will need to fix all the scripts of course, because they will search in '--sysconfdir=/etc' while you will put the files in e.g. '--sysconfdir=/foo'.
Are you familiar with 'make && make install'? After 'make', you have everything compiled, but it's sitting in your build directory - maybe you want something like that? 'Install' means copy those files to their respective destinations and set proper attributes.

[karol@black ~]$ whatis install
install (1)          - copy files and set attributes

oh yes, maybe I could patch install to mount --bind instead of copy... problem is mount --bind isn't persistent, so it needs to run every reboot, don't know exactly but this doesn't appeal to me very much... still I'll look into it, thanks again!
I really really want to keep original file hierarchy in place, it can be hidden with gobohide, this way packages can keep their original config. Only problem is how to best create this 'double hierarchy layer', without spending to much system resources. mount --bind works quite cool like that, but I'm not yet sure how to best adapt to it.

Offline

#12 2011-02-15 13:32:39

ibendiben
Member
Registered: 2007-10-10
Posts: 519

Re: [SOLVED]Howto list directories owned by package: pacman -Qo /dir

bacman from pacman-contrib package seems interesting for this purpose

Offline

#13 2011-02-15 13:36:02

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED]Howto list directories owned by package: pacman -Qo /dir

ibendiben wrote:

bacman from pacman-contrib package seems interesting for this purpose

I think bacman will just create a package, e.g. pacman-3.4.3-1-pkg.tar.xz. It is used, when you have an app installed and you don't have the package in the cache anymore and you want to install it on another computer and you can't get this package from any other source.

Offline

#14 2011-02-15 14:57:05

tlvb
Member
From: Sweden
Registered: 2008-10-06
Posts: 297
Website

Re: [SOLVED]Howto list directories owned by package: pacman -Qo /dir

If you are still interested in finding a packages directories;
(requires some tedious setup though, telling it what all the system directories are)

excluded='
/usr/
/usr/include/
/usr/lib/
/usr/lib/pkgconfig/
/usr/share/
/usr/share/licenses/
/usr/share/man/
/usr/share/man/man3/
'
package=zlib
for d in `pacman -Qlq $package|grep -E '/$'`; do echo $excluded|grep -qv $d && echo $d; done

I need a sorted list of all random numbers, so that I can retrieve a suitable one later with a binary search instead of having to iterate through the generation process every time.

Offline

#15 2011-02-15 21:07:31

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,396
Website

Re: [SOLVED]Howto list directories owned by package: pacman -Qo /dir

I'm sure this can be done more efficiently....

> l1=$(pacman -Qql pacman-git | grep /$ | sort)
> l2=$(pacman -Qql $(pacman -Qq | grep -v ^pacman-git$) | grep /$ | sort | uniq)

> comm -23 <(printf "%s\n" "$l1") <(printf "%s\n" "$l2")
/var/cache/pacman/
/var/cache/pacman/pkg/
/var/lib/pacman/

Offline

#16 2011-02-15 21:37:28

ibendiben
Member
Registered: 2007-10-10
Posts: 519

Re: [SOLVED]Howto list directories owned by package: pacman -Qo /dir

Wait, what you suggest Allan... that's definitely something to keep in mind!

Last edited by ibendiben (2011-02-15 21:40:56)

Offline

#17 2011-02-16 09:03:48

ibendiben
Member
Registered: 2007-10-10
Posts: 519

Re: [SOLVED]Howto list directories owned by package: pacman -Qo /dir

Allan's method really puts me on the right track, I can even use pacman -Ql filesystem to filter the system dirs. Amazing I didn't think of it. So simple!
Thanks karol, tlvb for your help, appreciate! It's now solved.

Offline

Board footer

Powered by FluxBB