Last active
July 9, 2018 02:23
-
-
Save koyo922/422ca95f1350faacf42c485ee9054feb to your computer and use it in GitHub Desktop.
python_config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# referencing: https://www.moerats.com/archives/507/ | |
set -e | |
# Usage: pipe to `sh` on the fly, or download and use | |
# curl -L https://tinyurl.com/mk-inst-py | PYTHON_VERSION=<2.7.15 or 3.6.5> [SILENT_SUDO=1] sh | |
# wget https://tinyurl.com/mk-inst-py && PYTHON_VERSION=3.6.5 sh ./install_python_from_source.sh | |
if ! [[ "$PYTHON_VERSION" =~ ^(2.7.15|3.6.5)$ ]]; then # required environ var | |
echo "Usage: PYTHON_VERSION=<2.7.15 or 3.6.5> [SILENT_SUDO=1] sh $BASH_SOURCE" | |
exit 1 | |
fi | |
[[ $SILENT_SUDO == 1 ]] && SUDO='sudo -n' || SUDO='sudo' | |
PYTHON_ROOT=$HOME/local/Python-$PYTHON_VERSION | |
if [ -d $PYTHON_ROOT ]; then | |
echo "PYTHON_ROOT already exists: $PYTHON_ROOT" | |
exit 0 | |
fi | |
export LANG=en_US.UTF-8 | |
export LANGUAGE=en_US.UTF-8 | |
OS_DISTRIBUTION=$(python -m platform) | |
cat <<'EOF' | |
******************** CAUTION: when prompted for SUDO-password, you can take either of the following actions: | |
1. Enter your password | |
2. Hit CTRL-C to SKIP yum/apt-get steps and CONTINUE the installation | |
EOF | |
if [[ "$OS_DISTRIBUTION" == *centos* ]]; then | |
if $SUDO yum -y update; then | |
$SUDO yum groupinstall -y "Development tools" | |
$SUDO yum install -y nano make screen gcc ncurses-libs zlib-devel mysql-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel openssl-devel | |
else | |
echo '^^^^^^^^^^^^^^^^^^^^ [SKIP] Skipped yum operation as non-root' | |
fi | |
elif [[ "$OS_DISTRIBUTION" == *Ubuntu* ]]; then | |
if $SUDO apt-get update -y; then | |
$SUDO apt-get install -y make gcc libncurses5-dev libncursesw5-dev bzip2 libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev ca-certificates | |
else | |
echo '^^^^^^^^^^^^^^^^^^^^ [SKIP] Skipped apt operation as non-root or sudo' | |
fi | |
else | |
echo '^^^^^^^^^^^^^^^^^^^^ [FATAL] Only CentOS/Ubuntu OS supported now' | |
exit 1 | |
fi | |
if [ ! -d "Python-$PYTHON_VERSION" ]; then | |
#curl https://www.moerats.com/usr/shell/Python3/Python-3.6.4.tar.gz | tar xzfv - | |
# curl https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz | tar xzfv - | |
curl ftp://jp01-ime-odp00.jp01.baidu.com/home/work/tools/Python-$PYTHON_VERSION.tgz | tar xzfv - | |
fi | |
cd Python-$PYTHON_VERSION | |
mkdir -p $PYTHON_ROOT | |
./configure --prefix=$PYTHON_ROOT | |
make && make install | |
if [[ $PYTHON_VERSION="3.6.5" ]]; then | |
ln -s $PYTHON_ROOT/bin/python3 $PYTHON_ROOT/bin/python | |
echo "[INFO] symlink created: $(ls -lh $PYTHON_ROOT/bin/python)" | |
fi | |
echo "******************** [SUCC] PYTHON installed at: $PYTHON_ROOT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment