forked from berlin493/github4shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_python.sh
187 lines (160 loc) · 4.85 KB
/
install_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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
check_system (){
SYSTEM_INFO=`head -n 1 /etc/issue`
case "${SYSTEM_INFO}" in
'CentOS release 5'*)
SYSTEM='centos5'
YUM_SOURCE_NAME='centos5-lan'
CONFIG_CMD='chkconfig'
;;
'Red Hat Enterprise Linux Server release 5'*)
SYSTEM='rhel5'
YUM_SOURCE_NAME='RHEL5-lan'
CONFIG_CMD='chkconfig'
;;
# 'Debian GNU/Linux 6'*)
# SYSTEM='debian6'
# CONFIG_CMD='sysv-rc-conf'
# ;;
# 'Debian GNU/Linux 7'*)
# SYSTEM='debian7'
# CONFIG_CMD='sysv-rc-conf'
# ;;
*)
SYSTEM='unknown'
echo "This script not support ${SYSTEM_INFO}" 1>&2
exit 1
;;
esac
}
set_install_cmd () {
local para="$1"
case "${SYSTEM}" in
centos5|rhel5)
local install_cmd='yum --skip-broken --nogpgcheck'
local package="${YUM_PACKAGE}"
;;
# debian6|debian7)
# local install_cmd='apt-get --force-yes'
# local package="${APT_PACKAGE}"
# eval "${install_cmd} install -y sysv-rc-conf >/dev/null 2>&1" || eval "echo ${install_cmd} fail! 1>&2;exit 1"
# ;;
*)
echo "This script not support ${SYSTEM_INFO}" 1>&2
exit 1
;;
esac
if [ "${install_cmd}" = 'yum' -a "${para}" = 'lan' ];then
install_cmd="yum --skip-broken --nogpgcheck --disablerepo=\* --enablerepo=${YUM_SOURCE_NAME}"
fi
local log_file="${TEMP_PATH}/YUM.log"
echo -n "Install ${package} please wait ...... "
eval "${install_cmd} install -y ${package} >${log_file} 2>&1" || local install_stat='fail'
if [ "${install_stat}" = "fail" ];then
echo -e "${install_cmd} not available!\nview error please type: less ${log_file}" 1>&2
exit 1
fi
echo "done."
}
create_tmp_dir () {
mkdir -p "${INSTALL_PATH}" && cd "${INSTALL_PATH}" || local mkdir_dir='fail'
if [ "${mkdir_dir}" = "fail" ];then
echo "mkdir ${INSTALL_PATH} fail!" 1>&2
exit 1
fi
}
del_tmp () {
test -d "${INSTALL_PATH}" && rm -rf "${INSTALL_PATH}"
}
download_file () {
local url="$1"
echo -n "Download ${url} ...... "
wget -q "${url}" && echo 'done.' || local download='fail'
if [ "${download}" = "fail" ];then
echo "fail!" 1>&2 && del_tmp
exit 1
fi
}
check_file () {
local file="$1"
local ex_dir=`echo "${file}"|awk -F'.tar|.tgz' '{print $1}'`
local dir="${INSTALL_PATH}/${ex_dir}"
test -f ${file} && tar xzf ${file} || eval "echo ${file} not exsit!;del_tmp;exit 1"
test -d ${dir} && cd ${dir} || eval "echo ${dir} not exsit!;del_tmp;exit 1"
echo -n "Compile ${file} please wait ...... "
}
run_cmds () {
local cmd_log="${TEMP_PATH}/install_${PACKAGE}.log"
test -f "${cmd_log}" && rm -f ${cmd_log}
for cmd in "$@"
do
${cmd} >> "${cmd_log}" 2>&1 || compile='fail'
if [ "${compile}" = 'fail' ]; then
echo "run ${cmd} error! please type: less ${cmd_log}" 1>&2 && del_tmp
exit 1
fi
done
echo "done."
# cd ..
}
download_and_check () {
download_file "${PACKAGE_URL}/${PACKAGE}"
check_file "${PACKAGE}"
}
echo_bye () {
echo "Install ${PACKAGE} complete!"
}
exit_and_clear () {
del_tmp
echo_bye
}
main () {
#SET TEMP PATH
TEMP_PATH='/usr/local/src'
#SET PACKAGE
YUM_SERVER='yum.suixingpay.com'
YUM_PACKAGE='gcc glibc glibc-common make gcc-c++ zlib zlib-devel readline readline-devel openssl-devel'
APT_PACKAGE='build-essential'
PACKAGE_URL="http://${YUM_SERVER}/tools"
#SET TEMP DIR
INSTALL_DIR="install_$$"
INSTALL_PATH="${TEMP_PATH}/${INSTALL_DIR}"
#SET EXIT STATUS AND COMMAND
trap "exit 1" HUP INT PIPE QUIT TERM
trap "rm -rf ${INSTALL_PATH}" EXIT
#CHECK SYSTEM AND CREATE TEMP DIR
check_system
#create_tmp_dir
set_install_cmd 'lan'
my_time=`date -d now +"%F_%H-%M"`
#Install Python-2.7.6
PACKAGE='Python-2.7.6.tgz'
create_tmp_dir
download_and_check
old_python_version='/usr/bin/python'
test -f ${old_python_version} && mv ${old_python_version} ${old_python_version}.bak.${my_time}
run_cmds './configure --prefix=/usr' 'make' 'make install'
#Install easy_install
PACKAGE='setuptools-1.3.2.tar.gz'
create_tmp_dir
download_and_check
run_cmds 'python setup.py build' 'python setup.py install'
python_version=`ls /usr/bin/python2*|grep -oE '[0-9]\.[0-9]$'|head -n 1`
yum_file='/usr/bin/yum'
test -f ${yum_file} && sed -r -i.bak_${my_time} "1s/(python).*$/\1${python_version}/" ${yum_file}
#Modify yum cmds
yum_cmd_path='/usr/share/system-config-network'
test -d ${yum_cmd_path} && cd ${yum_cmd_path} || cmd_path='not found'
if [ "${cmd_path}" = 'not found' ];then
echo ${yum_cmd_path} not found! 1>&2
else
ls *.py|\
while read cmd_file
do
sed -r -i.bak_${my_time} "1s/(python).*$/\1${python_version}/" ${cmd_file}
done
fi
#EXIT AND CLEAR TEMP DIR
exit_and_clear
}
main