Friday, June 3, 2016

How to Install packages from my hard drive.

Most if not all packages (files ending in *.rpm) are on the online repositories. In some cases you have the rpm from your pc or you have downloaded it from some site/server etc.  Question is how would one install it?

Simple answer is to use the rpm utility since openSUSE is one of the rpm-based distro like Rhel and Centos but we will not use that in our example since openSUSE has zypper.

To install the package name foo

      
    zypper in foo.rpm
  

or one can use the absolute path

      
    zypper in /path/to/foo.rpm
 

e.g.

      
    zypper in /var/run/media/jetchisel/foo.rpm 
 


Another question is: 


What if you have a bunch of packages (rpm's) that you want to install?  


One can work around it by using some shell tricks on the cli. One in particular is the use of glob and an array.

Save the rpm's in an array.

      
    packages=(*.rpm)
 

or use an absolute path.

      
    packages=(/path/to/myrpm/*.rpm)
 

e.g.

      
    packages=(/var/run/media/jetchisel/*.rpm)
 


Install the rpm's

      
    zypper in "${packages[@]}"
 

The last but not the least question.  


I have a bunch of rpm's which are the dependencies from the program/package that is located on the online repositories.


The alternative question is:    


how can I make a local directory (folder) to become a local repository?


First option is using zypper.


   zypper ar -t plaindir . local 


or one can use an absolute path for the directory.


   zypper ar -t plaindir  /path/to/rpm local 


let's take out that zypper code piece by piece.

 zypper ar  is add repository

  -t plaindir   means type is a plain directory (folder)

the    .    (dot)  means where you are located the value of the command    pwd  
 
  /path/to/rpm      is the absolute path.

   local   is the alias of the repository and it is arbitrary

Once the directory (folder) is added as a repo you can now refresh it.


   zypper ref local


Print the packages from the local repo.


   zypper --no-refresh se -t package -r local




Now install the package(s) and enjoy! :)


One can look for more option using the help option for zypper.


   zypper help ar 


The second option is using yast2 in the following order.

  1. yast2 
  2. Software Repositories
  3. Add
  4. Local Directory




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 ).