You are not logged in.

#1 2019-06-11 22:32:37

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 9,814
Website

Find files linked against libxfconf-0.so.2 for a pacman hook [solved]

I want to write a script that will check a list of packages against libxfconf-0.so.2 and then warn the user only if one or more of them is linked against libxfconf-0.so.2 otherwise it will end silently. 

What I started on is just wrong (matches ne 0 due to pre package list not checked packages).  What is the most efficient way to do this?

#!/bin/bash
  
readarray -t pkgs < <( { pacman -Qoq /usr/include/xfce4 ; pacman -Qoq /usr/lib/xfce4 ; } | grep -v xfconf-devel | sort -u)
if [ ${#pkgs[@]} -ne 0 ]; then
  printf "WARNING: the following are linked against libxfconf-0.so.2 and need a rebuild!\n"

  for pkg in "${pkgs[@]}"; do
    mapfile -t files < <(pacman -Qlq "$pkg" | grep -v /$)
    grep -Fq 'libxfconf-0.so.2' "${files[@]}" <&- 2>/dev/null && printf " -> %s\n" "$pkg"
  done
fi

Last edited by graysky (2019-06-12 23:41:30)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2019-06-11 22:44:48

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 22,040
Website

Re: Find files linked against libxfconf-0.so.2 for a pacman hook [solved]

This is untested, but should do it:

#!/bin/sh

ldd $(pacman -Qlq $PACKAGES) 2>&1 | \
	sed -n '/:$/{s/://;h;};/libxfconf-0.so.2/{g;p;}' | \
	pacman -Qqo - 2>/dev/null | \
	sort -u

This is only a very minor change to my script that checks for any foreign packages (e.g., aur packages) that need to be rebuilt which has had a good bit of testing:

#!/bin/sh

ldd $(pacman -Qlmq) 2>&1 | \
        sed -n '/:$/{s/://;h;};/not found/{g;p;}' | \
        pacman -Qqo - 2>/dev/null | \
        sort -u

EDIT: this doesn't give a "Warning ..." message, it simply outputs the names of packages containing binaries linked against that lib.  But it'd be easy enough to save the list, and print that message followed by the list if the list is not empty.

EDIT 2: note also that in making the list of packages, pacman can take multiple parameters, the following two are equivalent (well, one of them sucks, one doesn't, but they do the same thing):

$some_command <( { pacman -Qoq /path/to/file1; pacman -Qoq /path/to/file2 })
$some_command <( pacman -Qoq /path/to/file1 /path/to/file2 )

EDIT 3: I'm not sure I understand your approach, are you grepping binaries to find the name of the lib?  That doesn't seem wise.  That will likely be very slow, and could easily return false positives if a man page or README mentions that lib at all.  `ldd` will tell you what is actually linked.

Last edited by Trilby (2019-06-11 22:57:21)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2019-06-11 23:05:25

NuSkool
Member
Registered: 2015-03-23
Posts: 89

Re: Find files linked against libxfconf-0.so.2 for a pacman hook [solved]

This is untested

Tested, not sure what exactly looking for?

$ PACKAGES=$(pacman -Qgq xfce4) ; ldd $(pacman -Qlq $PACKAGES) 2>/dev/null | sed -n '/:$/{s/://;h;};/libxfconf-0.so.2/{g;p;}' | pacman -Qqo - 2>/dev/null | sort -u
thunar
thunar-volman
xfce4-panel
xfce4-power-manager
xfce4-session
xfce4-settings
xfconf
xfdesktop
xfwm4
$ pacman -Qqo /usr/lib/libxfconf-0.so.2
xfconf

Last edited by NuSkool (2019-06-11 23:15:47)

Offline

#4 2019-06-11 23:49:25

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 9,814
Website

Re: Find files linked against libxfconf-0.so.2 for a pacman hook [solved]

@Trilby - So something like this?

#!/bin/sh
  
readarray -t pkgs < <( { pacman -Qoq /usr/include/xfce4 ; pacman -Qoq /usr/lib/xfce4 ; } | grep -v xfconf-devel | sort -u)

ldd $(pacman -Qlq "${pkgs[@]}" ) 2>&1 | \ 
  sed -n '/:$/{s/://;h;};/libxfconf-0.so.2/{g;p;}' | \
  pacman -Qqo - 2>/dev/null | \
  sort -u

CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#5 2019-06-12 00:40:40

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 22,040
Website

Re: Find files linked against libxfconf-0.so.2 for a pacman hook [solved]

Somewhat.  But if you are going to use all the bashisms in making the package list (there really no need at all there for readarray) then you need to change the shebang.  Also you overlooked the comment about pacman taking more than one argument: there's no need for the two pacman's in the subshell that generates the list.  The sort also does nothing there.  So this would do:

#!/bin/sh
ldd $(pacman -Qoq /usr/include/xfce4 /usr/lib/xfce4 | grep -v xfconf-dev | pacman -Qlq) 2>&1 | \
# ...

But I still can't really make out what the goal is there.  You are looking for packages containing binaries linking against a specific lib, right?  So why are you looking for packages that own /usr/include/xfce4, there are no binaries under that path.  Are all the potential packages in a specific group?  Would this work:

#!/bin/sh

ldd $(pacman -Qgq xfce4 | pacman -Qlq -) 2>&1 | \
# ...

Or wouldn't all these candidate packages depend on xfconf?  Why not start with those packages as a list?  And why are you filtering out xfconf-dev?  Surely xfconf-dev can't possibly link against a library provided by xfconf.  You've clarified what you want to do with this "list of packages", so that's the code I put in my first reply.  But the criteria for that initial list of packages doesn't make any sense.  What packages do you want to check?

I suspect what you may really want would be this:

#!/bin/sh

ldd $(pactree -rl xfconf | pacman -Qlq) 2>&1 |\
#...

This will check every package with an xfconf dependency to see if anything wthin that package it is (still) linking
to the specific lib file.

Also, if this is all for a pacman hook, I'm not sure if it's kosher to use pacman commands in a pacman hook.

What is the end goal here?  Are target users those who install xfconf-devel and you want to warn them to rebuld anything that depends on it?  Are they to rebuild repo packages from ABS, or do you expect that they have AUR versions of those packages as well?  If the latter, then my original script for checking which foreign packages need to be rebuilt would work "out of the box" - but that's not something for a pacman hook as that's just normal system maintenance.

Last edited by Trilby (2019-06-12 00:50:49)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2019-06-12 18:13:26

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 9,814
Website

Re: Find files linked against libxfconf-0.so.2 for a pacman hook [solved]

Trilby wrote:

What is the end goal here?  Are target users those who install xfconf-devel and you want to warn them to rebuld anything that depends on it?

@Trilby - The use case is for the xfce4-devel packages.  Need to make sure none of the non-devel xfce4 packages depend on that lib and warn the user to rebuild if some are found.  The pacman hook triggers the check and warn script (your proposal above).  I'd like the warning to be silent unless there is something to report, similar to what the perl package does:  https://git.archlinux.org/svntogit/pack … kages/perl

...is there some way to grep for libxfconf-0.so.2 in the pacman database or is that what the pacman commands are essentially doing?

I am hosting the xfce4-devel packages in repo-ck, so they won't be foreign packages (ie pacman -Qm won't be universal).

Last edited by graysky (2019-06-12 18:21:08)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#7 2019-06-12 19:29:54

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 22,040
Website

Re: Find files linked against libxfconf-0.so.2 for a pacman hook [solved]

graysky wrote:

Need to make sure none of the non-devel xfce4 packages depend on that lib

Then skip all that pacman -Qo stuff for generating the initial list.  The packages that *could* be subject to this are a easily definable finite set (e.g., from `pactree -srl`).  Just use that set as the initial list to check with my script.

graysky wrote:

...is there some way to grep for libxfconf-0.so.2 in the pacman database...

Sure, but the results would be meaningless.  The presence or absence of that text-string is not really relevant to the question at hand: you need to know what packages contain binaries linked against that lib.  This information is not present in the pacman database.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2019-06-12 20:12:29

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 9,814
Website

Re: Find files linked against libxfconf-0.so.2 for a pacman hook [solved]

@Trilby - capital idea!  I defined all possibles in the pkgs array.  I think I would need a silent way to check to see which ones were actually installed or else your code will print errors/package x was not found.  Since I want this to be in a pacman hook, I don't think using pactree (from pacman-contrib) would be right.

Here is the code I have based on your suggestion:

#!/bin/bash
pkgs=(libxfce4ui thunar xfce4-clipman-plugin xfce4-notes-plugin xfce4-notifydxfce4-panel
	xfce4-power-manager xfce4-pulseaudio-plugin xfce4-session xfce4-settings xfce4-xkb-plugin
	xfconf xfwm4
)

ldd $(pacman -Qlq "${pkgs[@]}") 2>&1 | \
	sed -n '/:$/{s/://;h;};/libxfconf-0.so.2/{g;p;}' | \
	pacman -Qqo - 2>/dev/null | \
	sort -u

Last edited by graysky (2019-06-12 20:13:24)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#9 2019-06-12 21:46:50

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 22,040
Website

Re: Find files linked against libxfconf-0.so.2 for a pacman hook [solved]

graysky wrote:

I think I would need a silent way to check to see which ones were actually installed or else your code will print errors/package x was not found.

Don't over think it.  If the internal pacman command can produce errors that you want to silence, just do that.

ldd $(pacman -Qlq "${pkgs[@]}" 2>/dev/null) 2>&1 | \
	sed -n '/:$/{s/://;h;};/libxfconf-0.so.2/{g;p;}' | \
	pacman -Qqo - 2>/dev/null | \
	sort -u

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#10 2019-06-12 23:07:25

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 9,814
Website

Re: Find files linked against libxfconf-0.so.2 for a pacman hook [solved]

<< head smack >>
Thanks.

Here is the finished product with a large degree of your help:

#!/bin/bash

pkgs=(libxfce4ui thunar xfce4-clipman-plugin xfce4-notes-plugin xfce4-notifydxfce4-panel
  xfce4-power-manager xfce4-pulseaudio-plugin xfce4-session xfce4-settings xfce4-xkb-plugin
  xfconf xfwm4
)

mapfile -t rebuild < <(ldd $(pacman -Qlq "${pkgs[@]}" 2>/dev/null) 2>&1 | \
  sed -n '/:$/{s/://;h;};/libxfconf-0.so.2/{g;p;}' | \
  pacman -Qqo - 2>/dev/null | \
  sort -u)

if [ ${#rebuild[@]} -ne 0 ]; then
  printf "WARNING: the following are linked against libxfconf-0.so.2 and need a rebuild!\n"
  printf " -> %s\n" "${rebuild[@]}"
fi

CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#11 2019-06-12 23:08:27

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 22,040
Website

Re: Find files linked against libxfconf-0.so.2 for a pacman hook [solved]

If you're going to use the arrays and bash, you may as well use the '[[' conditional rather than '['.

sidenote, neither of the arrays actually do anything for you here that you wouldn't get with a simple variable.

Last edited by Trilby (2019-06-12 23:09:36)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#12 2019-06-12 23:31:48

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 9,814
Website

Re: Find files linked against libxfconf-0.so.2 for a pacman hook [solved]

I can google it, but on what do you base your suggestion to use the double brackets?


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#13 2019-06-12 23:33:57

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 22,040
Website

Re: Find files linked against libxfconf-0.so.2 for a pacman hook [solved]

The same thing you'll find when you google it.  But I'm hardly the one to ask, as I don't write bash anymore.

Last edited by Trilby (2019-06-12 23:35:33)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#14 2019-06-12 23:41:07

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 9,814
Website

Re: Find files linked against libxfconf-0.so.2 for a pacman hook [solved]

Trilby wrote:

The same thing you'll find when you google it.  But I'm hardly the one to ask, as I don't write bash anymore.

Yes, you do big_smile

...and thank you again for the pointers!

Trilby wrote:

Don't over think it.  If the internal pacman command can produce errors that you want to silence, just do that.

ldd $(pacman -Qlq "${pkgs[@]}" 2>/dev/null) 2>&1 | \
	sed -n '/:$/{s/://;h;};/libxfconf-0.so.2/{g;p;}' | \
	pacman -Qqo - 2>/dev/null | \
	sort -u

Last edited by graysky (2019-06-12 23:41:55)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#15 2019-06-13 00:14:19

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 22,040
Website

Re: Find files linked against libxfconf-0.so.2 for a pacman hook [solved]

Nope, you wrote all the bash bits.  This is how I'd write it:

#!/bin/sh

pkgs="
   libxfce4ui
   thunar
   xfce4-clipman-plugin
   xfce4-notes-plugin
   xfce4-notifydxfce4-panel
   xfce4-power-manager
   xfce4-pulseaudio-plugin
   xfce4-session
   xfce4-settings
   xfce4-xkb-plugin
   xfconf
   xfwm4
"

rebuild=$(
   ldd $(pacman -Qlq $pkgs 2>/dev/null) 2>&1 | \
   sed -n '/:$/{s/://;h;};/libxfconf-0.so.2/{g;p;}' | \
   pacman -Qqo - 2>/dev/null | \
   sort -u)

if [ -n "$rebuild" ]; then
   printf 'WARNING: the following are linked against libxfconf-0.so.2 and need a rebuild!\n'
   printf ' -> %s\n' $rebuild
fi

Last edited by Trilby (2019-06-13 00:15:07)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB