-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstaller.sh
94 lines (83 loc) · 2.38 KB
/
installer.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
#!/bin/bash
#############
# Author: Mario Bartolome
# Date: Apr 14, 2018
#
# This file will install all the necessary python packages to
# deploy and run this solution.
#
#############
printUsage()
{
echo "[!] USAGE: $0 VirtualEnvName [Optional]SetupName.py" >&2
exit 1
}
createEnv()
{
echo "[+] Creating environment on ../$1..."
mkdir ../$1 && python3 -m venv ../$1 && echo "[*] Python environment created on parent folder!"
isEnv=1
}
sigKillDetected()
{
echo "[!] Could not finish the process!"
if [ "x$1" != "x" ] && [ -d ../$1 ]; then
echo "Cleaning up..."
rm -rf ../$1
fi
exit 1
}
trap 'sigKillDetected $1' INT
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
printUsage
fi
if [ $# -eq 1 ]; then
if [ -f ./setup.py ]; then
setupFile=setup.py
else
echo "[!] I can't find the default 'setup.py' file to install" >&2
printUsage
fi
else
setupFile=$2
fi
echo "[+] Prior to attempt to install Python dependencies, make sure your system has the following packages installed:"
echo -e "\t gcc - I'm gonna need to compile some stuff..."
echo -e "\t python3-dev - To compile some Python dependencies"
echo -e "\t python3-venv - To create a virtual environment"
echo -e "\t python3-setuptools - To setup the Python dependencies"
echo "otherwise the setup will fail"
echo -e "\nDo you want to continue and create $1 virtualEnv?[enter]"
read
isEnv=0
if [ -d "../$1" ]; then
echo "[!] Uh oh, it seems $1 already exists on the parent directory" >&2
if [ -f "../$1/pyvenv.cfg" ]; then
isEnv=1
echo "[!] It also seems to be an existing Python Environment with the following packages on it: " >&2
../$1/bin/pip list --format=columns
fi
echo "[!] Do you want to overwrite it(yes/no)?"
read answer
if [ $answer = "yes" ]; then
rm -r ../$1
isEnv=0
echo "[*] Previous environment deleted"
createEnv $1
fi
else
createEnv $1
fi
if [ $isEnv -eq 1 ]; then
echo "[+] Activating $1..."
source ../$1/bin/activate
echo "[*] Python environment successfully activated"
echo "[+] Installing dependencies, this may take a while..."
python3 $setupFile install
echo "[*] Done! Use "
echo -e "\tsource ../$1/bin/activate"
echo "to enable the Virtual Environment"
else
echo "[!] $1 does not seem to be a Python VirtualEnvironment"
exit 1
fi