-
Notifications
You must be signed in to change notification settings - Fork 0
/
platforminfo
executable file
·85 lines (75 loc) · 3.2 KB
/
platforminfo
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
#!/usr/bin/env bash
readonly WIDTH_NAME=35
run_and_output_with_command()
{
out=$(eval "${1}" 2> /dev/null)
[ "${?}" != 0 ] && return
echo "${2:-${1}}:"
echo "$out"
echo
}
has_command()
{
command -v "${1}" &> /dev/null
}
gcc_version()
{
compiler="${1}"
MAJOR=$(echo __GNUC__ | "$compiler" -E -x c - | tail -n 1)
MINOR=$(echo __GNUC_MINOR__ | "$compiler" -E -x c - | tail -n 1)
PATCHLEVEL=$(echo __GNUC_PATCHLEVEL__ | "$compiler" -E -x c - | tail -n 1)
echo "$MAJOR.$MINOR.$PATCHLEVEL"
}
main()
{
if [ -r /usr/bin/lsb_release ]; then
run_and_output_with_command '/usr/bin/lsb_release -a'
elif [ -r /etc/system-release ]; then
run_and_output_with_command 'cat /etc/system-release'
fi
if [ -r /proc/version ]; then
run_and_output_with_command 'cat /proc/version'
else
run_and_output_with_command 'uname -a'
fi
pycode=$(cat << EOF
import sys, platform
print(platform.platform())
print(platform.uname())
print('Endianness: ' + (sys.byteorder + ' endian').title())
EOF
)
run_and_output_with_command 'python -c "$pycode"' "Python Platform"
if [ -r /proc/cpuinfo ]; then
printf "%${WIDTH_NAME}s: %s\n" 'CPU model' "$(grep 'model name' /proc/cpuinfo | uniq | awk -F : '{print $2}' | sed 's/^[ \t]*//g')"
printf "%${WIDTH_NAME}s: %s\n" 'Number of physical CPUs' "$(grep 'physical id' /proc/cpuinfo | uniq | wc -l)"
printf "%${WIDTH_NAME}s: %s\n" 'Number of CPU cores' "$(grep 'processor' /proc/cpuinfo | uniq | wc -l)"
fi
if [ -r /proc/meminfo ]; then
printf "%${WIDTH_NAME}s: %s\n" 'Total physical memory' "$(grep 'MemTotal' /proc/meminfo | awk -F : '{print $2}' | sed 's/^[ \t]*//g')"
fi
has_command hostname && printf "%${WIDTH_NAME}s: %s\n" 'Hostname' "$(hostname --fqdn)"
[ -n "$BASH_VERSION" ] && printf "%${WIDTH_NAME}s: %s\n" 'Bash version' "$BASH_VERSION"
has_command gcc && printf "%${WIDTH_NAME}s: %s\n" 'GCC version' "$(gcc_version gcc)"
has_command g++ && printf "%${WIDTH_NAME}s: %s\n" 'G++ version' "$(gcc_version g++)"
has_command php && printf "%${WIDTH_NAME}s: %s\n" 'PHP version' "$(php -v | sed -n '1p')"
has_command python3 && printf "%${WIDTH_NAME}s: %s\n" 'Python3 version' "$(python3 --version)"
has_command python2 && printf "%${WIDTH_NAME}s: %s\n" 'Python2 version' "$(python2 --version 2>&1)"
echo
pycode=$(cat << EOF
import sys, platform, pprint, os
print('%*s: %s' % ($WIDTH_NAME, 'platform.python_version', platform.python_version()))
print('%*s: %s' % ($WIDTH_NAME, 'sys.version_info', sys.version_info))
print('%*s: %s' % ($WIDTH_NAME, 'sys.version', ''.join(sys.version.split(os.linesep))))
print('%*s: %s' % ($WIDTH_NAME, 'sys.api_version', sys.api_version))
print('%*s: %s' % ($WIDTH_NAME, 'platform.python_implementation', platform.python_implementation()))
print('%*s: %s' % ($WIDTH_NAME, 'platform.python_build', platform.python_build()))
print('%*s: %s' % ($WIDTH_NAME, 'platform.python_compiler', platform.python_compiler()))
print('Search path for modules:')
pprint.pprint(sys.path, indent = 4)
EOF
)
run_and_output_with_command 'python3 -c "$pycode"' "Python3"
run_and_output_with_command 'python2 -c "$pycode"' "Python2"
}
main "$@"