-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpython_chooser.sh
More file actions
executable file
·185 lines (185 loc) · 5.02 KB
/
python_chooser.sh
File metadata and controls
executable file
·185 lines (185 loc) · 5.02 KB
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
#!/bin/bash
#
# python_command.sh: looks at OS-related quantities and reports
# correct python-related command to use
#
## accepts one positional argument
## argument can have one of these values: command, config, scons, version, minor,
## boost, or boost_cmake
### command: python command to use
### config: python-config command use
### scon: scons command to use
### version: Python major version
### minor: Python minor version
### boost: name of the python-boost library, without the file extension and
### without the initial "lib"
## writes output to stdout
#
arg=$1
get_python_version() {
version_full=`${pycommand[command]} --version 2>&1 | awk '{print $2}'`
version_major=`echo $version_full | awk -F. '{print $1}'`
version_minor=`echo $version_full | awk -F. '{print $2}'`
version_subminor=`echo $version_full | awk -F. '{print $3}'`
}
#
# get OS-related information
#
uname=`uname`
if [ $uname == "Linux" ]
then
if [ -e /etc/fedora-release ]
then
dist_name=`awk '{print $1}' < /etc/fedora-release`
dist_version=`awk '{print $3}' < /etc/fedora-release`
elif [ -e /etc/redhat-release ]
then
if grep -lq 'Red Hat' /etc/redhat-release
then
dist_name=RedHat
elif grep -lq CentOS /etc/redhat-release
then
dist_name=CentOS
elif grep -lq Rocky /etc/redhat-release
then
dist_name=CentOS
elif grep -lq Alma /etc/redhat-release
then
dist_name=Alma
else
dist_name=unknown_redhat_like
fi
dist_version=`awk -F 'release' '{print $2}' < /etc/redhat-release \
| awk '{print $1}' | awk -F. '{print $1}'`
elif [ -e /etc/lsb-release ] # Ubuntu-like
then
dist_name=`grep DISTRIB_ID /etc/lsb-release | awk -F= '{print $2}'`
dist_version=`grep DISTRIB_RELEASE /etc/lsb-release \
| awk -F= '{print $2}' | awk -F. '{print $1}'`
fi
fi
distribution=$dist_name$dist_version
#
# encode the data on which command to use on which OS
## start with old versions and work your way up
#
declare -A pycommand
pycommand[lib]=''
pycommand[boost_cmake]=python3
if [ $dist_name == Fedora ]
then
if [ $dist_version -ge 32 ]
then
pycommand[command]=python
pycommand[config]=python-config
pycommand[scons]=scons
get_python_version
pycommand[version]=$version_major
pycommand[boost]=boost_python$version_major$version_minor
pycommand[boost_cmake]=python$version_major$version_minor
else
pycommand[command]=python
pycommand[config]=python-config
pycommand[scons]=scons
get_python_version
pycommand[version]=$version_major
pycommand[boost]=boost_python
fi
if [ $dist_version -ge 33 ]
then
pycommand[lib]=-lpython$version_major.$version_minor
fi
elif [[ $dist_name == RedHat || $dist_name == CentOS || $dist_name == Alma ]]
then
if [ $dist_version -le 7 ]
then
pycommand[command]=python
get_python_version
pycommand[config]=python-config
pycommand[scons]=scons
pycommand[boost]=boost_python
pycommand[lib]=-lpython$version_major.$version_minor
elif [ $dist_version -eq 8 ]
then
pycommand[command]=python3
get_python_version
pycommand[config]=python$version_major-config
pycommand[scons]=scons-$version_major
pycommand[boost]=boost_python$version_major
pycommand[lib]=-lpython$version_major
else
pycommand[command]=python3
get_python_version
pycommand[config]=python$version_major-config
pycommand[scons]=scons-$version_major
pycommand[boost]=boost_python$version_major$version_minor
pycommand[lib]=-lpython$version_major.$version_minor
fi
pycommand[version]=$version_major
elif [ $dist_name == Ubuntu ]
then
pycommand[command]=python3
get_python_version
pycommand[config]=python3-config
pycommand[scons]=scons
pycommand[version]=$version_major
pycommand[boost]=boost_python$version_major$version_minor
pycommand[lib]=-lpython$version_major.$version_minor
else
pycommand[command]=python
get_python_version
pycommand[config]=python-config
pycommand[scons]=scons
pycommand[version]=$version_major
pycommand[boost]=boost_python
fi
#
# report the answer
#
case $arg in
boost)
echo ${pycommand[boost]}
;;
boost_cmake)
echo ${pycommand[boost_cmake]}
;;
command)
echo ${pycommand[command]}
;;
config)
echo ${pycommand[config]}
;;
info)
echo uname = $uname
echo dist_name = $dist_name
echo dist_version = $dist_version
echo distribution = $distribution
echo version_full = $version_full
echo version_major = $version_major
echo version_minor = $version_minor
echo version_subminor = $version_subminor
echo python command = ${pycommand[command]}
echo config command = ${pycommand[config]}
echo scons command = ${pycommand[scons]}
echo version command = ${pycommand[version]}
echo boost command = ${pycommand[boost]}
echo lib command = ${pycommand[lib]}
;;
lib)
echo ${pycommand[lib]}
;;
scons)
echo ${pycommand[scons]}
;;
version)
echo ${pycommand[version]}
;;
minor)
echo $version_minor
;;
*)
echo python_chooser.sh error: unknown argument = \"$arg\"
echo accepted arguments: boost, boost_cmake, command, config, info, lib, scons, version, minor
exit 1
;;
esac