forked from brAthena/brAthena20180924
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sysinfogen.sh
261 lines (230 loc) · 7.24 KB
/
sysinfogen.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/bin/sh
# Projeto brAthena
# www.brathena.org
# Base Author: Haru
# Fix EOL 14102015
do_fail() {
echo 'Error writing output file'
exit 1
}
cleanstring() {
if [ "$( echo "x x" | sed -e 's/[[:space:]]//g' )" = "x x" ]; then
# Workaround for non-POSIX-compliant systems that lack [[:space:]] (Solaris)
echo "$@" | sed -e 's/"/ /g' -e 's/[ ][ ]*/ /g' -e 's/^[ ]*//g' -e 's/[ ]*$//g'
else
echo "$@" | sed -e 's/"/ /g' -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g'
fi
}
if [ -z "$1" ]; then
echo 'No output file specified'
exit 1
fi
OUTFILE="$1"
shift
if ! touch "$OUTFILE"; then
echo 'Cannot create output file'
exit 1
fi
cat > "$OUTFILE" << EOF
// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
// See the LICENSE file
// This file was automatically generated. Any edit to it will be lost.
EOF
[ $? -eq 0 ] || do_fail
BRATHENA_PLATFORM="$( uname -s )"
BRATHENA_CORES="0"
BRATHENA_CPU="Unknown"
case $BRATHENA_PLATFORM in
Linux)
DIST=''
DESCRIPTION=''
REV=''
if type lsb_release >/dev/null 2>&1; then
LSBINFO="$( lsb_release -a 2>/dev/null )"
DIST="$( cleanstring "$( echo "$LSBINFO" | grep '^Distributor ID:' | cut -d: -f2- )" )"
DESCRIPTION="$( echo "$LSBINFO" | grep '^Description:' | cut -d: -f2- | sed 's/Enterprise Linux Enterprise Linux/Oracle Linux/' )"
fi
if [ -z "$DIST" ] || [ "$DIST" = "Gentoo" ]; then
if [ -f /etc/gentoo-release ]; then
# "Gentoo Base System release 2.2"
DIST='Gentoo'
DESCRIPTION="$( head -n 1 /etc/gentoo-release )"
REV=''
elif [ -f /etc/arch-release ]; then
# empty release file
DIST='ArchLinux'
DESCRIPTION=''
REV=''
elif [ -f /etc/vmware-release ]; then
# "VMware ESX Server 3" or "VMware ESX 4.0 (Kandinsky)"
DIST="VMWare"
DESCRIPTION="$( head -n 1 /etc/vmware-release )"
REV=''
elif [ -f /etc/debian_version ]; then
# "wheezy/sid"
DIST="Debian"
DESCRIPTION="Debian GNU/Linux $( head -n 1 /etc/debian_version )"
REV=''
elif [ -f /etc/fedora-release ]; then
# "Fedora release 9 (Sulphur)"
DIST="Fedora"
DESCRIPTION="$( head -n 1 /etc/fedora-release )"
REV=''
elif [ -f /etc/knoppix_version ]; then
# "3.2 2003-04-15"
DIST="Knoppix"
REV="Knoppix GNU/Linux $( head -n 1 /etc/knoppix_version )"
DESCRIPTION=''
elif [ -f /etc/mandriva-release ]; then
# "Mandriva Linux release 2010.1 (Official) for x86_64"
DIST="Mandriva"
DESCRIPTION="$( head -n 1 /etc/mandriva-release )"
REV=''
elif [ -f /etc/mandrake-release ]; then
# "Mandrakelinux release 10.1 (Community) for i586"
DIST="Mandrake"
DESCRIPTION="$( head -n 1 /etc/mandrake-release )"
REV=''
elif [ -f /etc/oracle-release ]; then
# "Oracle Linux Server release 6.3"
DIST="Oracle"
DESCRIPTION="$( head -n 1 /etc/oracle-release )"
REV=''
elif [ -f /etc/centos-release ]; then
# "CentOS Linux release 6.0 (Final)"
DIST="CentOS"
DESCRIPTION="$( head -n 1 /etc/centos-release )"
REV=''
elif [ -f /etc/redhat-release ]; then
# "Red Hat Enterprise Linux Server release 5 (Tikanga)"
DIST="RedHat"
DESCRIPTION="$( head -n 1 /etc/redhat-release )"
REV=''
elif [ -f /etc/slackware-version ]; then
DIST="Slackware"
DESCRIPTION="$( head -n 1 /etc/slackware-version )"
REV=''
elif [ -f /etc/slackware-release ]; then
DIST="Slackware"
DESCRIPTION="$( head -n 1 /etc/slackware-release )"
REV=''
elif [ -f /etc/SuSE-release ]; then
# "SUSE Linux Enterprise Server 11 (x86_64)"
# Note: it may contain several extra lines
DIST="SuSE"
DESCRIPTION="$( head -n 1 /etc/SuSE-release )"
REV=''
elif [ -f /etc/trustix-release ]; then
# "Trustix Secure Linux release 2.0 (Cloud)"
DIST="Trustix"
DESCRIPTION="$( head -n 1 /etc/trustix-release )"
REV=''
else
DIST='Unknown'
DESCRIPTION=''
REV=''
fi
fi
if [ -n "$DESCRIPTION" ]; then
DIST="$DESCRIPTION"
fi
BRATHENA_OSVERSION="$DIST"
BRATHENA_CPU="$( cat /proc/cpuinfo | grep "model name" | head -n 1 | cut -d: -f2- )"
BRATHENA_CORES="$( grep '^processor' /proc/cpuinfo | wc -l )"
;;
Darwin)
BRATHENA_PLATFORM="Mac OS X"
if type sw_vers >/dev/null 2>&1; then
BRATHENA_OSVERSION="$( sw_vers -productName ) $( sw_vers -productVersion ) $( sw_vers -buildVersion )"
else
BRATHENA_OSVERSION="Unknown"
fi
if type system_profiler >/dev/null 2>&1; then
HWDATA="$( system_profiler SPHardwareDataType )"
HWDATA_CPU="$( echo "$HWDATA" | grep "Processor Name:" | cut -d: -f2- )"
HWDATA_CPUSPEED="$( cleanstring "$( echo "$HWDATA" | grep "Processor Speed:" | cut -d: -f2- )" )"
BRATHENA_CORES="$( echo "$HWDATA" | grep "Total Number of Cores:" | cut -d: -f2- )"
BRATHENA_CPU="${HWDATA_CPU} (${HWDATA_CPUSPEED})"
fi
;;
SunOS)
BRATHENA_PLATFORM="Solaris"
BRATHENA_OSVERSION="${BRATHENA_PLATFORM} $( uname -r ) ($( uname -p) $(uname -v))"
;;
AIX)
BRATHENA_OSVERSION="AIX $( oslevel ) ($(`oslevel -r`))"
;;
CYGWIN*)
BRATHENA_PLATFORM="Cygwin Windows"
BRATHENA_OSVERSION="$( cleanstring "$( uname -s )" )"
BRATHENA_CPU="$( cat /proc/cpuinfo | grep "model name" | head -n 1 | cut -d: -f2- )"
BRATHENA_CORES="$( grep '^processor' /proc/cpuinfo | wc -l )"
;;
OpenBSD)
BRATHENA_OSVERSION="${BRATHENA_PLATFORM} $( uname -r ) ($( uname -p) $(uname -v))"
BRATHENA_CPU="$( sysctl hw.model | cut -d= -f2- )"
BRATHENA_CORES="$( sysctl hw.ncpu | cut -d= -f2- )"
;;
FreeBSD)
BRATHENA_OSVERSION="${BRATHENA_PLATFORM} $( uname -r ) ($( uname -p))"
BRATHENA_CPU="$( sysctl hw.model | cut -d: -f2- )"
BRATHENA_CORES="$( sysctl hw.ncpu | cut -d: -f2- )"
;;
NetBSD)
BRATHENA_OSVERSION="${BRATHENA_PLATFORM} $( uname -r ) ($( uname -p))"
BRATHENA_CPU="$( sysctl hw.model | cut -d= -f2- )"
BRATHENA_CORES="$( sysctl hw.ncpu | cut -d= -f2- )"
;;
*)
BRATHENA_OSVERSION="Unknown"
;;
esac
cat >> "$OUTFILE" << EOF
// Platform (uname -s)
#define SYSINFO_PLATFORM "$( cleanstring "${BRATHENA_PLATFORM}" )"
// Operating System version (Platform-dependent)
#define SYSINFO_OSVERSION "$( cleanstring "${BRATHENA_OSVERSION}" )"
// CPU Model (Platform-dependent)
#define SYSINFO_CPU "$( cleanstring "${BRATHENA_CPU}" )"
// CPU Cores (Platform-dependent)
#define SYSINFO_CPUCORES ( $( cleanstring "${BRATHENA_CORES}" ) )
EOF
[ $? -eq 0 ] || do_fail
BRATHENA_ARCH="$( uname -m )"
cat >> "$OUTFILE" << EOF
// OS Architecture (uname -m)
#define SYSINFO_ARCH "$( cleanstring "${BRATHENA_ARCH}" )"
EOF
[ $? -eq 0 ] || do_fail
BRATHENA_CFLAGS="$@"
BRATHENA_CFLAGS="$( echo "${BRATHENA_CFLAGS}" | sed 's/"//g' )"
cat >> "$OUTFILE" << EOF
// Compiler Flags
#define SYSINFO_CFLAGS "$( cleanstring "${BRATHENA_CFLAGS}" )"
EOF
[ $? -eq 0 ] || do_fail
BRATHENA_VCSREV=""
if [ -d .git ]; then
BRATHENA_VCSTYPE="VCSTYPE_GIT"
if type git >/dev/null 2>&1; then
BRATHENA_VCSREV="$( git rev-parse HEAD )"
else
BRATHENA_VCSREV="Unknown"
fi
elif [ -d .svn ]; then
BRATHENA_VCSTYPE="VCSTYPE_SVN"
if type svnversion >/dev/null 2>&1; then
BRATHENA_VCSREV="$( svnversion )"
else
BRATHENA_VCSREV="Unknown"
fi
else
BRATHENA_VCSTYPE="VCSTYPE_NONE"
fi
cat >> "$OUTFILE" << EOF
// VCS Type
#define SYSINFO_VCSTYPE ${BRATHENA_VCSTYPE}
// VCS Revision
#define SYSINFO_VCSREV "$( cleanstring "${BRATHENA_VCSREV}" )"
EOF
[ $? -eq 0 ] || do_fail