Find out which package I should install on a Linux system

I made a bash script to install a software package on a Linux system. I can use 4 packages to install the software:

  • x86.deb
  • x86.rpm
  • x86_64.deb
  • x86_64.rpm

I know when to manually install which package on a Linux server, but I would like to know "automatically" (in my bash script) which I should install.

Is there any command to find out? I already know there is a way to find out the architecture (32-bit or 64-bit) using the "arch" command, but I don't know how to find out which package I need.

+3


source to share


1 answer


uname -m

or arch

provides you with an architecture ( x86_64

or similar).

You can probably figure out if your system is RPM or DEB based (e.g. Ubuntu is DEB based) by setting both options where the package is installed /bin/ls

:

dpkg -S /bin/ls

      

will print

coreutils: /bin/ls

      

in a DEB based system.

rpm -q -f /bin/ls

      



will print

coreutils-5.97-23.el5_6.4

      

on an RPM based system (possibly with different version numbers).

On the "wrong" system, each of them will give an error message.

if dpkg -S /bin/ls >/dev/null 2>&1
then
  case "$(arch)" in
    x86_64)
      sudo dpkg -i x86_64.deb;;
    i368)
      sudo dpkg -i x86.deb;;
    *)
      echo "Don't know how to handle $(arch)"
      exit 1
      ;;
  esac
elif rpm -q -f /bin/ls >/dev/null 2>&1
then
  case "$(arch)" in
    x86_64)
      sudo rpm -i x86_64.rpm;;
    i368)
      sudo rpm -i x86.rpm;;
    *)
      echo "Don't know how to handle $(arch)"
      exit 1
      ;;
  esac
else
  echo "Don't know this package system (neither RPM nor DEB)."
  exit 1
fi

      

Of course, all this only makes sense if you know what to do then, i.e. That is, if you know which package should be installed on which package system, with which architecture.

0


source







All Articles