Skip to content

Instantly share code, notes, and snippets.

@zhongwm
Last active January 7, 2020 12:29
Show Gist options
  • Select an option

  • Save zhongwm/aae98f5bf614c4006d2c28fc3baadc5b to your computer and use it in GitHub Desktop.

Select an option

Save zhongwm/aae98f5bf614c4006d2c28fc3baadc5b to your computer and use it in GitHub Desktop.
#!/bin/sh
# Run this script on Centos 7 to quickly install python 3 and relavent
# packages to run python 3 applications, including pip, virtualenv.
# Will use a local yum repository at `172.16.8.113` to speed up.
if ! grep -q "CentOS Linux release 7" /etc/redhat-release; then
echo Not centos 7, will soon abort
exit 1
fi
if python3.7 -c 'import zlib' 2>/dev/null && pip 2>/dev/null && gcc --version 2>/dev/null && virtualenv --version 2>/dev/null; then
echo "Software already installed"
exit 0
else
echo "Software need to be installed"
fi
echo '--------------------------'
echo Will backup repo files in /etc/yum.repos.d/ to /etc/yum.repos.d/bak/
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/
cat <<EOF >/etc/yum.repos.d/local-repos.repo
[local-base]
name=CentOS Base
baseurl=http://172.16.8.87/base/
gpgcheck=0
enabled=1
[local-centosplus]
name=CentOS CentOSPlus
baseurl=http://172.16.8.87/centosplus/
gpgcheck=0
enabled=1
[local-extras]
name=CentOS Extras
baseurl=http://172.16.8.87/extras/
gpgcheck=0
enabled=1
[local-updates]
name=CentOS Updates
baseurl=http://172.16.8.87/updates/
gpgcheck=0
enabled=1
EOF
mkdir -p /root/.config/pip
cat <<EOF >/root/.config/pip/pip.conf
[global]
timeout = 60
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com
EOF
echo '--------------------------'
echo Will install packages for python3 environment
yum -y install python3 python3-pip # python3-devel
yum -y group install "Development Tools"
# tools for ordinary python package build
yum install -y openssl-devel bzip2-devel libffi-devel ncurses ncurses-devel readline readline-devel \
sqlite sqlite-devel
install_python3_7() {
cd /usr/src
tar tzf Python-3.7.4.tgz >/dev/null 2>&1 || curl -OL https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
tar zxf Python-3.7.4.tgz
cd Python-3.7.4
# python 2 or 3 are both ok for following script
python <<<"
with open('Modules/Setup.dist') as f1:
cnt=f1.read()
cnt=cnt.replace('#zlib zlibmodule.c -I\$(prefix)/include -L\$(exec_prefix)/lib -lz', 'zlib zlibmodule.c -I\$(prefix)/include -L\$(exec_prefix)/lib -lz')
cnt=cnt.replace('#readline readline.c -lreadline -ltermcap', 'readline readline.c -lreadline -ltermcap')
cnt=cnt.replace('#_curses _cursesmodule.c -lcurses -ltermcap', '_curses _cursesmodule.c -lcurses -ltermcap')
cnt=cnt.replace('#syslog syslogmodule.c\t\t# syslog daemon interface', 'syslog syslogmodule.c # syslog daemon interface')
cnt=cnt.replace('#_curses_panel _curses_panel.c -lpanel -lncurses', '_curses_panel _curses_panel.c -lpanel -lncurses')
with open('Modules/Setup.dist', 'w') as f2:
f2.write(cnt)
"
./configure --enable-optimizations # CPPFLAGS='-I/opt/zlib/include' LDFLAGS='-L/opt/zlib/lib'
make altinstall
# rm -f /usr/src/Python-3.7.4.tgz
python3.7 -V
}
python3.7 -c 'import zlib' || install_python3_7
pip3 install virtualenv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment