Multi-OS package installation and search functions

Commands to search for packages and install packages are usually too little long to have to type very often. But making an alias for them can be troublesome if you work on multiple OSes. I used to just have the following:

1
2
alias inst="sudo apt-get install"
alias query="sudo apt-cache search"

But that only worked on Debian based systems. I wanted commands to search for packages, get info on packages, and install packages on all OSes I commonly work on. It ended up being easier to write this as bash functions. They all use a variable defined in another one of my functions, described here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function inst () {
    # Installs passed packages.
    case "$CUR_OS" in
    'debian')
        sudo apt-get install $@
        ;;
    'redhat')
        sudo yum install $@
        ;;
    *)
        echo "You are not on a supported OS."
        ;;
    esac
}

function query () {
    # Returns search results for passed packages.
    case "$CUR_OS" in
    'debian')
        sudo apt-cache search $@
        ;;
    'redhat')
        sudo yum search $@
        ;;
    *)
        echo "You are not on a supported OS."
        ;;
    esac
}

function pkginfo () {
    # Returns info on passed packages.
    case "$CUR_OS" in
    'debian')
        sudo apt-cache show $@
        ;;
    'redhat')
        sudo yum info $@
        ;;
    *)
        echo "You are not on a supported OS."
        ;;
    esac
}

So now I can type

1
2
3
inst PKGNAME
query PKGNAME
pkginfo PKGNAME

and it will either do what I need it to do, for almost every box I am on, or let me know the OS is not supported (at which point I can just add another appropriate block).

Post to Twitter Post to Delicious Post to Digg Post to Reddit

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

This entry was posted in CLI and tagged , , . Bookmark the permalink.

One Response to Multi-OS package installation and search functions

  1. Pingback: Useful Bash functions to determine OS and more | tail -f findings.out

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>