-
Notifications
You must be signed in to change notification settings - Fork 0
/
Python3_x.sh
144 lines (140 loc) · 4.33 KB
/
Python3_x.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
#!/bin/bash
#
# ----------------------------------------------------------------------------
# Generalized and expanded version of:
# https://gist.githubusercontent.com/SeppPenner/6a5a30ebc8f79936fa136c524417761d/raw/3060da171c0653daac52b17e1598919a0ecb17e6/setup.sh
# By Phil Huhn
#
PROGNAME=$(basename "$0")
REVISION="1.0.6"
# Options variables:
PY_VER=3.7.2
GPIO=true
ODBC=false
FORCE=false
LINK=false
#
if [ "$1" == "-h" ]; then
cat <<EOF
Usage: $0 [options]
-h this help text.
-p python version, default value: ${PY_VER}
-f force python, default value: ${FORCE}
-l link python3, default value: ${LINK}
-g install GPIO, default value: ${GPIO}
-o install ODBC, default value: ${ODBC}
Example: $0 -p 3.8.0a2 -o true -l true
EOF
exit
fi
#
# process of arguments
#
while getopts ":p:f:l:g:o:" option
do
case "${option}"
in
p) PY_VER=${OPTARG};;
f) FORCE=$(echo "${OPTARG}" | tr '[:upper:]' '[:lower:]');;
l) LINK=$(echo "${OPTARG}" | tr '[:upper:]' '[:lower:]');;
g) GPIO=$(echo "${OPTARG}" | tr '[:upper:]' '[:lower:]');;
o) ODBC=$(echo "${OPTARG}" | tr '[:upper:]' '[:lower:]');;
*) echo "Invalid option: ${option} arg: ${OPTARG}"
exit 1
;;
esac
done
#
echo "=- Running ${PROGNAME} ${REVISION} -="
date
#
PY_CMD=$(echo "${PY_VER}" | grep -Po '^\d.\d')
PY_DIR=$(echo "${PY_VER}" | grep -Po '^\d.\d.\d')
echo "force python value: ${FORCE}"
echo "link install, value: ${LINK}"
echo "install GPIO value: ${GPIO}"
echo "install ODBC value: ${ODBC}"
echo "${LINENO} ${PROGNAME}, Install Python ${PY_VER}, command python${PY_CMD}"
date
#
cd /tmp || exit 1
echo "${LINENO} ${PROGNAME}, apply updates, ..."
sudo apt update
sudo apt upgrade
echo "${LINENO} ${PROGNAME}, requirements, ..."
sudo apt install gcc libxml2-dev libxslt1-dev zlib1g-dev g++
sudo apt-get update -y
echo "${LINENO} ${PROGNAME}, build-essential, ..."
sudo apt-get install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev -y
#
which "python${PY_CMD}" > /dev/null
if [ $? != 0 ] || [ "x${FORCE}" == "xtrue" ]; then
echo "${LINENO} ${PROGNAME}, download and build Python ${PY_VER}"
wget "https://www.python.org/ftp/python/${PY_DIR}/Python-${PY_VER}.tar.xz"
tar xf "Python-${PY_VER}.tar.xz"
cd "Python-${PY_VER}" || exit 2
./configure
make -j 4
sudo make altinstall
cd .. || exit 3
sudo rm -r "Python-${PY_VER}"
rm "Python-${PY_VER}.tar.xz"
#
which "python${PY_CMD}" > /dev/null
if [ $? != 0 ]; then
echo "${LINENO} ${PROGNAME}, python failed to build, ..."
exit 1
fi
sudo apt install python3-pip
#
if [ "X${LINK}" == Xtrue ]; then
sudo rm /usr/bin/python3
sudo ln -s "/usr/local/bin/python${PY_CMD}" /usr/bin/python3
echo "${LINENO} ${PROGNAME}, current python version, ..."
python3 -V
fi
#
else
echo "${LINENO} ${PROGNAME}, skipping python download and build, ..."
fi
#
sudo apt update
sudo apt upgrade
sudo apt-get install unixodbc-dev
#
if [ "x${GPIO}" == "xtrue" ]; then
sudo apt-get update -y
echo "${LINENO} ${PROGNAME}, installing GPIO, ..."
sudo apt install python3-gpiozero
# sudo apt install python3-rpi.gpio (now automatically installed)
sudo "python${PY_CMD}" -m pip install pigpio
sudo "python${PY_CMD}" -m pip install RPIO
else
echo "${LINENO} ${PROGNAME}, skipping GPIO, ..."
fi
#
if [ "x${ODBC}" == "xtrue" ]; then
echo "${LINENO} ${PROGNAME}, installing ODBC, ..."
sudo "python${PY_CMD}" -m pip install pyodbc
else
echo "${LINENO} ${PROGNAME}, skipping ODBC, ..."
fi
#
sudo apt-get --purge remove tk-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev -y
sudo apt-get autoremove -y
sudo apt-get clean
#
cd ~ || exit 4
echo "Now use python${PY_CMD} command to use this version."
echo "Do NOT link python to point to another version and do NOT delete python2.7"
if [ "X${LINK}" == Xfalse ]; then
echo "To link this version to python3, do the following:"
echo " $ sudo rm /usr/bin/python3"
echo " $ sudo ln -s /usr/local/bin/python3.7 /usr/bin/python3"
echo " $ python3 -V"
echo " Python 3.7.2"
else
echo "Now python${PY_CMD} command is linked to python3 command."
echo "To remove python${PY_CMD}, you must first relinked previous version to python3."
fi
#