1. 2017-07-19 - Remove multiple RPMs; Tags: Remove multiple RPMs

    Remove multiple RPMs

    A small recipe how to remove multiple applications with yum.

    Query against the package database with your search term

    tan@omega:~> rpm -qa | grep p2fear

    Use the output as input for yum

    tan@omega:~> sudo yum remove $(rpm -qa | grep p2fear) -y
  2. 2016-12-24 - Deploy rpm file to Artifactory with maven deploy:deploy-file; Tags: Deploy rpm file to Artifactory with maven deploy:deploy-file

    Deploy rpm file to Artifactory with maven deploy:deploy-file

    The maven deploy plugin allows to deploy artifacts and files to your internal repository. If you happen to have a Maven Repository like Sonatype Nexus or JFrog’s Artifactory the plugin is the right choice. This post covers how to deploy a rpm file to Artifactory. The Maven repository itself is not covered here.

    First you have to define in your maven project (pom.xml) the deploy-file goal. Replace the properties. Following example is for a rpm generated file with Apache Maven.

        <!-- deploy rpm to artifactory -->
                <!-- must match id of settings.xml of Jenkins -->

    Artifactory itself may have a snapshot and release repository, which is expressed through two maven profiles (test and prod).


    After the rpm is generated, deploy your rpm within the Jenkinsfile to production if you happen to be on the git master branch, otherwise put it the snapshot repository.

    stage('Build: artifactory') {
    	if (isMaster) {
    		sh "${mvnHome}/bin/mvn rpm:version deploy:deploy-file --activate-profiles prod -Dbuild.number=${BUILD_NUMBER}"
    	} else {
    		sh "${mvnHome}/bin/mvn rpm:version deploy:deploy-file --activate-profiles test -Dbuild.number=${BUILD_NUMBER}"
  3. 2016-12-22 - Add proxy for yum; Tags: Add proxy for yum

    Add proxy for yum

    If you are running a virtual machine for linux centos on your windows host and you have configured CNTLM, you can access in the virtual machine with yum the repository by adding this line in your /etc/yum.conf:

    echo "proxy=" >> /etc/yum.conf

    Add proxy_username and proxy_password if you need it.

    To access with rpm the internet like

    rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch

    put in /etc/environment

  4. 2016-12-22 - Import and remove gpg key with rpm; Tags: Import and remove gpg key with rpm

    Import and remove gpg key with rpm

    Got to check out Elasticsearch Curator. Elastic use the PGP key D88E42B4. Since working with rhel 7 I had to use rpm and yum for installing packages.

    Install or import the public key into the keyring:

    rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch

    After the Proof of Concept I perform a cleanup and remove the key.

    Query installed keys:

    root@omega:~# rpm -q gpg-pubkey

    The last key in the list is the imported one of elastic. Remove it with:

    rpm --erase --allmatches gpg-pubkey-d88e42b4-52371eca
  5. 2016-04-25 - Conditional check of installed rpm; Tags: Conditional check of installed rpm

    Conditional check of installed rpm

    I had to do some scripting. You can query the rpm database with a wildcard pattern. The output is stored in a variable FOUND.

    FOUND=$(rpm -qa *econn*)
    vinh@foha03:~> echo $FOUND

    To check is the search result is empty (-z) or not empty (-n):

    vinh@foha03:~> if [ -z "$FOUND" ]; then echo $FOUND; fi
    vinh@foha03:~> if [ -n "$FOUND" ]; then echo $FOUND; fi
  6. 2016-01-25 - Build a function for RPM cleanup; Tags: Build a function for RPM cleanup

    Build a function for RPM cleanup

    Sometimes the rpmdb checksum is invalid. To fix that I have created a simple function in bash script that reads the input from stdin. If yes in any kind or y ignore case is entered, the rpmdb will be rebuild and we clean the local yum cache.

    See also Red Hat Enterprise Linux - Working with yum cache.

    read -r -p "Are you sure? [y/N] " response if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]] then
      if [ -f /var/lib/rpm/.rpm.lock ]
          echo ".. RPM operation in progress. Try later. Abort cleanup."
          echo ".. rebuild RPM database"
          rpm --rebuilddb
          echo ".. clean local yum rpmdb cache"
          yum clean rpmdb
  7. 2015-11-14 - Remove installed rpm forcefully; Tags: Remove installed rpm forcefully

    Remove installed rpm forcefully

    If you create your own rpm, you may make mistakes in the scrips of pre and post installation and removal. Especially removing an rpm with a wrong pre-uninstall script is not possible, e.g removing a folder that doesn’t exists. For that case you can erase the rpm with the --noscripts option.

    rpm -e --noscripts my-rpm-1.0.0-85.noarch

    After that clean up manually.

  8. 2015-11-12 - Use whiptail in interactive shell scripts; Tags: Use whiptail in interactive shell scripts

    Use whiptail in interactive shell scripts

    Whiptail is a program that allows shell scripts to display dialog boxes to the user for informational purposes, or to get input from the user in a friendly way. It is included in several linux distributions like Debian or rhel.

    Following script demonstrates a shell script skeleton for a rpm cleanup script. Whiptail is only displayed in interactive mode (run the script with bash -i).

      RPM=`which rpm`
      if [ "$RPM"="" ]; then
        echo "no rpm installed"
        echo "do cleanup"
        $RPM --rebuildb
    if [[ "$-" == *i* ]]; then
      if whiptail --title "Cleanup RPM" --yesno "Are you sure?" 10 40 ;then
        echo "Cleanup aborted"
      echo "do something old school"
  9. 2015-11-04 - Extract file contents of rpm archive; Tags: Extract file contents of rpm archive

    Extract file contents of rpm archive

    This post demonstrates how to extract the file contents of an rpm package, for e.g. analyzing the rpm packaging.

    We need two commands for that:

    • rpm2cpio - Extract cpio archive from RPM Package Manager (RPM) package.
    • cpio - copy files to and from archives

    To extract in current directory

    rpm2cpio appl-1.0.0.noarch.rpm | cpio -idmv

    cpio options explained:

    • -i extract
    • -d make-directories
    • -m preserve-modification-time
    • -v verbose :-)
  10. 2015-10-08 - Check optional scripts in rpm file; Tags: Check optional scripts in rpm file

    Check optional scripts in rpm file

    RPM allows optional scripts to be executed within the install and remove operation.

    This involves the events

    • pre-install
    • post-install
    • pre-uninstall
    • post-uninstall

    To check the script contents:

    rpm -qlp test.x86.rpm --scripts > scripts.out
    # to search for foo in scripts
    grep "foo" scripts.out

    The options are:

    • {-q | --query}
    • {-l | --list} = query option, list files in package
    • {-p | --package} URLFILE = query option, query an (uninstalled) package URLFILE.
    • --scripts = query option, list the package specific scriptlet(s) that are used as part of the installation and uninstallation processes.
  11. 2015-10-07 - Correct Rpmdb; Tags: Correct Rpmdb

    Correct Rpmdb

    Seeing this Rpmdb checksum is invalid: dCDPT(pkg checksums) in RedHat or CentOS?

    These commands can help you fix the problem:

    # needs root permission
    rpm --rebuilddb
    # clean cache
    yum clean all