View previous topic :: View next topic |
Author |
Message |
m1027 n00b
Joined: 27 Jan 2020 Posts: 2
|
Posted: Thu Oct 06, 2022 6:39 am Post subject: Ask whether there is a update for a package via bash? |
|
|
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 |
|
|
fedeliallalinea Administrator
Joined: 08 Mar 2003 Posts: 30909 Location: here
|
Posted: Thu Oct 06, 2022 6:55 am Post subject: |
|
|
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 |
|
|
grknight Retired Dev
Joined: 20 Feb 2015 Posts: 1660
|
Posted: Thu Oct 06, 2022 12:51 pm Post subject: |
|
|
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 |
|
|
Genone Retired Dev
Joined: 14 Mar 2003 Posts: 9527 Location: beyond the rim
|
Posted: Thu Oct 06, 2022 2:23 pm Post subject: |
|
|
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 |
|
|
grknight Retired Dev
Joined: 20 Feb 2015 Posts: 1660
|
Posted: Thu Oct 06, 2022 4:54 pm Post subject: |
|
|
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 |
|
|
|