Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Ask whether there is a update for a package via bash?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
m1027
n00b
n00b


Joined: 27 Jan 2020
Posts: 2

PostPosted: Thu Oct 06, 2022 6:39 am    Post subject: Ask whether there is a update for a package via bash? Reply with quote

Hi,

manually I can do "emerge --pretend --update PACKAGE" to just check (not install) whether there is a update for a package.

How would I do that scripted in bash? There seems to be no distinction by a return value or such.

Thanks
Back to top
View user's profile Send private message
fedeliallalinea
Administrator
Administrator


Joined: 08 Mar 2003
Posts: 30909
Location: here

PostPosted: Thu Oct 06, 2022 6:55 am    Post subject: Reply with quote

I can't find anything on the emerge man page that explains the returned value, you can still use grep to check
Code:
$ emerge -pu --nodeps --verbose n  PACKAGE | grep -E "\[ebuild.+U.+\]"

_________________
Questions are guaranteed in life; Answers aren't.
Back to top
View user's profile Send private message
grknight
Retired Dev
Retired Dev


Joined: 20 Feb 2015
Posts: 1660

PostPosted: Thu Oct 06, 2022 12:51 pm    Post subject: Reply with quote

Compare the results of portageq best_visible / installed <atom> and portageq best_visible / ebuild <atom>.

Note that a package that has multiple slots must include the slot notation in the atom to have consistency.

Edit: The installed test may return empty strings if keywords or masks change, which usually triggers a rebuild without user intervention. If that is undesirable, then use portageq best_version / <atom> instead.
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9527
Location: beyond the rim

PostPosted: Thu Oct 06, 2022 2:23 pm    Post subject: Reply with quote

The quick+dirty option would be to parse the output of `emerge -p --nodeps $pkg`, like
Code:
status=$(emerge -p --nodeps $pkg | fgrep $pkg | cut -d' ' -f 2)
if [[ "$status" == "U" ]]; then
    # Update available
elif [[ "$status" == "UD" ]]; then
    # Downgrade pending
elif [[ "$status" == "N" ]]; then
    # Package not yet installed
elif [[ "$status" == "NS" ]]; then
    # New slot to be installed
fi

(assume all remaining cases to be rebuilds)

However this may miss some corner-cases (see manpage), and in particular ignoring deps may in some (probably academic) edge-cases actually affect the result (same applies to the portageq solution). You could omit --nodeps if $pkg is guaranteed to specify the full exact package name (including category), else the grep might match too much. Question is if you can live with a 95% solution, or do you need a 100% solution?

Quote:
Compare the results of portageq best_visible / installed <atom> and portageq best_visible / ebuild <atom>.

As long as you only check for equality that's fine. I would not attempt to do an actual version comparison in bash though, that's very likely to fail you at some point.

Quote:
I can't find anything on the emerge man page that explains the returned value

The exit code of emerge is used to indicate errors, not to report the result of a successful operation.
Back to top
View user's profile Send private message
grknight
Retired Dev
Retired Dev


Joined: 20 Feb 2015
Posts: 1660

PostPosted: Thu Oct 06, 2022 4:54 pm    Post subject: Reply with quote

Genone wrote:
Quote:
Compare the results of portageq best_visible / installed <atom> and portageq best_visible / ebuild <atom>.

As long as you only check for equality that's fine. I would not attempt to do an actual version comparison in bash though, that's very likely to fail you at some point.


For the purpose of a package is ready to be updated, when the outputs are equal, there is no update. Otherwise there will be. (again, slots matter here in the atom)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum