Du bist hier: Startseite > Linux > BASH Functions > CheckCommand

CheckCommand

Prüft ob Befehl vorhanden ist, wenn nicht wird er installiert:

#!/bin/bash
checkCommand()
{
    if [ ! "$(id -u)" == "0" ]; then
	echo "Nicht als root angemeldet!";
	exit 1;
    fi
    command -v $2 >/dev/null || { 
	echo "Der Befehl \"$2\" wurde nicht gefunden!";
	if [ "$1" = "1" ]; then
	    echo "Automatische Installation wird gestartet!";
	    if [ ! "$4" = "" ] ; then
		eval "add-apt-repository $4 && apt-get update";
	    fi
	    eval "apt-get -y install $3";
	else
	    if [ ! "$4" = "" ] ; then
		echo -e "Installieren mit:\n";
		echo "add-apt-repository $4 && apt-get update";
	    fi
	    echo -e "apt-get install $3\n";
	    exit 1;
	fi
    }
}
# Aufruf:
checkCommand "autoinstall_1_or_0" "comandname" "apt-get-install name" "ppa if exists"