-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpython.sh
121 lines (103 loc) · 3.03 KB
/
python.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
#!/bin/bash
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
PINK='\033[1;35m'
show() {
case $2 in
"error")
echo -e "${PINK}${BOLD}❌ $1${NORMAL}"
;;
"progress")
echo -e "${PINK}${BOLD}⏳ $1${NORMAL}"
;;
*)
echo -e "${PINK}${BOLD}✅ $1${NORMAL}"
;;
esac
}
check_python_installed() {
if command -v python3 >/dev/null 2>&1; then
show "Python 3 is already installed."
return 0
else
show "Python 3 is not installed." "error"
return 1
fi
}
check_pip_installed() {
if command -v pip3 >/dev/null 2>&1; then
show "pip3 is already installed."
return 0
else
show "pip3 is not installed." "error"
return 1
fi
}
install_python() {
show "Installing Python 3 and pip..." "progress"
sudo apt update
sudo apt install -y python3 python3-pip
show "Python and pip installation complete."
}
install_dev_tools() {
show "Installing essential development tools..." "progress"
sudo apt install -y build-essential libssl-dev libffi-dev python3-dev
show "Development tools installed successfully."
}
install_virtualenv() {
show "Installing virtualenv..." "progress"
pip3 install virtualenv
show "virtualenv installed."
}
add_python_to_path() {
if grep -q "python3" "$HOME/.bashrc" || grep -q "python3" "$HOME/.zshrc"; then
show "Python is already added to PATH."
else
show "Adding Python to PATH..." "progress"
if [ -f "$HOME/.bashrc" ]; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$HOME/.bashrc"
elif [ -f "$HOME/.zshrc" ]; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$HOME/.zshrc"
else
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$HOME/.profile"
fi
fi
}
validate_python() {
show "Validating Python and pip installation..." "progress"
if ! command -v python3 >/dev/null 2>&1; then
show "Error: Python is not installed properly." "error"
return 1
else
show "Python 3 is working fine in the current session."
fi
if ! command -v pip3 >/dev/null 2>&1; then
show "Error: pip3 is not installed properly." "error"
return 1
else
show "pip3 is working fine in the current session."
fi
future_shell_test=$(bash -c "command -v python3 && command -v pip3")
if [ -z "$future_shell_test" ]; then
show "Error: PATH not properly set for future shell sessions." "error"
return 1
else
show "Python and pip are set up correctly for future shell sessions."
fi
return 0
}
show "Checking if Python 3 is already installed..." "progress"
if check_python_installed; then
show "Python 3 is already installed. Checking pip3..."
if ! check_pip_installed; then
install_python
fi
validate_python
else
install_python
install_dev_tools
install_virtualenv
add_python_to_path
validate_python
fi
show "Python installation and setup complete."