Showing posts with label rpm. Show all posts
Showing posts with label rpm. Show all posts

This Week I Learned - 2017 Week 14

Last week post or you can go through the whole series.

Proposal have been presented and submitted. Standard feedback received. Nevertheless, better than nothing regardless the quality of the reactions.

#1 GTCafe Studio. Stumbled upon this site while searching for different covers of Guthrie Govan's Emotive Ballad. It's rare these days to find any blog with original good content. Reading through his journal on learning guitar made me reflect back on my decision on donating all my guitars away few years back. Maybe is time to start all over again? Or maybe not? Learning to play an musical instrument is one of the way to escape from mind-numbing daily routines. However, there is a time and place for everything in life. In hindsight, sometimes you just have to move on.

#2 "CentOS is not stable, it is stale". So true that it hurts. For me, as a whole, Fedora provides a better desktop experience than Ubuntu. Yet, I still revert back to Ubuntu on my daily usage. Why? APT is definitely better than YUM and plenty of software selection. Furthermore, LXD works only in Ubuntu and not Fedora. And yes, finally Canonical realized that and declared Ubuntu Unity will be replaced by Gnome 18.04 LTS. Maybe this Ask HN post on feedback for Ubuntu 17.10 from the community have finally sealed the fate for Unity?

I always wonder what would happen if Red Hat decided to use build a distro based on Debian or DPKG package manager instead of creating their own RPM packaging manager? A unified GNU/Linux desktop will come sooner rather than unnecessary fragmentation and efforts. For example, the competition of next generation display server of Mir and Wayland. Yes, I know having options and competitions is good for progress. But the priority and effort should be on fixing the damn display drivers performance and stability issues. Fragmentation leads to duplication of works.

#3 Five great Perl programming techniques to make your life fun again. An old article, 11 years ago but everything described there is as relevant as today especially iteration using `map` and `grep` and Dispatch Table as illustrated in example below. As Perl does not have `switch` statement, hence using Dispatch Table is a good Perl design patternMark Jason Dominus, in his book, Higher-Order Perl also devoted a whole chapter (PDF) on this matter.
my $dispatch_for = {
   a => \&display_a,
   b => \&display_b,
   q => sub { ReadMode('normal'); exit(0) },
   DEFAULT => sub { print "That key does nothing\n"; },
};

my $func = $dispatch_for->{$char} || $dispatch_for->{DEFAULT};
$func->();

#4 Perl 5 Internals (PDF). Interesting reading on the intricacy part of the Perl itself. It was brought to my attention that Perl is a bytecode compiler, not an interpreter or a compiler.

#5 The 'g' key shortcuts in Vim. You will learn something new everyday, there are so many key bindings. Surprisingly, I only knew and regularly use two. Really needs to refresh and relearn this.

This Week I Learned - 2016 Week 11

Last week post or the whole series.

#1 Undoing a git rebase. I've made a mistake where you can 'fixup' a previous commit during rebasing. Instead of trying the fix it, might as well undo the rebasing through these two commands, provided you haven't done anything else before hand.
$ git reset --hard ORIG_HEAD
$ git rebase -i --abort

#2 NextBug, a bug recommender for Bugzilla based on the textual recommendation. Rare to find an interesting academic project which have immediate impact in the industry. This makes the developer aware the context of the issue being looked into. Video presentation of the tool as well as published papers here, here and here.

#3 Journal of Software Engineering Research and Development. Surprising find, especially this paper, Patch rejection in Firefox: negative reviews, backouts, and issue reopening. There seems to be a lot of interesting research done in field of Empirical Software Engineering (ESE). The most prolific group in the industry for this field most likely is the Microsoft ESE group.

#4 Open Source Society University. Does pursuing a typical degree in Computer Science compare to self-taught is a sensible choice these days? Not anymore but unfortunately, a degree is the minimum requirement if you need to work oversea and to get pass the Human Resource department.

#5 Pollen, a book publishing system written in Racket. Right, another publishing system in another exotic programming language. Why not? I've enough of Sphinx, anyway.

#6 Lumen, a PHP micro-framework based on Laravel. Yes, another PHP micro-frameworks.

#7 pkgr, create DEB or RPM package for Ruby, NodeJS, or Go application.

EPEL Yum Repository in CentOS

As Ansible, an automation tool, is not included to the default Yum repository in CentOS 6, you've to setup Extra Packages for Enterprise Linux (EPEL) Yum repository. I found this article on setting up EPEL repository and realize that I've been doing it the wrong way all this while. Instead of downloading the EPEL rpm package separately, we can install it directly as it's already located within the CentOS Extra Repository just by running the command below.
$ sudo yum install epel-release

Extra information on the epel-release package.
$ yum show epel-release
......
Installed Packages
Name        : epel-release
Arch        : noarch
Version     : 6
Release     : 8
Size        : 22 k
Repo        : installed
From repo   : extras
Summary     : Extra Packages for Enterprise Linux repository configuration
URL         : http://dl.fedoraproject.org/pub/epel/
License     : GPLv2
Description : This package contains the Extra Packages for Enterprise Linux (EPEL) repository
: GPG key as well as configuration for yum and up2date.

Listing the files within the epel-release package.
$ rpm -ql epel-release
/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
/etc/rpm/macros.ghc-srpm
/etc/yum.repos.d/epel-testing.repo
/etc/yum.repos.d/epel.repo
/usr/share/doc/epel-release-6
/usr/share/doc/epel-release-6/GPL

Getting the list of RPM packages from EPEL repository.
$ yum list | grep epel

Since this is third-party YUM repository, certain system administrator may prefer to disable it by default and only install certain package from it when necessary.
$ cat /etc/yum.repos.d/epel* | grep enabled
enabled=0
enabled=0
enabled=0
enabled=1
enabled=0
enabled=0
$ sed -i 's/enabled=1/enabled=0/g' /etc/yum.repos.d/epel*
$ cat /etc/yum.repos.d/epel* | grep enabled
enabled=0
enabled=0
enabled=0
enabled=0
enabled=0
enabled=0

If you've installed any packages from this Yum repository. You should clear all the downloaded cache RPM packages..
$ yum clean all

Unfortunately, to perform any yum commands against this repository, we've to explicitly state the repository for every command. Some examples.
$ yum search --enablerepo=epel ansible
$ yum list --enablerepo=epel | grep epel | grep ansible
$ yum install --enablerepo=epel ansible

Indeed a bit hassle to type all these commands. You can create an alias to reduce the needless typing.
$ alias yumepel="yum --enablerepo='epel'"
$ yumepel search ansible

Expanding RPM's Build-in Macro Values.

While looking into Drupal directory structures in Fedora, I stumbled upon this file, /usr/lib/rpm/macros.d/macros.drupal7, which seems to be the configuration file for RPM command.
$ cat /usr/lib/rpm/macros.d/macros.drupal7 
%drupal7            %{_datadir}/drupal7
%drupal7_modules    %{drupal7}/modules
%drupal7_themes     %{drupal7}/themes
%drupal7_libraries  %{_sysconfdir}/drupal7/all/libraries

# No-op macro to allow spec compatibility with RPM < 4.9 (no fileattrs)
%drupal7_find_provides_and_requires %{nil}

Let's try to expand the values of the above built-in RPM's macros.
$ cat /usr/lib/rpm/macros.d/macros.drupal7  | awk '{print $1}' | grep ^% | xargs -I % sh -c 'echo -en "%\t"; rpm --eval %' | column -t
%drupal7                             /usr/share/drupal7
%drupal7_modules                     /usr/share/drupal7/modules
%drupal7_themes                      /usr/share/drupal7/themes
%drupal7_libraries                   /etc/drupal7/all/libraries
%drupal7_find_provides_and_requires

Why not create a Bash function for the above command instead? Put this in your $HOME/.bashrc file.
# expanding the value of the rpm's built-in macros.
function rpm_macro() {
    if [[ -z "$1" ]]; then
        echo "No filename supplied"
    else
        cat $1 | awk '{print $1}' | grep ^% |\
        xargs -I % sh -c 'echo -en "%\t"; rpm --eval %' | column -t  
    fi  
}

Try out our newly created bash function.
$ rpm_macro macros.drupal7 
%drupal7                             /usr/share/drupal7
%drupal7_modules                     /usr/share/drupal7/modules
%drupal7_themes                      /usr/share/drupal7/themes
%drupal7_libraries                   /etc/drupal7/all/libraries
%drupal7_find_provides_and_requires

DNF Unofficially Replaced Yum In Fedora 22

As I was setting up my Fedora F22 (Rawhide) installation, I've noticed that the Yellowdog Updater, Modified (YUM), the default installer has been deprecated in favour of new Dandified Yum (DNF). As this email in the mailing list confirms my assumption before the release of Fedora 22 Beta in coming week. Example as shown below when I tried to install Google Chrome web browser.

Using the good old RPM Package Manager (RPM) where the installation failed due to failed dependencies.
$ sudo rpm -ivh google-chrome-stable_current_x86_64.rpm
[sudo] password for ang:
warning: google-chrome-stable_current_x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 7fac5991: NOKEY
error: Failed dependencies:
 lsb >= 4.0 is needed by google-chrome-stable-41.0.2272.118-1.x86_64
 libXss.so.1()(64bit) is needed by google-chrome-stable-41.0.2272.118-1.x86_64

Instead of searching for the package names of the dependencies, we can use the yum localinstall command to resolve that for us. Unfortunately, the yum command has been delegated to dnf where the localinstall command does not exists.
$ sudo yum localinstall google-chrome-stable_current_x86_64.rpm
Yum command has been deprecated, use dnf instead.
See 'man dnf' and 'man yum2dnf' for more information.
To transfer transaction metadata from yum to DNF, run 'dnf migrate'Redirecting to '/usr/bin/dnf localinstall google-chrome-stable_current_x86_64.rpm'

No such command: localinstall. Please use /usr/bin/dnf --help
It could be a DNF plugin command.

Hence, we use the dnf command directly. I'm still puzzle why we need 122 packages just to install Google Chrome. Most likely the dependencies of the LSB packages and all the Perl libraries.
$ sudo dnf install ./google-chrome-stable_current_x86_64.rpm

......
Transaction Summary
=================================================================================
Install  122 Packages

Total size: 66 M
Total download size: 21 M
Installed size: 245 M
Is this ok [y/N]:

I still prefer YUM over DNF due to my familiarity with YUM instead of DNF. However, both are still lacking behind the apt-get despite DNF trying its best to narrow the gap.

Oracle MySQL in Fedora Rawhide (F22)

Due to some constraint, I need to install Oracle MySQL community version in Fedora Rawhide (F22) instead of using the default MariaDB. Installation procedure through Yum repository as follows:

Download and install the Yum repository rpm. We will download the latest version available which is for F21. No worry, we will fix the release version not found issue later. Note only rpm command support installation directly through an URL instead of yum command.
$ sudo rpm -ivh http://dev.mysql.com/get/mysql-community-release-fc21-6.noarch.rpm
Retrieving http://dev.mysql.com/get/mysql-community-release-fc21-6.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-release-fc21-6   ################################# [100%]

To check that the MySQL Community repositories have been installed properly.
$ yum repolist | grep mysql
mysql-connectors-community/22/x86_64 MySQL Connectors Community             3
mysql-tools-community/22/x86_64      MySQL Tools Community                  1
mysql56-community/22/x86_64          MySQL 5.6 Community Server            32

Next, update our locate RPM database with newly installed MySQL repository package. Unfortunately, as I mentioned earlier, the repository does not contains packages for F22 release.
$ sudo yum update
Loaded plugins: aliases, fastestmirror, remove-with-leaves, yum-fast-downloader
http://repo.mysql.com/yum/mysql-connectors-community/fc/22/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
http://repo.mysql.com/yum/mysql-tools-community/fc/22/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
http://repo.mysql.com/yum/mysql-5.6-community/fc/22/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
Loading mirror speeds from cached hostfile
 * rpmfusion-free-rawhide: mirrors.tummy.com
 * rpmfusion-nonfree-rawhide: mirror.bjtu.edu.cn
No packages marked for update

If we look into the MySQL Community repository file, we can see that we need to change the $releasever variable.
$ cat /etc/yum.repos.d/mysql-community.repo | grep baseurl
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/fc/$releasever/$basearch/
baseurl=http://repo.mysql.com/yum/mysql-tools-community/fc/$releasever/$basearch/
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/fc/$releasever/$basearch/
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/fc/$releasever/$basearch/

Now, we're going to check the values of these yum variables as seen above using yum-debug-dump command.
$ sudo yum-debug-dump
Loaded plugins: fastestmirror, remove-with-leaves, yum-fast-downloader
Loading mirror speeds from cached hostfile
 * rpmfusion-free-rawhide: mirrors.tummy.com
 * rpmfusion-nonfree-rawhide: mirror.bjtu.edu.cn
Output written to: /tmp/yum_debug_dump-butterfly-2015-02-15_03:47:14.txt.gz

$ zcat /tmp/yum_debug_dump-W08LAP040-2015-02-15_03\:47\:14.txt.gz  | grep "YUM INFO" -A 3
%%%%YUM INFO
  arch: ia32e
  basearch: x86_64
  releasever: 22

Replace the $releasever manually with Fedora version F21 as it should let us install it without issues.
$ sudo sed -i 's/$releasever/21/g' mysql-community*
$ sudo cat mysql-community* | grep baseurl
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/fc/21/$basearch/
baseurl=http://repo.mysql.com/yum/mysql-tools-community/fc/21/$basearch/
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/fc/21/$basearch/
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/fc/21/$basearch/
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/fc/21/SRPMS
baseurl=http://repo.mysql.com/yum/mysql-tools-community/fc/21/SRPMS
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/fc/21/SRPMS
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/fc/21/SRPMS

Re-update all Yum repositories again.
$ sudo yum update
Loaded plugins: aliases, fastestmirror, remove-with-leaves, yum-fast-downloader
mysql-connectors-community                            | 2.5 kB  00:00:00     
mysql-tools-community                                 | 2.4 kB  00:00:00     
mysql56-community                                     | 2.5 kB  00:00:00     
Loading mirror speeds from cached hostfile
 * rpmfusion-free-rawhide: mirrors.tummy.com
 * rpmfusion-nonfree-rawhide: mirror.bjtu.edu.cn
No packages marked for update

Lastly, installation of both the MySQL Community client and server.
$ sudo yum install mysql-server mysql

Resetting GNU/Linux File or Folder Permissions

While setting the group file or folder permissions and ownership to /var/www, sometimes we may accidentally update the wrong folder, like to the parent folder of /var instead of /var/www.

In order to restore the default file or folders permissions in RPM-based system, there is a built-in option to revert the changes quickly compare to DEB-based system. Yup, this is probably one of the missing feature if we compare both packaging system.

First, let's find the RPM package name that contains the /var/www/html folder. Using the rpm command.
$ time rpm -qf /var/www/html
$ time rpm -qf /var/www/html
httpd-2.4.10-1.fc20.x86_64
real    0m0.025s
user    0m0.018s
sys     0m0.006s

Using the yum command which gave us four packages and took around 1-plus BLOODY minutes.
$ time yum whatprovides '/var/www/html'
real    1m23.865s
user    0m19.660s
sys     0m0.901s

Now that is something we can improve by using cached result through -C option. Let's try again. But then again, the results are still not entirely accurate.
$ time yum -C whatprovides '/var/www/html'
......
real    0m0.350s
user    0m0.257s
sys     0m0.050s

$ ls -ld /var/www/html/
drwxr-sr-x 1 root apache 40 Oct  4 15:05 /var/www/html/

Unfortunately, yum does not include support for reverting ownership and permissions of any installed files or folders. Reset the ownership.
$ sudo rpm --setugids httpd
$ ls -ld /var/www/html
drwxr-sr-x 1 root root 40 Oct  4 15:05 /var/www/html/

However, resetting the permissions does not seems to remove back the setguid flag. Weird. Unfortunately, I can't google for any good explanation of such problem.
$ sudo rpm --setugids httpd
$ ls -ld /var/www/html
drwxr-sr-x 1 root root 40 Oct  4 15:05 /var/www/html/

CentOS and Red Hat

Red Hat is probably the best and worse possible thing that can happen to CentOS, a community-based GNU/Linux distribution derived from it. The good part is you have the stability and good driver support since Red Hat is popular among the commercial world. The worst part is stability comes with a price. Getting latest greatest software updates (e.g. PHP or Subversion) is quite limited unless is a security fix. So you left with two choices, either you get the updates from third party repositories or you built from source code. Unfortunately, both ways have their own issues.

First, is always tricky to mix third party repositories and base repository. Certain common library packages maybe updated by third party repositories causing unnecessary breakage with existing software. Although Yum priority plugin and packages exclusion can solve that, it is still a hassle.

Second, installation by source code compilation. You can have all the customize options but with all the issues in former way as well. However, you can have the flexibility to isolate your installation into specific directory (/opt) with GNU Stow, a symlink farm manager. But you lost the ability to verify the integrity of your software binaries (check for tampering or planted Trojan) in case there is a security breach. To solve that, some may rebuild the software into RPM packages software from existing RPM's spec file which is what all the third party repositories are doing right now. In the end, you still back the problem of the first method.

How then ? Just migrate and move to a more bleeding edge distro like Ubuntu or Fedora.