1#!/bin/sh
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements.  See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership.  The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License.  You may obtain a copy of the License at
9#
10#   http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied.  See the License for the
16# specific language governing permissions and limitations
17# under the License.
18
19PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
20HOSTNAME=`uname -n`
21OS=`uname -s`
22CPUTYPE=`uname -p`
23BITNESS=32
24
25LS=/bin/ls
26OSFAMILY=
27DATETIME=`date -u +'%Y-%m-%d %H:%M:%S'`
28
29if [ "${OS}" = "SunOS" ]; then
30   BITNESS=`isainfo -b`
31   OSFAMILY="SUNOS"
32   OSNAME="SunOS"
33   OSBUILD=`head -1 /etc/release | sed -e "s/^ *//"`
34   CPUNUM=`/usr/sbin/psrinfo -v | grep "^Status of" | wc -l | sed 's/^ *//'`
35else
36   if [ "${OS}" = "Darwin" ]; then
37      sysctl hw.cpu64bit_capable | grep -q "1$"
38      if [ $? -eq 0 ]; then
39         BITNESS=64
40      fi
41   else
42      uname -a | egrep "x86_64|WOW64|sparc64" >/dev/null
43      if [ $? -eq 0 ]; then
44         BITNESS=64
45      fi
46   fi
47
48   if [ -f "/etc/sun-release" ]; then
49      OSNAME="${OS}-JDS"
50      OSBUILD=`head -1 /etc/sun-release`
51   elif [ -f /etc/SuSE-release ]; then
52      OSNAME="${OS}-SuSE"
53      OSBUILD=`cat /etc/SuSE-release | tr "\n" " "`;
54   elif [ -f /etc/redhat-release ]; then
55      OSNAME="${OS}-Redhat"
56      OSBUILD=`head -1 /etc/redhat-release`
57   elif [ -f /etc/gentoo-release ]; then
58      OSNAME="${OS}-Gentoo"
59      OSBUILD=`head -1 /etc/gentoo-release`
60   elif [ -f /etc/lsb-release ]; then
61      OSNAME="${OS}-"`cat /etc/lsb-release | grep DISTRIB_ID | sed 's/.*=//'`
62      OSBUILD=`cat /etc/lsb-release | grep DISTRIB_DESCRIPTION | sed 's/.*=//' | sed 's/"//g'`
63   fi
64fi
65
66OSFAMILY=${OSFAMILY:-`echo ${OS} | grep _NT- >/dev/null && echo WINDOWS`}
67OSFAMILY=${OSFAMILY:-`test "$OS" = "Darwin" && echo MACOSX`}
68OSFAMILY=${OSFAMILY:-`test "$OS" = "Linux" && echo LINUX`}
69OSFAMILY=${OSFAMILY:-${OS}}
70
71CPUFAMILY=`(echo ${CPUTYPE} | egrep "^i|x86_64|athlon|Intel" >/dev/null && echo x86) || echo ${CPUTYPE}`
72if [ "${CPUFAMILY}" != "x86" -a "${CPUFAMILY}" != "sparc" -a "${CPUFAMILY}" != "sparc64" ]; then
73   CPUTYPE=`uname -m`
74fi
75CPUFAMILY=`(echo ${CPUTYPE} | egrep "^i|x86_64|athlon|Intel" >/dev/null && echo x86) || echo ${CPUTYPE}`
76if [ "${CPUFAMILY}" = "sparc64" ]; then
77   CPUFAMILY="sparc"
78fi
79
80USERDIRBASE=${HOME}
81
82if [ "${OSFAMILY}" = "LINUX" ]; then
83   if [ "${CPUFAMILY}" = "sparc" ]; then
84     CPUNUM=`cat /proc/cpuinfo | grep 'ncpus active' | sed 's/[^:]*.[ ]*//'`
85   else
86     CPUNUM=`cat /proc/cpuinfo | grep processor | wc -l | sed 's/^ *//'`
87   fi
88elif [ "${OSFAMILY}" = "WINDOWS" ]; then
89   CPUNUM=$NUMBER_OF_PROCESSORS
90   OSNAME=`uname`
91   USERDIRBASE=${USERPROFILE}
92elif [ "${OSFAMILY}" = "MACOSX" ]; then
93   CPUNUM=`hostinfo | awk '/processor.*logical/{print $1}'`
94   OSNAME="MacOSX"
95   OSBUILD=`hostinfo | sed -n '/kernel version/{n;p;}' | sed 's/[	 ]*\([^:]*\).*/\1/'`
96elif [ "${OSFAMILY}" = "FreeBSD" ]; then
97   CPUNUM=`sysctl hw.ncpu | awk '{print $2}'`
98   OSNAME=`sysctl -n  kern.ostype`
99   OSBUILD=`sysctl -n kern.osrelease`
100fi
101
102wx_fail() {
103    tmp="${1}/wx_test"
104    touch ${tmp} 2> /dev/null
105    if [ $? -eq 0 ]; then
106        chmod u+x ${tmp} 2> /dev/null
107        if [ -x ${tmp} ]; then
108            rm ${tmp} 2> /dev/null
109            return 1
110        fi
111        rm ${tmp} 2> /dev/null
112    fi
113
114    return 0
115}
116
117USER=${USER:-`logname 2>/dev/null`}
118USER=${USER:-${USERNAME}}
119USER_D=`echo ${USER} | sed "s/[\\/]/_/g"`
120TMPBASE=${TMPBASE:-/var/tmp}
121
122SUFFIX=0
123TMPDIRBASE=${TMPBASE}/dlight_${USER_D}
124
125if wx_fail ${TMPBASE}; then
126    if wx_fail ${TMPDIRBASE}; then
127        TMPBASE=/tmp
128        TMPDIRBASE=${TMPBASE}/dlight_${USER_D}
129    fi
130fi
131
132mkdir -p ${TMPDIRBASE}
133while [ ${SUFFIX} -lt 5 ]; do
134    if wx_fail ${TMPDIRBASE}; then
135        echo "Warning: TMPDIRBASE is not writable: ${TMPDIRBASE}">&2
136        SUFFIX=`expr 1 + ${SUFFIX}`
137        TMPDIRBASE=${TMPBASE}/dlight_${USER_D}_${SUFFIX}
138        /bin/mkdir -p ${TMPDIRBASE} 2>/dev/null
139    else
140        break
141    fi
142done
143
144if wx_fail ${TMPDIRBASE}; then
145    :
146else
147    SUFFIX=0
148    TMPBASE=${TMPDIRBASE}
149    TMPDIRBASE=${TMPBASE}/${NB_KEY}
150    mkdir -p ${TMPDIRBASE}
151    while [ ${SUFFIX} -lt 5 ]; do
152        if wx_fail ${TMPDIRBASE}; then
153            echo "Warning: TMPDIRBASE is not writable: ${TMPDIRBASE}">&2
154            SUFFIX=`expr 1 + ${SUFFIX}`
155            TMPDIRBASE=${TMPBASE}/${NB_KEY}_${SUFFIX}
156            /bin/mkdir -p ${TMPDIRBASE} 2>/dev/null
157        else
158            break
159        fi
160    done
161fi
162
163if wx_fail ${TMPDIRBASE}; then
164    TMPDIRBASE=${TMPBASE}
165fi
166
167if wx_fail ${TMPDIRBASE}; then
168    echo "Error: TMPDIRBASE is not writable: ${TMPDIRBASE}">&2
169fi
170
171ENVFILE="${TMPDIRBASE}/env"
172
173ID=`LC_MESSAGES=C /usr/bin/id`
174
175echo BITNESS=${BITNESS}
176echo CPUFAMILY=${CPUFAMILY}
177echo CPUNUM=${CPUNUM}
178echo CPUTYPE=${CPUTYPE}
179echo HOSTNAME=${HOSTNAME}
180echo OSNAME=${OSNAME}
181echo OSBUILD=${OSBUILD}
182echo OSFAMILY=${OSFAMILY}
183echo USER=${USER}
184echo SH=${SHELL}
185echo USERDIRBASE=${USERDIRBASE}
186echo TMPDIRBASE=${TMPDIRBASE}
187echo DATETIME=${DATETIME}
188echo ENVFILE=${ENVFILE}
189echo ID=${ID}
190exit 0
191