Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change install script from Redhat to Ubuntu

An install script (for Microsoft® SQL Server® ODBC Driver 1.0 for Linux) has been written for Redhat with RPM

It uses this code to check if certain packages are installed

req_libs=( glibc e2fsprogs krb5-libs openssl )

for lib in ${req_libs[@]}
do
    local present=$(rpm -q -a $lib) >> $log_file 2>&1
    if [ "$present" == "" ]; then
        log "The $lib library was not found installed in the RPM database."
        log "See README for which libraries are required for the $driver_name."
        return 1;
    fi
done

I have overcome this problem by knowing/trusting that the libraries are installed and simply removing the test, but I'd like to tidy this up now.

  1. How can I find which libraries to look for on Ubuntu. Is there a command or translation webpage for Redhat -> Ubuntu
  2. Is replacing rpm -q -a with dpkg -s correct?
like image 366
jdog Avatar asked Feb 24 '13 21:02

jdog


1 Answers

1) Finding the right packages

In Ubuntu/Debian, typically library packages are prepended with "lib" rather than suffixed. Development packages are usually just suffixed with "-dev" rather than "-devel"

If you are unsure of what the equivalent package is named, you can always do this:

sudo apt-get update
apt-cache search <packagename>

...and do not include the "lib" or "dev" portions in your search and you will get decent results. From there you can manually determine what the correct package is that you are looking for.

2) Finding installed packages

You can use "dpkg -s" and it will work, although from my understanding of what "rpm -qa" outputs, you are propably wanting something less verbose. "dpkg-query -l " piped into "grep " will output the package info on one line and should be much easier to read through.

Here is what the equivalent portion of the script would look like(with the proper package names and the log_file output on a separate line to work properly):

#!/bin/bash

function stack_install()
{

log_file="$HOME/Desktop/stackoverflow/stack-log.txt"

req_libs=( libc6 e2fsprogs libkrb5-3 openssl )

for lib in ${req_libs[@]}
do
    local present=$(dpkg-query -l "$lib" | grep "$lib" 2>/dev/null)
    echo "$present" >> "$log_file"
    if [ "$present" == "" ]; then
        echo "The $lib library was not found installed in the dpkg database."
        echo "See README for which libraries are required for the $driver_name."
        return 1;
    fi
done 
}

stack_install
like image 90
redteam316 Avatar answered Sep 30 '22 06:09

redteam316