0

I filed Is there a way to find patches which need testing from packages you have? and I was given a script which works -

for source in $(dpkg-query --show -f '${source:Package}\n' | sort -u); do bts select source:${source} tag:patch; done

now while the command works - the output is confusing, these few lines are the output -

[$] for source in $(dpkg-query --show -f '${source:Package}\n' | sort -u); do bts select source:${source} tag:patch; done          

781691
725728
805989
677570
772688
823072

Now it would be nice if there was a way to -

a. Gives the listing in descending manner so newer/exciting patches can be known/understood/tried out first than earlier ones.

b. Should list the package it belongs to -

for example 823072 belongs to acpi-support which has a patch or 805989 which is accountsservice . Having package names would be lot nicer.

c. Lastly, each time after the listing is complete (or is it? ) It should exit to command-prompt. If for some reason, networking connection down or not finding any bugs, it should bail out with a statement stating whatever the reason might be.

Is it possible ? I am on zsh and use oh-my-zsh so everything is operated from ~/.oh-my-zsh

Update - I have done something similar for listing local files but do not know how the above can be achieved -

┌─[shirish@debian] - [~] - [6266]
└─[$] alias ll

ll='ls -lt --color=auto --time-style=long-iso'

Update 2 - I tried just sort for now, have no idea about sed

I saw http://www.thegeekstuff.com/2013/04/sort-files/ as well as

http://www.tecmint.com/sort-command-linux/

and specifically saw -

The following sort command sorts lines in test file in reverse order and removes duplicate lines from sorted output.

$ sort -r -u test 5 4 2 1

I tried to use the same in the script shared but it gives a different output altogether -

┌─[shirish@debian] - [~] - [6273]
└─[$] for source in $(dpkg-query --show -f '${source:Package}\n' | sort -r -u); do bts select source:${source} tag:patch; done       
538069
831900
779566
622933
691638
776663
419233

AFAI understand it, sort has been used to make sure that bug numbers do not repeat and are unique (means the listing is only once), don't really know why reverse is not working when it should work as the example shared. Maybe something to do with zsh or I am not writing it correctly :( .

Looking up sed in the meanwhile to see if I can understand something.

Update 3 - this doesn't seem to work in zsh for some reason, just using the sed bits atm -

┌─[shirish@debian] - [~] - [6312]
└─[$] cat find-interesting-patches.sh

for source in $(dpkg-query --show -f '${source:Package}\n' | sort -u) do bts select source:${source} tag:patch | sed "s/^/${source} /g" done

and -

┌─[shirish@debian] - [~] - [6313]
└─[$] ll -h find-interesting-patches.sh

-rwxr-xr-x 1 shirish shirish 141 2016-11-23 23:56 find-interesting-patches.sh

so execute permissions are there

Trying to run it I get -

┌─[shirish@debian] - [~] - [6315]
└─[$] ./find-interesting-patches.sh

./find-interesting-patches.sh: 1: ./find-interesting-patches.sh: Syntax error: "|" unexpected

any ideas what could be wrong here ?

  • (a) and (b) are simple adaptations of the script using standard tools — what have you tried? Regarding (c), the loop takes a long time to run (depending on the number of installed packages), but it does complete eventually. – Stephen Kitt Nov 23 '16 at 10:15
  • I dunno what standard tools you are talking about. I only came to know about --time-style=long-iso sometime back which I have shared but that doesn't work in this instance. I only know of grep as standard tool but don't think that will benefit in this case :( – shirish Nov 23 '16 at 14:46
  • I was thinking of sort and sed. – Stephen Kitt Nov 23 '16 at 14:57
  • I have updated my query, tried few web resources for sort but couldn't get something that worked for sorting in descending order :( – shirish Nov 23 '16 at 16:55
2

Starting with

for source in $(dpkg-query --show -f '${source:Package}\n' | sort -u); do bts select source:${source} tag:patch; done

sorting the output involves another use of sort, to sort the overall output numerically in reverse order:

for source in $(dpkg-query --show -f '${source:Package}\n' | sort -u); do bts select source:${source} tag:patch; done \
| sort -n -r

To display the (source) package name along with the bug number, the simplest option is to add ${source} (the source package) in the right place, processing bts's output each time it's run:

for source in $(dpkg-query --show -f '${source:Package}\n' | sort -u)
do bts select source:${source} tag:patch | sed "s/^/${source} /g"
done

This outputs lines of the form

linux 845422

so we need to change the final sort to sort on the second field:

for source in $(dpkg-query --show -f '${source:Package}\n' | sort -u)
do bts select source:${source} tag:patch | sed "s/^/${source} /g"
done | sort -k2,2n -r

On a single line that's

for source in $(dpkg-query --show -f '${source:Package}\n' | sort -u); do bts select source:${source} tag:patch | sed "s/^/${source} /g"; done | sort -k2,2n -r
  • I updated my query as it doesn't seem to work, no idea why, maybe some zsh thing ? – shirish Nov 23 '16 at 18:31
  • I know that backslash `` is basically to state that the line is ending and new line begans. See paste.debian.net/898195 but still get the same issue. – shirish Nov 23 '16 at 21:24
  • because I don't see the semi-colons, let me check again. – shirish Nov 23 '16 at 21:52
  • Let us continue this discussion in chat. – shirish Nov 23 '16 at 21:55
  • I tried it again, added those semi-colons and still I get the error. paste.debian.net/898201 .... I have not used back-ticks anywhere AFAIK. – shirish Nov 23 '16 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.