-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinux-functions.sh
executable file
·57 lines (46 loc) · 1.1 KB
/
linux-functions.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
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
function install_package {
if ! [ -x "$(command -v apt)" ]; then
echo "apt is not supported in this environment"
exit 1
fi
for var in "$@" ; do
apt -qq install -y $var
done
}
function add_to_path {
if [ "$#" -ne 2 ]; then
echo "This function expects exactly 2 parameters"
exit 1
fi
local PROGRAM_NAME=$1
local PROGRAM_PATH=$2
if is_sudo ; then
local RM_CMD="rm"
local CAT_CMD="cat"
local BASH_CMD="bash"
local CHMOD_CMD="chmod"
local SUDO_CMD=""
else
local RM_CMD="sudo rm"
local CAT_CMD="sudo cat"
local BASH_CMD="sudo bash"
local CHMOD_CMD="sudo chmod"
local SUDO_CMD="sudo"
fi
ENV_FILE=/etc/profile.d/$PROGRAM_NAME.sh
if [ -f $ENV_FILE ] ; then
$SUDO_CMD rm $ENV_FILE
fi
$SUDO_CMD bash -c "echo export PATH=\\\"$PROGRAM_PATH:\\\$PATH\\\" > $ENV_FILE"
$SUDO_CMD chmod 755 $ENV_FILE
ENV_FILE=/etc/profile.d/$PROGRAM_NAME.sh
if [ -f $ENV_FILE ] ; then
$RM_CMD $ENV_FILE
fi
$BASH_CMD -c "cat <<'EOF' > $ENV_FILE
export PATH=$PROGRAM_PATH:\$PATH
EOF"
$CHMOD_CMD 755 $ENV_FILE
echo $ENV_FILE
}