Thursday, June 2, 2016

How to revert packages from the previous repo

 The most common usecase doing a vendor change of packages

You did a dup to a specific repository but you want to revert back the packages to the previous repository.

First find out the list of your repos.

  •   zypper lr  


#  | Alias                                           | Name                                                               | Enabled | Refresh
---+----------------------------------+--------------------------------------------------+---------+--------
 1 | Packman                                   | Packman                                                           | Yes     | No    
 2 | libdvdcss                                   | libdvdcss                                                            | Yes     | No    
 3 | openSUSE-13.2-0                    | openSUSE-13.2-0                                            | Yes     | No    
 4 | repo-debug                               | openSUSE-13.2-Debug                                   | No       | No    
 5 | repo-debug-update                 | openSUSE-13.2-Update-Debug                    | No       | No    
 6 | repo-debug-update-non-oss | openSUSE-13.2-Update-Debug-Non-Oss   | No       | No    
 7 | repo-non-oss                            | openSUSE-13.2-Non-Oss                              | Yes      | No    
 8 | repo-oss                                    | openSUSE-13.2-Oss                                       | Yes      | No    
 9 | repo-source                              | openSUSE-13.2-Source                                 | No        | No    
10 | repo-update                            | openSUSE-13.2-Update                                 | Yes      | No    
11 | repo-update-non-oss            | openSUSE-13.2-Update-Non-Oss                | Yes      | No  
12 | shells                                        | shells                                                                 | Yes      | No




The leading number in the repos would suffice in our example. In this example we will do a vendor change from OBS shell repo to standard openSUSE repo.

List the packages from the shell repo (leading number 12)

  •  zypper --no-refresh se -t package -ir 12 | awk '$1 ~ /^i/{print $3}'

The --no-refresh: literal meaning no need to explain.
The -t package : type is a package
The se means: search
The i means: installed-only
The r means: repo and its arguments are <aliase|repo|url> which zypper will ONLY search for packages.



bash
bash-completion
bash-doc
bash-lang
command-not-found
ksh
libreadline6
readline-doc
scout
zsh




Replace the   {print $3}   with    {printf("<%s>\n", $3)}   in the awk code to check for white spaces in the packages names.

  •  zypper --no-refresh se -t package -ir 12 | awk '$1 ~ /^i/{printf("<%s>\n", $3)}'


<bash>
<bash-completion>
<bash-doc>
<bash-lang>
<command-not-found>
<ksh>
<libreadline6>
<readline-doc>
<scout>
<zsh>





That looks good so far since the     <   and   >   does not show any white space before and after the package names.
Now capture/save that packages in an (bash) array named packages in our example.

  •  mapfile -t packages < <(zypper --no-refresh se -t package -ir 12 | awk '$1 ~ /^i/{print $3}') 

The previous code is bash which requires version 4 and up. Now if you're stuck with bash3 (which is highly unlikely but hey :) ) you can do a while read loop and save the output in an array.


  while read -r package; do 
     packages+=("$package")
  done < <(zypper --no-refresh se -t package -ir 12 | awk '$1 ~/^i/{print $3}') 


Note that  package   and    packages   are not the same and it is arbitrary.

Now disable that shell repo (leading number 12).

  •  zypper mr -d 12 

Do a force reinstall of the packages that came from the OBS shell repo (leading number 12) to the standard openSUSE repo. The idea is, since the OBS repo is disabled then libzypp or zypper does not have a choice but to look for packages at the enabled repos.

  •  zypper in -f "${packages[@]}" 

Thats it, just wait for zypper to tell you that packages are going to be reinstalled.

----
Additional search for packages using zypper

To list packages

  •  zypper --no-refresh se -t package -ir # 

To list patterns

  •   zypper --no-refresh se -t pattern -ir # 

To list patches

  •   zypper --no-refresh se -t patch -ir #  

where # is the number 12 in the previous example. Adjust/add that modification to the awk code on the previous example and you should be fine.

So far only package and pattern can be force-reinstall ( at least on this side ).

1 comment:

  1. Their wide range of extras and goodies are on their web site, you may find a way to|which you'll} visit right here. The Snapmaker 3D printers aren’t just 3D printers – you Duvet Cover can to|you possibly can} switch the extruder module out and switch in the CNC carver, or the laser engraver module in just a few minutes and get working. This opens up prospects for both duplication 3D printing , and mirror modes , significantly enhancing efficiency. Unboxing and meeting from our Kobra evaluation.The Anycubic Kobra delivers unbelievable value for the asking price, with a spec sheet that reads like one for a printer twice its price.

    ReplyDelete