-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhelper_function.sh
executable file
·73 lines (67 loc) · 1.7 KB
/
helper_function.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
# Copyright (c) 2018 Jegathesan Shanmugam
# Released under the MIT License (MIT)
# https://github.com/nullbyte91/Simple-Sh-DataScience/blob/master/LICENSE.md
# Title : helper_function.sh
# Description : This script contains helper function to support other bash scripts
# author : Jegathesan Shanmugam
function systemBasicUpdates()
{
# Update the apt package index and Upgrade the Ubuntu system
sudo apt-get update
if [[ $? > 0 ]]
then
echo "apt-get update failed, exiting."
exit
else
echo "apt-get update ran succesfuly, continuing with script."
fi
sudo apt-get -y upgrade
if [[ $? > 0 ]]
then
echo "apt-get upgrade failed, exiting."
exit
else
echo "apt-get upgrade ran succesfuly, continuing with script."
fi
}
function installAptPackages()
{
for pkg in $1; do
if dpkg --get-selections | grep -q "^$pkg[[:space:]]*install$" >/dev/null; then
echo -e "$pkg is already installed"
else
if sudo apt-get -qq install $pkg; then
echo "Successfully installed $pkg"
else
echo "Error installing $pkg"
fi
fi
done
}
function installPipPackages()
{
echo "Note: Pip install with --user Mode"
echo "$1 & $2"
if [ "$1" == "2" ];
then
pip install $2 --user
else
pip3 install $2 --user
fi
}
function removeAptPackages()
{
for pkg in $1; do
if dpkg --get-selections | grep -q "^$pkg[[:space:]]*install$" >/dev/null; then
echo -e "$pkg is installed. Gonna remove"
if sudo apt-get -qq remove $pkg; then
echo "Successfull remove $pkg"
else
echo "Error removing $pkg"
fi
else
echo -e "$pkg is not installed"
fi
done
}