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

Thursday, December 11, 2014

Curl and download error of packages

Most of the time i am behind a NAT router either at work or at home and those error are pretty common on my openSUSE system.

The old school trick i always do is ping those hosts.

 ping download.opensuse.org 

 ping downloadcontent.opensuse.org 

now edit the file /etc/hosts  and add

 RESULT-OF-IP-FROM-PING  download.opensuse.org 

 RESULT-OF-IP-FROM-PING  downloadcontent.opensuse.org 

eg. something like this.

 195.135.221.134  download.opensuse.org 
 195.135.221.157  downloadcontent.opensuse.org 
 

That trick always saves me from choosing a local mirror manually. It works for me and I'm not saying it will work for everyone, just try it and see.

Monday, April 7, 2014

Boot-Installed-System

Some tips howto boot your not so bootable system using the DVD.












































































































Once you are logged in then you can use
 yast2 bootloader 
 fdisk -l  to check for the bootable flag
 grub2-mkconfig /boot/grub2/grub.cfg 
 mkinitrd 

Good Luck folks!

Saturday, March 8, 2014

Disable autorefresh

Disabling auto refresh of your repositories has some benefits. If you are on a limited internet connection or you just do not want to refresh every time you invoke zypper or yast sw_single then this post might be of interest for you.


Disable auto refresh for all remote repositories.
 zypper mr -R -t 

Now if you want to perform an update obviously you need to refresh the repositories. Here is a function that should help you do that. OpenSUSE defaults to bash for the log-in shell so you can just add this to your /etc/bash.bashrc.local  note that  bashrc.local does not exist and needs to be created.



update () {
## Check if user is root, if not exit with an error.    
if (( EUID !=0 )); then
  echo 'Root privileges are required for refreshing system repositories.' 1>&2
  return 1

fi

## Create an array from the enabled repos by parsing zypper lr.    
enabled=()
while IFS="|" read -ra line; do
  [[ ${line[3]} = *Yes* ]] && enabled+=("${line[0]// /}")

done < <(zypper lr) 

## Refresh all enabled repos and update.   
zypper ref "${enabled[@]}" && zypper up
}

After you have save it you can source bashrc.local run:    source /etc/bash.bashrc.local      and then you can just run:    update 


One question might arise if you change you're log-in shell into something more advance. Don't worry you can just create a bash script and name it    update   (or whatever name you like) and modify that function like this.


#!/bin/bash

## Check if user is root, if not exit with an error.
if (( EUID !=0 )); then
  echo 'Root privileges are required for refreshing system repositories.' 1>&2
  exit 1
fi
 

## Create an array from the enabled repos by parsing zypper lr.
enabled=()
while IFS="|" read -ra line; do
  [[ ${line[3]} = *Yes* ]] && enabled+=("${line[0]// /}")

done < <(zypper lr)
 

## Refresh all enabled repos and update.  
zypper ref "${enabled[@]}" && zypper up


Put it in say   /usr/local/bin  or any place that you are comfortable with. Make it executable
  chmod +x update  Then you can just run   update

Happy updating!

Sunday, November 17, 2013

Vboxwebsrv with systemd on openSUSE

This works if you need to restart vboxwebsrv using systemd in openSUSE. Some folks  will raise some eye browse with this configuration for sure :-). The USER-NAME in the entry below is the username of the user who will access vboxwebsrv.



Create a unit file in /etc.

  •  /etc/systemd/system/VBoxWeb.service 

why etc? because according to the man pages somewhere that if a local admin will make a unit file it should be in /etc because the order of which the unit file to be executed. Meaning if you have conflicting unit files in /usr and in /etc then the latter will be prioritize. Note that packages (*.rpm) unit files are in /usr.


Put the entry below inside that unit file.


 [Unit]
 Description=VirtualBox Web Service
 After=network.target

 [Service]
 Type=forking
 PIDFile=/run/VBoxWeb/VBoxWeb.pid
 EnvironmentFile=/usr/lib/systemd/system/VBoxWeb.service
 ExecStartPre=/bin/bash -c 'if [[ -e $PIDFile ]]; then rm -f "$PIDFile"; fi'

 ExecStart=/usr/bin/vboxwebsrv --pidfile "$PIDFile" --background
 Restart=on-failure
 User=USER-NAME
 Group=vboxusers

 [Install]
 WantedBy=multi-user.target





 This is not a shell script! That is what systemd folks will say for sure ;-). The ExecStartPre in that unit file is removing (deleting) the pid file so when vboxwebsv should restart  you will not get any errors. The EnvironmentFile entry is like sourcing a shell script. In this case it is sourcing the unit file itself, hence the variable PIDFile. Note that with systemd 208 which is the default fro 13.1 the ExecPre line in that unit file is not required anymore, seems systemd is much smarter now a days! :-). 12.3 below you might still need it.


Create the temporary files and directories.

  •  echo "d /run/VBoxWeb 0755 USER-NAME vboxusers" > /etc/tmpfiles.d/VBoxWeb.conf 

  •  mkdir /run/VBoxWeb 


Change the permission.

  •  chown USER-NAME:vboxusers /run/VBoxWeb 

  •  chmod 755 /run/VBoxWeb 


Disable the vboxwebsrv service that came with VirtualBox package.

  •  chkconfig vboxweb-service off 

or

  •  systemctl disable vboxweb-service.service 


Start your newly created (unit file)  Daemon.

  •  systemctl start VBoxWeb.service 

Enable your newly created (unit file)  Daemon.

  •  systemctl enable VBoxWeb.service



This is very useful when you are using phpvirtualbox and you are restarting the vms every once in a while.


Cheers...

Thursday, October 10, 2013

VirtualBox Autosave Autostart of vms

This assumes that you are the only user on your system if not then you can try my Phpvirtualbox  guide. You do not need your favorite sudo utility nor running su just to set your vms to auto. Enable the systemd service one time and use VBoxManage to set your vms to auto.


 Download the script that will handle the vms.
  •  wget https://raw.github.com/Jetchisel/VBoxAutostart/master/systemd-vboxinit 
Copy it to your ~/bin directory.
  •   cp -v systemd-vboxinit ~/bin   
Make it executable.
  •  chmod ug+x ~/bin/systemd-vboxinit 

Change the group to vboxusers
  •  chgrp vboxusers ~/bin/systemd-vboxinit 


2. Download the unit file that will execute your script during boot/restart/shutdown of the host.
  •  wget https://raw.github.com/Jetchisel/VBoxAutostart/master/VBoxAutostart@.service 
Replace The ExecStart and ExecStop part with your "$HOME"/bin as the PATH
  •  cp -v VBoxAutostart@.service /usr/lib/systemd/system 
 Start that service.
  •  systemctl start VBoxAutostart@your-user-name.service 
Enable it .
  •  systemctl enable VBoxAutostart@your-user-name.service 
Check the status.
  •  systemctl status VBoxAutostart@your-user-name.service 
your-user-name is your user name not mine :-)

 3. Choose your vms that you want to autostart and autosave during boot/restart/shutdown of your host.

Get the names of the vms.
  •   VBoxManage list vms  
Set it to auto so the script will handle the autostart and autosave of the vm.
  •  VBoxManage setextradata YOUR-VM-NAME pvbx/startupMode auto 
Get the status.
  •   VBoxManage getextradata YOUR-VM-NAME pvbx/startupMode 

       Set it to manual if you dont want your vms to be handled by the script.
      •  VBoxManage setextradata YOUR-VM-NAME pvbx/startupMode manual 
      Set it to empty 'No value' the same thing it will be ignored by the script.
      •   VBoxManage setextradata YOUR-VM-NAME pvbx/startupMode 
        •   You can use the ExtraData script from the zip file below to manage your vms. 

          4. To access your vms.
          •  rdesktop localhost:1234 

          where 1234 is the port number which you can set via the gui or via VBoxManage.

          A gui app which you can use is krdc for Kde and   gnome-rdp for Gnome.

          The zip file from github. https://github.com/Jetchisel/VBoxAutostart/archive/master.zip

          I have package this stuff and it's in OBS now as an rpm. Look for systemd-vboxinit

           NOTE: if you have the Phpvirtualbox solution then you do not need this thus it can conflict with each other.