-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
installtool.sh
47 lines (37 loc) · 1.32 KB
/
installtool.sh
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
45
46
47
#!/bin/bash/
source "$DIR/utils/install_package.sh"
# in this file is declared a function that installs a tool and its related packages
install_tool() {
# $1: the name of the tool we're installing
local TOOL=$1
shift
printf "installing tool \"$TOOL\"\n"
while test $# -gt 0; do
# the name of the package we're installing
local PKG=$1
shift
# the installation function to use (default to apt-get)
local INSTALL_FUNCTION=${1:-"apt_get_install &> /dev/null"}
shift
# optional, overrides check to see if package is installed
local IS_INSTALLED=$1
shift
# check wether or not the package is already installed
local PKG_OK=$(dpkg -l | awk '/^ii +'"$PKG"' +/' | egrep "^ii" | wc -l)
printf " [$TOOL] Checking for $PKG: "
# if package isnt installed, install it
if [ "$IS_INSTALLED" = "YES" ] || type "$PKG" &> /dev/null ; then
# if its already installed, just move on
printf "ok.\n"
else
echo "No $PKG. Setting up $PKG."
$INSTALL_FUNCTION $PKG
fi
done
}
# Usage of install_tool shall be as shown bellow:
# to install tool "node", with packages "yarn", "nvm" and "node"
# install_tool "node" \
# "nvm" "shell_function_that_installs_nvm" \
# "node" "shell_function_that_installs_nvm" \
# "yarn" "shell_function_that_installs_yarn"