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

    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
    p2fear_remote_1-4.18.5-695.noarch
    p2fear_online_register_1-4.18.5-1933.noarch
    p2fear_mocks_1-4.18.5-1789.noarch
    p2fear_online_type_a_1-4.18.5-1975.noarch
    p2fear_healthcheck-4.18.5-414.noarch
    p2fear_online_type_c_1-4.18.5-1947.noarch
    p2fear_batch_1-4.18.5-765.noarch
    

    Use the output as input for yum

    tan@omega:~> sudo yum remove $(rpm -qa | grep p2fear) -y
    
    rpm
  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
    Loading...

    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.

    <build>
    <plugins>
        <!-- deploy rpm to artifactory -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.8.2</version>
            <goals>
                <goal>deploy-file</goal>
            </goals>
            <configuration>
                <!-- must match id of settings.xml of Jenkins -->
                <repositoryId>artifactory</repositoryId>
                <url>${deployment.repository.url}</url>
                <artifactId>${project.artifactId}</artifactId>
                <groupId>${project.groupId}</groupId>
                <version>${rpm.version}-${rpm.release}.noarch</version>
                <file>${rpm.copy.to.location}</file>
            </configuration>
        </plugin>
    </plugins>
    </build>
    

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

    <profiles>
        <profile>
            <id>test</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <deployment.repository.url>https://artifactory.cinhtau.net/artifactory/yum-snapshot-local
                </deployment.repository.url>
            </properties>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <deployment.repository.url>https://artifactory.cinhtau.net/artifactory/yum-release-local
                </deployment.repository.url>
            </properties>
        </profile>
    </profiles>
    

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

    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=http://10.0.2.2:3128" >> /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

    http_proxy="http://10.0.2.2:3128"
    https_proxy="https://10.0.2.2:3128"
    
  4. 2016-12-22 - Import and remove gpg key with rpm; Tags: Import and remove gpg key with rpm
    Loading...

    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
    gpg-pubkey-fd431d51-4ae0493b
    gpg-pubkey-352c64e5-52ae6884
    gpg-pubkey-5ce2d476-50be41ba
    gpg-pubkey-2fa658e0-45700c69
    gpg-pubkey-b1275ea3-546d1808
    gpg-pubkey-bfdbb0c6-54c7ee8b
    gpg-pubkey-de57bfbe-53a9be98
    gpg-pubkey-d88e42b4-52371eca
    

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

    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
    fo-econn-dev-3.2.7-364.noarch
    

    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
    fo-econn-dev-3.2.7-364.noarch
    
  6. 2016-01-25 - Build a function for RPM cleanup; Tags: Build a function for RPM cleanup
    Loading...

    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 ]
        then
          echo ".. RPM operation in progress. Try later. Abort cleanup."
      else
          echo ".. rebuild RPM database"
          rpm --rebuilddb
          echo ".. clean local yum rpmdb cache"
          yum clean rpmdb
      fi
    fi
    ;;
    
    rpm
  7. 2015-11-14 - Remove installed rpm forcefully; Tags: Remove installed rpm forcefully
    Loading...

    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.

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

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

    #!/bin/bash
    do_rpm_cleanup(){
      RPM=`which rpm`
      if [ "$RPM"="" ]; then
        echo "no rpm installed"
      else
        echo "do cleanup"
        $RPM --rebuildb
      fi
    }
    if [[ "$-" == *i* ]]; then
      if whiptail --title "Cleanup RPM" --yesno "Are you sure?" 10 40 ;then
        do_rpm_cleanup
      else
        echo "Cleanup aborted"
      fi
    else
      echo "do something old school"
      do_rpm_cleanup
    fi
    
  9. 2015-11-04 - Extract file contents of rpm archive; Tags: Extract file contents of rpm archive
    Loading...

    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 :-)
    rpm
  10. 2015-10-08 - Check optional scripts in rpm file; Tags: Check optional scripts in rpm file
    Loading...

    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.
    rpm
  11. 2015-10-07 - Correct Rpmdb; Tags: Correct Rpmdb
    Loading...

    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
    
    rpm