I wanted to know which pattern provides [WayBack] etckeeper which is in the [WayBack] openSUSE Software package etckeeper
.
It seems no built-in search query can do that, so I built one my own.
Since the result takes quite a while to produce, the output is a pattern.txt
that you can manually search.
This is the command:
zypper search -t pattern | grep "|" | tail -n +2 | perl -pe 's/^.*? \| //' | perl -pe 's/ *\| .*$//' | xargs -I {} sh -c "zypper info -t pattern {}" > patterns.txt
The content is like this (the 2017 date shows I wrote this a long time ago):
Loading repository data...
Reading installed packages...
Information for pattern apparmor:
---------------------------------
Repository : Main Repository (OSS)
Name : apparmor
Version : 20170319-16.1
Arch : x86_64
Vendor : openSUSE
Installed : Yes (automatically)
Visible to User : Yes
Summary : AppArmor
Description :
AppArmor is an application security framework that provides mandatory access control for programs. It protects from exploitation of software flaws and compromised systems. It offers an advanced tool set that automates the development of per-program application sec
urity without requiring additional knowledge.
Contents :
S | Name | Type | Dependency
---+----------------------------+---------+------------
i | apparmor-abstractions | package | Required
i | apparmor-parser | package | Required
i | apparmor-profiles | package | Required
i | audit | package | Required
i | patterns-base-apparmor | package | Required
i+ | patterns-base-minimal_base | package | Required
i | apparmor-utils | package | Recommended
i | patterns-base-apparmor_opt | package | Recommended
i | yast2-apparmor | package | Recommended
Here is some explanation
The first thee bits give the table of patterns without the header line using tail
as explained by [WayBack] linux – Print a file skipping first X lines in Bash – Stack Overflow and [WayBack] SDB:Zypper manual – openSUSE Wiki – Query Commands.
zypper search -t pattern | grep "|" | tail -n +2
The perl
bits strip out the parts until and including the first " | "
and starting with and including the remaining first " | "
:
| perl -pe 's/^.*? \| //' | perl -pe 's/ *\| .*$//'
TI’m using perl
here because sed
does not allow for non-greedy regular expressions: [WayBack] text processing – Non-greedy match with SED regex (emulate perl’s .*?) – Unix & Linux Stack Exchange.
In order to run the regular expression on each line, the -pe
parameters are used as explained at [WayBack] command line – Perl flags -pe, -pi, -p, -w, -d, -i, -t? – Stack Overflow:
Yes, Google is notoriously difficult for looking up punctuation and, unfortunately, Perl does seem to be mostly made up of punctuation :-)
The command line switches are all detailed in perlrun. (available from the command line by calling perldoc perlrun
)
Going into the options briefly, one-by-one:
-p: Places a printing loop around your command so that it acts on each
line of standard input. Used mostly so Perl can beat the
pants off awk in terms of power AND simplicity :-)
-n: Places a non-printing loop around your command.
-e: Allows you to provide the program as an argument rather
than in a file. You don't want to have to create a script
file for every little Perl one-liner.
-i: Modifies your input file in-place (making a backup of the
original). Handy to modify files without the {copy,
delete-original, rename} process.
-w: Activates some warnings. Any good Perl coder will use this.
-d: Runs under the Perl debugger. For debugging your Perl code,
obviously.
-t: Treats certain "tainted" (dubious) code as warnings (proper
taint mode will error on this dubious code). Used to beef
up Perl security, especially when running code for other
users, such as setuid scripts or web stuff.
…
-w
is generally to be avoided, actually, as it enables warnings for all code, including CPAN modules which weren’t written with warnings in mind. The results are generally pretty noisy, as well as pretty useless.
-w
is generally avoided, but it should be replaced with use warnings
in your own code.
…
- Can you enlighten about the order of the flags? If I do
perl -i -0pe
everything works as expected, if I do perl -i -0ep
it doesn’t, if I change other flags order, it also breaks. What’s the deal with that? I’m very confused…
- Arguments that may/must take an additional parameter can’t be inside a compressed list.
-i
takes an extension for the backup. -e
takes a perl command. In -0ep
you are telling perl that ‘p’ is a perl command instead of an argument. That won’t work out well at all.
The final bit is using xargs
to call zypper info
for gettting information on each pattern based on [WayBack] SDB:Zypper manual – openSUSE Wiki – Package Management Commands.:
| xargs -I {} sh -c "zypper info -t pattern {}" > patterns.txt
The outcome
There is no pattern that installs package etckeeper
.
Too bad, as on a new system, it is one of the first packages I install.
–jeroen
Like this:
Like Loading...
Related
Leave a Reply