-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython_installer.sh
executable file
·76 lines (61 loc) · 1.71 KB
/
python_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
#!/usr/bin/env bash
# $1 is the user link
script_dir=$(dirname "$0")
source "$script_dir/lib/common_functions.sh"
# funtions
# get the version of the python file
function get_version {
local version=$(dirname "$1")
version=$(basename "$version")
version=${version%.*}
echo "$version"
}
# checks if the file extension is .tgz
function check_tgz {
if [[ $1 != *.tgz ]]; then
error_message "file provided does not end with .tgz"
fi
}
# downloads the file from the url
# and checks if it was successful
function get {
wget --timeout=600 "$1" --no-check-certificate
if [ $? -ne 0 ]; then
error_message "failed to download file"
fi
}
# installs the python file
function python_install {
sudo apt-get update
sudo apt-get install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev
tar -xf $1
python_folder=$(basename "$1" .tgz)
$python_folder/configure --enable-optimizations
make
make altinstall
rm -r "$2"
}
# variables
original_user=$(get_username)
base_folder="$(getent passwd $original_user | cut -d: -f6)/python_versions"
filename=$(basename "$1")
# main script
# confirms if running with sudo/root
root_confirm
# checks if file is a tgz
check_tgz "$1"
# gets the version of the python file
# is already installed
version=$(get_version "$1")
verify_version "$version"
# creates the base folder
# if the folder already exists, first delete it.
if check_if_exists "$base_folder"; then
rm -rf "$base_folder"
fi
make_dir "$base_folder"
# downloads the file
get $1
# installs the file
# and removes the python folder/files
python_install "$filename" "$base_folder"