Thursday, March 5, 2020

Swapping CapsLock to Esc key in openSUSE 15.+

Being a vim user I have adopted my keyboard to swap the caps key from the esc key. In openSUSE the file /etc/vconsole.conf needs to be edited in order to make the changes permanent.

1.  First thing we need to do is create a new directory somewhere in /usr

  mkdir -p /usr/local/share/kbd/keymaps/ 

2.  Next change directory to the newly created directory.

  cd /usr/local/share/kbd/keymaps/  

3.  Next copy the keyboard layout/setup that you're using from /usr/share/kbd/keymaps/xkbd.

  cp -v /usr/share/kbd/keymaps/xkb/us.map.gz /usr/local/share/kbd/keymaps/  

5.   ls 

You should see the output.

  us.map.gz  

6. unzip it.

  gunzip us.map.gz  

7. Check the default value of the keycodes for Escape and Caps_Lock.

  grep -noE '^keycode[[:space:]]*(1|58)[[:space:]]*=[[:space:]][^ ]*' us.map  

   The output should be like this.

  2:keycode 1 = Escape  
  59:keycode 58 = CtrlL_Lock 


8. Change value of key code 1 to 58 and 58 to 1.

printf '%s\n' '/^\(keycode[[:space:]]*\)1\([[:space:]]*=.*$\)/s//\158\2/' \
'/^\(keycode[[:space:]]*\)58\([[:space:]]*=.*$\)/s//\11\2/' ,p Q | ed -s us.map \ 
| grep -noE '^keycode[[:space:]]*(1|58)[[:space:]]*=[[:space:]][^ ]*'

Should print the output below, since that ed code does not edit the file in-place but just prints the output to stdout.

  2:keycode 58 = Escape  
  59:keycode 1 = CtrlL_Lock  


To actually edit the file you have two options using ed.

Using printf with ed.

 printf '%s\n' '/^\(keycode[[:space:]]*\)1\([[:space:]]*=.*$\)/s//\158\2/' \
'/^\(keycode[[:space:]]*\)58\([[:space:]]*=.*$\)/s//\11\2/' w | ed -s us.map

Using a  heredoc with ed.

ed -s us.map << 'EOF'  
/^\(keycode[[:space:]]*\)1\([[:space:]]*=.*$\)/s//\158\2/
/^\(keycode[[:space:]]*\)58\([[:space:]]*=.*$\)/s//\11\2/
w
q
EOF

9. Check the new value the keycodes Escape and Caps_Lock

   grep -noE '^keycode[[:space:]]*(1|58)[[:space:]]*=[[:space:]][^ ]*' us.map  

 The output should be like this.

  2:keycode 58 = Escape  
  59:keycode 1 = CtrlL_Lock 


10. Save it to /usr/local/share/kbd/keymaps/personal.map

  mv -v us.map personal.map  

11. To load during the session

  loadkeys /usr/local/share/kbd/keymaps/personal.map 

12. To make permanent In order to load the keymap at boot, specify the full path to the file in the KEYMAP variable in /etc/vconsole.conf. The file does not have to be gzipped as the official keymaps provided by kbd.

   Check the value of /etc/vconsole.conf

  cat /etc/vconsole.conf 

You should see what is the default setup in that config file.

13 .Back up first vconsole.conf before editing that file.

  cp -v /etc/vconsole.conf /etc/vconsole.conf.original  

14. Replace the value of KEYMAP to the absolute path of the new key mappings.

  printf '%s\n' '/^\(KEYMAP\).*/s//\1=\/usr\/local\/share\/kbd\/keymaps\/personal.map/' w | ed -s /etc/vconsole.conf  

15. Check the value of the newly edited /etc/vconsole.conf file.

  cat /etc/vconsole.conf  



Sunday, July 22, 2018

Keeping the Bash shell history

There are a lot howto's and instructions about keeping the shell's history but my favorite is my own fork of dhist.sh which is sdb. Now you're probably asking as to why would anyone wants to keep the history of all the commands you have written during the interactive shell? Well for starters you can check which commands did you executed during the last week on which directory or the exit status of that command. or you want to check for the commands that has a word  foo  somewhere in there or you remember a very cool command that has a lot of combinations of pipes, subshell, redirections and so on, that you have had executed but forgot the exact syntax.



 The history is kept in a file called .bash_history inside your $HOME directory. A normal text file has its limitations because of the file size. Imagine even if you manage to save all the history in one file then that file could get bigger and bigger depending on how much data in contains.

In openSUSE Leap 15.0 syslog can be used to log bash history according to this
site which actually works as expected/advertised, unfortunately sdb can't be used 
in parallel with that set up. Just don't edit the /etc/bash.bashrc file instead create a
new file named /etc/bash.bashrc.local .

Any how sdb saves the history in a sqlite3 database, why sqlite? because it has no server client authentication. If you have read and write to the database file then you can use that database there is no admin privilege involve. Quoting what google has to say about sqlite

Unlike other databases (like SQL Server and MySQL) SQLite does not support stored procedures. SQLite is file-based, unlike other databases, like SQL Server and MySQL which are server-based. SQL is a Structured Query Language used to query a Database usually Relational Database Systems.

Sqlite is being used by some of the popular web browsers like firefox and most modern smart phone also like Android. Yes there is always a risk of sql-injection  which can either collect user info or destroy the database and worsts it can blocked everybody in the entire system but since sqlite is only a file based then the risk is minimal. No authentication on the server, client side needed. The worst that could happen is you lose your history table from the database. At the point the "Always keep a backup" comes in.

For those of you who does not know how to use vim  you should at least know howto exit or quit vim without editing a file. Since vim is the default  value of the environment variable EDITOR if it is empty. Press the escape key and then key in the colon and the q key followed by an exclamation key.

   <esc>:q!   

Create a cron job to automatically save the database at some safe place. An example on howto do it in openSUSE every hour.

   0 * * * * /usr/bin/sqlite3 database ".backup /path/to/new/safe/location/database"   

Give the absolute path of the sqlite3 executable and replace the database with the correct name and path and the path to the new database  file. Note that the database will be over ridden every hour so it is wise to create a script and just use cron to execute it

Now lets see how we can use sdb in the interactive shell.

Let's say you want to look for commands in the current session e.g. currently open terminal
that you're using. Type

  sdb   

If you just open a new terminal then the only thing you will see are the headers. Which
looks like this (with the -c option).

+-------------+-----------+--------------------+----------------------+-------------+-----------+-----------------+------------------+
 |     ID         |  COUNT |    DATE/TIME   |    USER@HOST   | STATUS   |    TTY     | DIRECTORY |▶ COMMAND |
+-------------+-----------+--------------------+----------------------+-------------+-----------+-----------------+------------------+

Now if you want to see the other shell sessions and current ones. e.g. if there are other terminals that are open and you or others that is using sdb. Use the -a option, which defaults to 100 lines only.

   sdb -a   

If you want to see all the commands starting from the very beginning add the -m option and use the + sign to specify the maximum value instead of typing 999999999999999999 for the value of -m. Yes they are 18 9's!

  sdb -am+  

Change the + sign into some number/digit to specify how much lines you want.

If you want to see the directory, exit status, user and host, then add the -c option.

   sdb -cam+  

The -u, -h, -l and -d can be specified for specific query as well.

If you want to see sqlite commands that has been executed then add the -v option.

   sdb -vcam+   

To check for commands that starts with zypper use the -b option

   sdb -vcam+ -b zypper   

To check the commands that starts with zypper and ends with bash add the -e option.

   sdb -vcam+ -b zypper -e bash  

On the other hand the -w option can do that also

    sdb -vcam+ -w 'zypper%bash'   

The % is like the glob in the shell which is * , but the % is for sqlite.

To check for commands that was executed from 10 days ago and now.

   sdb -cam+ -t '-10 days, now'   

To check the commands that was executed in the directory /foo and all the directory under it
recursive search.

    sdb -vcam+ -r /foo   

It is also possible to re execute the commands that you can find in the query by providing
the ID of the command. Run command with the id 100

  sdb -E 100  

Now some example of long combination of options.

    sdb -am+ -n0 -w 'zypper%bash' -u jetchisel -h leap150 -r "$HOME" -t '-1 year, -2 days'    


The -a for all commands from the other sessions and current ones. (100 lines only.)
The -m+ for all the commands from the beginning.
 First the  -n option with the zero argument checks for the commands that exited with a zero status.
The -w for commands that starts with zypper and ends with bash.
The -u for the username of the user
The -h for the hostname  of the computer.
The -r for a recursive search for commands on and under the directory "$HOME"
The -t is for searching commands starting from last year until 2 days ago.

Enjoy folks....

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.

          Monday, September 23, 2013

          PhpSysInfo

          Download the latest release in  http://sourceforge.net/projects/phpsysinfo/files/latest/download 


          Unpack that tar ball. I choose to install in /data/apache2.
          •  tar -zxvf phpsysinfo-"$version"-tar.gz -c /data/apache2
          Set up sysinfo.
          •  cd /data/apache2/phpsysinfo-"$version" 
          •  cp -v phpsysinfo.ini.new phpsysinfo.ini 
          Set permission.
          •  chown -Rv wwwrun:www /data/apache2/phpsysinfo-"$version" 

          Add an entry to apache2 config
          •  vi /etc/apache2/conf.d/phpSysInfo.conf 

          Add the entry below

            
            Alias /sysinfo /data/apache2/phpsysinfo-"$version"

            <Directory /data/apache2/phpsysinfo-"$version">
               Options Indexes MultiViews FollowSymLinks
               Order allow,deny
               Allow from all
            </Directory>

           

          Again the only thing to adjust to your set up is /data/apache2.

          Restart apache2
          •  systemctl restart apache2.service 


          Type the url on your browser
          •  localhost/sysinfo 






















          Thursday, September 19, 2013

          phpVirtualBox on openSUSE reloaded


          phpVirtualBox home page has been moved from google to sourceforge it is in http://sourceforge.net/projects/phpvirtualbox/files/latest/download.  You will need to install VirtualBox since it is just a front end.  before you can use this app. Refer to my guide on how you can install vbox.  After you have installed vbox you will install a web server. We will use apache2 as an example. You can either use yast2 software management to install the lamp_server pattern and some php packages or use our friend zypper.

            In this setup i choose to install to a different directory than /srv/www/htdocs. So just in case something unrecoverable happens :P in my system i will not delete the directory where phpvirtuablox resides. Here i choose /data/apache2. You can put it any where you like just replace the config entry in apache2.

            To install the packages using zypper
              •     zypper in patterns-openSUSE-lamp_server php5-soap      

                 Create an entry for apache2
                  •     vi /etc/apache2/conf.d/phpvirtualbox.conf   

                  The only thing you need to replace to meet your setup is    /data/apache2  the rest is as-is.


                    Alias /phpvirtualbox  /data/apache2/phpvirtualbox

                    <Directory   /data/apache2/phpvirtualbox>
                       Options Indexes MultiViews FollowSymLinks
                       AllowOverride All
                       Order allow,deny
                       Allow from all
                    </Directory>



                     Unpack that zip file using unzip into /data/apache2.
                      •   unzip phpvirtualbox-"$version".zip -d /data/apache2/ && cd /data/apache2 
                        Rename that file to just phpvirtualbox
                          •   mv -v phpvirtualbox-"$version" phpvirtualbox && cd phpvirtualbox 

                            Now rename the php file
                              •  mv config.php-example config.php 

                                Edit that config.php file and put the name of the user which uses virtualbox and the corresponding line and do it like this.
                                     
                                    
                                    var $username = 'jetchisel';                                  
                                    var $password = 'mypassword';


                                  •   var $ location = 'http://127.0.0.1:18083';  

                                  •  var $consoleHost = 'IP ADDRESS OF YOUR COMPUTER'; 

                                  Create an file called virtualbox in /etc/default and put something like this.


                                    VBOXWEB_USER=jetchisel



                                  Set permissions as root run the following commands.

                                    •   chgrp -Rv vboxusers /data/apache2/phpvirtualbox  
                                    •   chmod -Rv 775 /data/apache2/phpvirtualbox   

                                       Edit that config.php file, un comment out the following.

                                          
                                          var $startStopConfig = true;
                                          
                                          var $enableAdvancedConfig = true;
                                                                         



                                        For the deprecated system V.
                                           Download the vboxinit for SuSE.
                                            •  wget https://raw.github.com/Jetchisel/vboxinit/master/sysV-vboxinit -O vboxinit 
                                              copy the script to /etc/init.d
                                                •  cp -v vboxinit /etc/init.d/vboxinit 
                                                  set permission.
                                                    •  chmod u+rx /etc/init.d/vboxinit  
                                                      Enable init script.
                                                        •  chkconfig vboxinit on  
                                                             Check the script if it is working
                                                                  •  /etc/init.d/vboxinit {start|stop|restart|status} 

                                                                  Enable the init scripts at boot time.

                                                                      •   chkconfig vboxweb-service on 

                                                                      Restart the init scripts as root run the following.
                                                                      •  service vboxautostart-service restart 
                                                                      •  service vboxweb-service restart 

                                                                      For SYSTEMD

                                                                       Download the systemd version  for SuSE.
                                                                      •  wget https://raw.github.com/Jetchisel/systemd-vboxinit/master/systemd-vboxinit 
                                                                      You can save it to any place you want even in /home/user/bin. In this example i choose to put in  to /usr/lib/systemd/
                                                                      •  cp -v systemd-vboxinit /usr/lib/systemd 
                                                                      Set permissions
                                                                      •  chmod ug+x /usr/lib/systemd/systemd-vboxinit 
                                                                      •  chgrp vboxusers /usr/lib/systemd/systemd-vboxinit


                                                                      Create a systemd unit  "vboxvmservice.service" (or any name that suits you)
                                                                      inside /usr/lib/systemd/system and add the entry below: Replace " username " with the user that belongs to the vboxusers group.

                                                                        

                                                                             [Unit]
                                                                             Description=VBox Virtual Machine  Service
                                                                             Requires=systemd-modules-load.service
                                                                             After=systemd-modules-load.service
                                                                             Before=shutdown.target reboot.target halt.target     


                                                                             [Service]
                                                                             Type=oneshot
                                                                             User=username
                                                                             Group=vboxusers

                                                                             KillMode=none
                                                                             StandardOutput=syslog+console
                                                                             EnvironmentFile=/etc/default/virtualbox
                                                                             ExecStart=/usr/lib/systemd/systemd-vboxinit start
                                                                             ExecStop=/usr/lib/systemd/systemd-vboxinit stop
                                                                             RemainAfterExit=yes

                                                                             [Install]
                                                                             WantedBy=multi-user.target


                                                                                                 

                                                                      If you choose to save the systemd-vboxinit script in another path and not /usr/lib/systemd then you need to adjust the following entry.

                                                                      •  ExecStart=/path/to/file/systemd-vboxinit start
                                                                      •  ExecStop=/paht/to/file/systemd-vboxinit stop 

                                                                      Start that newly created unit.
                                                                      •   systemctl start vboxvmservice.service 
                                                                      Enable the service at boot time.
                                                                      •  systemctl enable vboxvmservice.service 

                                                                      Enable the init scripts;

                                                                        •  systemctl enable vboxweb-service.service 

                                                                        Start and enable apache2.
                                                                        •   systemctl start apache2.service 
                                                                        •  systemctl enable apache2.service 

                                                                        In your browser type the url below:
                                                                        •   localhost/phpvirtualbox  

                                                                        First log in:
                                                                        •  username: admin 
                                                                        •  password: admin  























                                                                        After a log in you can add a user that can handle your vms.





























                                                                        Configure vms in phpvirtualbox's graphical menu.
                                                                        •  Settings --> General --> Basic --> "StartupMode --> Automatic" 























                                                                         An example of running vms at boot.





















                                                                        Checking the status of your unit after booting.






                                                                        Zip file from github:  https://github.com/Jetchisel/systemd-vboxinit/archive/master.zip

                                                                        You can search phpvirtualbox for an rpm package of this in OBS.

                                                                        Kudos to Mr. Ian Moore the author of phpvirtuabox.

                                                                        
                                                                        

                                                                        Sunday, August 25, 2013

                                                                        OpenSuSE on usb grub2

                                                                        Since 12.2 release opensuse has grub2 as an option to use. Come 12.3 it is the default grub in the installation but you can always choose to use the old legacy grub. As of this time of my blog entry Aug 2013, grub2 is still in development but usable (so they say :P ).

                                                                        Then if your using the old legacy grub  suse has some options to edit the necessary entry in order to boot your system when it has some boot issues.
                                                                        Sadly if you use grub2 then it is only limited to the following:







































                                                                        As you can see theres a lot of missing files to be edited unlike old legacy grub.
                                                                        Well some files were either renamed or removed completely. Grub2 has the following (but not limited to)  files:

                                                                        1. /boot/grub2/.device.map
                                                                        2. /etc/default/grub
                                                                        3. /boot/grub2/grub.cfg
                                                                        4. /etc/grub.d/

                                                                         If your going to do a usb install  then you should not follow the suggested partitioning from the installer since i may offer to use the existing internal partitions or worst suggest to delete it completely. Untick the "proposed separate home partition". Choose create partition setup and check your other partitions if they are mounted automagically by the installer if it is indeed mounted then umount it. The partitioning i suggest is to make the first part the root and if you really need a separate /home then put it in the second partition. A swap partition will be the last. Other wise you will be thrown at the grub prompt during the first reboot ;-(.



                                                                        You will probablly will encounter some errors similar to  this.









                                                                        This is to be expected, dont worry you can just copy the error somewhere.

                                                                        Let it reboot after the installation and boot again from the dvd and choose installation in the menu. 




































































































































































































                                                                        Once booted to your system you can  do the following commands.

                                                                        echo '(hd0)  /dev/disk/by-id/ata.....' > /boot/grub2/device.map

                                                                        Make sure you got the correct id of you disk.
                                                                        ----

                                                                          grub2-install --force /dev/sda1  

                                                                        /dev/sda1 is my root partition so point it to yours.

                                                                        Yo will get a WARNING but the important message is the last.







                                                                        ----


                                                                            grub2-mkconfig -o /boot/grub2/grub.cfg     

                                                                        ----
                                                                            /sbin/mkinitrd/     


                                                                        Now if you will not see any errors from the last command then it is safe to reboot.

                                                                        This hack is also true if you cloned your disk. This does not apply to efi system since i do not have any close encounter with EFI (at least not yet :P )

                                                                        Enjoy folks!

                                                                        Tuesday, April 17, 2012

                                                                        Things you can do with packages based on time.

                                                                        RPM keeps a history of installed things. In opensuse there is also a var log zypp history.  Here is an example of checking packages based on time.

                                                                            rpm -qa --qf '(%{INSTALLTIME:date})%{NAME}\n'

                                                                        Will yield something like this:


                                                                         (Mon 20 Feb  2012  01:45:49  PM   UTC) libSDL-devel
                                                                         (Wed 30 Nov 2011  06:24:38  PM   UTC) kdebase4-workspace-liboxygenstyle
                                                                         (Sat   14 Apr  2012  07:27:40  AM   UTC) ffmpegthumbnailer
                                                                         (Wed 30 Nov 2011  06:19:28   PM  UTC) ptools
                                                                         (Thu  05 Jan   2012  07:41:54  AM   UTC) NetworkManager
                                                                         (Fri    11 Nov  2011  12:17:16  AM   UTC) xorg-x11-driver-video
                                                                         (Wed 01 Feb   2012  01:32:00  AM  UTC) libmysqlclient_r18
                                                                         (Wed 30 Nov  2011  09:22:45  PM   UTC) libwpg-0_2-2
                                                                         (Wed 30 Nov  2011  06:21:22  PM   UTC) gegl-0_1
                                                                         (Sun  01 Apr   2012  08:00:55  PM  UTC) glibc-locale-32bit


                                                                        Ckecking /var/log/zypp/history

                                                                          while  IFS=\| read -ra line; do [[ $line = \#* ]] && continue; echo "${line[0]} -> ${line[2]}"; done < /var/log/zypp/history  

                                                                        Or if you change your shell to something more advance :-), you can use awk.

                                                                         awk -F '|' '/^#/ {next} {printf("%s -> %s\n", $1, $3)}' /var/log/zypp/history 

                                                                        Will yield something like this:


                                                                         2012-04-16 06:41:57 -> libquicktime0
                                                                         2012-04-16 06:42:23 -> avidemux
                                                                         2012-04-16 06:42:26 -> libswscale0
                                                                         2012-04-16 06:42:28 -> libpostproc50
                                                                         2012-04-16 06:42:41 -> libavcodec52
                                                                         2012-04-16 06:42:49 -> smplayer
                                                                         2012-04-16 06:42:54 -> gmplayer
                                                                         2012-04-16 06:43:02 -> mlt
                                                                         2012-04-16 06:43:40 -> kino
                                                                         2012-04-16 06:43:44 -> libavformat52
                                                                         2012-04-16 06:43:57 -> smplayer-themes
                                                                         2012-04-16 06:44:15 -> kdenlive
                                                                         2012-04-16 06:44:18 -> libavfilter1


                                                                        If you want to know when a specific package was installed or updated you can just filter out the correct package name as shown on  below.

                                                                         rpm -qa --qf '(%{INSTALLTIME:date}) %{NAME}\n'  '*packagename*' 

                                                                        Using awk to print out a certain field but in this example we just print out the whole line.

                                                                          awk '/packagename/{print $0}'  < <(rpm -qa --qf '(%{INSTALLTIME:date}) %{NAME}\n') 

                                                                        Replace packagename with the correct one and you should be fine. That  looks good, now we want to take action about the packages that is based on a certain time/date. First we need to sanitize the packages names, meaning we only need to extract the names and not the date so we can take action (eg pass the output to zypper). Let us go back to the first example using rpm to query packages. IMHO a better tool for extracting only the names is awk. Here is an example.


                                                                         rpm -qa --qf '(%{INSTALLTIME:date}) %{NAME}\n' |  awk '/Sun 01 Apr 2012/{print $NF}'  


                                                                         will yield something like this:


                                                                         wavpack
                                                                         glibc-locale
                                                                         glibc-info
                                                                         libmp3lame0
                                                                         aircrack-ng
                                                                         vlc-qt
                                                                         glibc-32bit
                                                                         ladspa-lemux
                                                                         libmad0
                                                                         2ManDVD
                                                                         glibc-i18ndata
                                                                         glibc
                                                                         libfaac0
                                                                         faac
                                                                         twolame
                                                                         vlc
                                                                         glibc-devel
                                                                         liba52-0
                                                                         libzen0
                                                                         libxvidcore4
                                                                         xvidcore
                                                                         libvlc5



                                                                        The awk code above looks for lines with the date 'Sun 01 Apr 2012' on it and then prints the last field so the result is just the package names that we are after. You can test the output without printing the last field by removing the last part of the code, then the awk code will be like   awk '/Sun 01 Apr 2012/' . You can even add the specific time (hours minutes and seconds) so you can have more control on the search, just add the end of the date of your awk code before the last /. After that you need  to pass it to zypper, fortunately bash4 has a builtin feature called mapfile aka readarray. This is an example of using mapfile for that, run this code as a normal user like the rest of the previous code.


                                                                            mapfile -t < <(rpm -qa --qf '(%{INSTALLTIME:date}) %{NAME}\n' | awk '/Sun 01 Apr 2012/{print $NF}')

                                                                          echo zypper rm "${MAPFILE[@]}"


                                                                        You will see the out put of what zypper will remove from your installed packages. If you are satisfied with zypper's proposal then you can run that above code; again as root without the 'echo'  so that zypper can remove the packages. Remember that mapfile is a bash4 feature if your bash is lower than bash4 you can use read and IFS.



                                                                          IFS=$'\n' read -rd '' -a files < <(rpm -qa --qf '(%{INSTALLTIME:date}) %{NAME}\n' | awk '/Sun 01 Apr 2012/{print $NF}')

                                                                          echo zypper rm "${files[@]}"



                                                                          For those of you who change the default shell to something more advance :-). Try
                                                                         creating a script with a shebang  #!/bin/bash  and put the out put of the code:

                                                                           rpm -qa --qf '(%{INSTALLTIME:date}) %{NAME}\n' | awk '/Sun 01 Apr 2012/{print$NF}' ORS=" " > myscript


                                                                        Now open that myscript with your favorite text editor and add the shebang then prefend   zypper rm   and a literal white space before the first package name then make it executable and  finally execute it.

                                                                        I have done this only in a vm just for a proof of concept and it works as expected. I have never been in a situation where i am forced to do such hacks in my production system. For those of you who are adventurous enough to try tumbleweed release then this might be the solution if you ever get into desperate situations that needs desperate measures to solve  it :-).


                                                                        Take it easy!