bash - Find out which package I have to install on a Linux system -


i made bash script install software package on linux system. there 4 packages can use install software:

  1. x86.deb
  2. x86.rpm
  3. x86_64.deb
  4. x86_64.rpm

i know when install package on linux server manually, find out "automatically" (in bash script) 1 have install.

is there command find out? know there way find out architecture (32-bit or 64-bit) via "arch" command, not know how find out package need.

uname -m or arch gives architecture (x86_64 or similar).

you can figure out whether system based on rpm or deb (e. g. ubuntu deb-based) asking both variants package installed /bin/ls:

dpkg -s /bin/ls 

will print

coreutils: /bin/ls 

on deb-based system.

rpm -q -f /bin/ls 

will print

coreutils-5.97-23.el5_6.4 

on rpm-based system (with different version numbers).

on "wrong" system each of these give error message instead.

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

of course makes sense in case know then, i. e. if know package installed on package system architecture.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -