-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpre-installation.sh
executable file
·156 lines (133 loc) · 4.38 KB
/
pre-installation.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
VENV_DIR="venv"
echo "Starting installation of Python 3, pip3, the Python requirements in the requirements.txt file, Ansible, the Ansible
requirements in the requirements.yml file, OpenSSH server and sshpass"
echo
sudo apt-get update
sudo apt-get upgrade
sleep 2
if ! command -v python3 &> /dev/null; then
echo "Python 3 is not installed. Installing now..."
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if [[ -n $(command -v apt-get) ]]; then
sudo apt-get update
sudo apt-get install -y python3
else
echo "Package manager not found. Please install Python 3 manually."
exit 1
fi
else
echo "Unsupported operating system: $OSTYPE"
exit 1
fi
echo "Python 3 has been installed."
else
echo "Python 3 is already installed."
fi
if ! command -v pip3 &> /dev/null; then
echo "pip3 is not installed. Installing now..."
if [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
if [ -f /etc/os-release ]; then
. /etc/os-release
if [ "$ID" == "ubuntu" ] || [ "$ID" == "debian" ]; then
sudo apt-get update
sudo apt-get install -y python3-pip
else
echo "Your operating system is not supported by this script."
exit 1
fi
else
echo "Your operating system is not supported by this script."
exit 1
fi
else
echo "Your operating system is not supported by this script."
exit 1
fi
echo "pip3 has been installed."
else
echo "pip3 is already installed."
fi
if ! command -v ansible &> /dev/null; then
echo "Ansible is not installed. Installing now..."
if [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
if [ -f /etc/os-release ]; then
. /etc/os-release
if [ "$ID" == "ubuntu" ] || [ "$ID" == "debian" ]; then
sudo apt-get update
sudo apt-get install -y ansible
else
echo "Your operating system is not supported by this script."
exit 1
fi
else
echo "Your operating system is not supported by this script."
exit 1
fi
else
echo "Your operating system is not supported by this script."
exit 1
fi
echo "Ansible has been installed."
else
echo "Ansible is already installed."
fi
if ! command -v sshd &> /dev/null; then
echo "OpenSSH server is not installed. Installing..."
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo apt-get install openssh-server -y
sudo apt-get install ssh -y
fi
echo "OpenSSH server installed successfully."
else
echo "OpenSSH server is already installed."
fi
if ! command -v sshpass &> /dev/null; then
echo "sshpass is not installed. Installing now..."
if [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
if [ -f /etc/os-release ]; then
. /etc/os-release
if [ "$ID" == "ubuntu" ] || [ "$ID" == "debian" ]; then
sudo apt-get update
sudo apt-get install -y sshpass
else
echo "Your operating system is not supported by this script."
exit 1
fi
else
echo "Your operating system is not supported by this script."
exit 1
fi
else
echo "Your operating system is not supported by this script."
exit 1
fi
echo "sshpass has been installed."
else
echo "sshpass is already installed."
fi
sudo apt install -y python3-venv
# Check if the virtual environment directory exists
if [ ! -d "$VENV_DIR" ]; then
# The virtual environment does not exist, create it
python3 -m venv "$VENV_DIR" || exit 1
# Activate the virtual environment
source "$VENV_DIR/bin/activate" || exit 1
# Install the requirements
if [ -f "requirements.txt" ]; then
pip3 install -r requirements.txt || exit 1
else
echo "No requirements.txt file found."
exit 1
fi
else
# The virtual environment exists, activate it
source "$VENV_DIR/bin/activate" || exit 1
fi
echo "Installing Python Requirements"
pip3 install -r requirements.txt || exit 1
echo
echo "Installing ansible galaxy requirements"
ansible-galaxy collection install -r requirements.yml
echo "Pre-installation complete..."
sleep 3