updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / ballistics-demo / setup.sh
blob4ad58cb7b299a783f7f7285a64895d76f5a961aa
1 #! /bin/sh
3 # Product setup script
5 # Go to the proper setup directory (if not already there)
6 cd `dirname $0`
8 # defaults
9 FATAL_ERROR="Fatal error, no tech support email configured in this setup"
10 # try to get root prior to running setup?
11 # 0: no
12 # 1: prompt, but run anyway if fails
13 # 2: require, abort if root fails
14 GET_ROOT=0
15 XSU_ICON=""
16 # You may want to set USE_XHOST to 1 if you want an X11 application to
17 # be launched with root privileges right after installation
18 USE_XHOST=0
19 # this is the message for su call, printf
20 SU_MESSAGE="You need to run this installation as the super user.\nPlease enter the root password."
22 if test -x /bin/su; then
23 SU_CMD=/bin/su
24 else
25 SU_CMD=/usr/bin/su
28 NULL=/dev/null
29 # See if we have the XPG4 utilities (Solaris)
30 if test -d /usr/xpg4/bin; then
31 PATH=/usr/xpg4/bin:$PATH
34 # Return the appropriate architecture string
35 DetectARCH()
37 status=1
38 case `uname -m` in
39 amd64 | x86_64)
40 echo "x86_64"
41 status=0;;
42 i?86 | i86*)
43 echo "x86"
44 status=0;;
45 90*/*)
46 echo "hppa"
47 status=0;;
49 case `uname -s` in
50 IRIX*)
51 echo "mips"
52 status=0;;
53 AIX*)
54 echo "ppc"
55 status=0;;
57 arch=`uname -p 2> /dev/null || uname -m`
58 if test "$arch" = powerpc; then
59 echo "ppc"
60 else
61 echo $arch
63 status=0;;
64 esac
65 esac
66 return $status
69 # Return the appropriate version string
70 DetectLIBC()
72 status=1
73 if [ `uname -s` != Linux ]; then
74 echo "glibc-2.1"
75 return $status
77 if [ -f `echo /lib/libc.so.6* | tail -n 1` ]; then
78 if fgrep GLIBC_2.1 /lib/libc.so.6* 2> $NULL >> $NULL; then
79 echo "glibc-2.1"
80 status=0
81 else
82 echo "glibc-2.0"
83 status=0
85 elif [ -f /lib/libc.so.5 ]; then
86 echo "libc5"
87 status=0
88 else
89 echo "unknown"
91 return $status
94 DetectOS()
96 os=`uname -s`
97 if test "$os" = "OpenUNIX"; then
98 echo SCO_SV
99 else
100 echo $os
102 return 0
105 # Detect the environment
106 arch=`DetectARCH`
107 libc=`DetectLIBC`
108 os=`DetectOS`
110 args=""
112 # Import preferences from a secondary script
113 if [ -f setup.data/config.sh ]; then
114 . setup.data/config.sh
115 elif [ -f SETUP.DAT/CONFIG.SH\;1 ]; then
116 # HP-UX and other systems unable to get LFN correctly
117 . SETUP.DAT/CONFIG.SH\;1
120 # Add some standard paths for compatibility
121 PATH=$PATH:/usr/ucb
123 # call setup with -auth when ran through su/xsu
124 auth=0
125 if [ "$1" = "-auth" ]
126 then
127 auth=1
128 shift
131 if [ "$auth" -eq 1 ]
132 then
133 # if root is absolutely required
134 # this happens if xsu/su execs setup.sh but it still doesn't have root rights
135 if [ "$GET_ROOT" -eq 2 ]
136 then
137 # NOTE TTimo: this causes the following error message in some cases:
138 # return: can only `return' from a function or sourced script
139 # BUT: in other cases, the return is legit, if you replace by an exit call, it's broken
140 exit 1
144 # Find the installation program
145 # try_run [-absolute] [-fatal] INSTALLER_NAME [PARAMETERS_PASSED]
146 # -absolute option: if what you are trying to execute has an absolute path
147 # NOTE: maybe try_run_absolute would be easier
148 # -fatal option: if you want verbose messages in case
149 # - the script could not be found
150 # - it's execution would fail
151 # INSTALLER_NAME: setup.gtk or setup
152 # PARAMETERS_PASSED: additional arguments passed to the setup script
153 try_run()
155 absolute=0
156 if [ "$1" = "-absolute" ]; then
157 absolute=1
158 shift
161 fatal=0
162 # older bash < 2.* don't like == operator, using =
163 if [ "$1" = "-fatal" ]; then
164 # got fatal
165 fatal=1
166 shift
169 setup=$1
170 shift
172 # First find the binary we want to run
173 failed=0
174 if [ "$absolute" -eq 0 ]
175 then
176 setup_bin="setup.data/bin/$os/$arch/$libc/$setup"
177 # trying $setup_bin
178 if [ ! -f "$setup_bin" ]; then
179 setup_bin="setup.data/bin/$os/$arch/$setup"
180 # libc dependant version failed, trying again
181 if [ ! -f "$setup_bin" ]; then
182 failed=1
185 if [ "$failed" -eq 1 ]; then
186 if [ "$fatal" -eq 1 ]; then
187 cat <<__EOF__
188 This installation doesn't support $libc on $os / $arch
189 (tried to run $setup)
190 $FATAL_ERROR
191 __EOF__
193 return $failed
196 # Try to run the binary ($setup_bin)
197 # The executable is here but we can't execute it from CD
198 # NOTE TTimo: this is dangerous, we also use $setup to store the name of the try_run
199 setup="$HOME/.setup$$"
200 rm -f "$setup"
201 cp "$setup_bin" "$setup"
202 chmod 700 "$setup"
203 trap "rm -f $setup" 1 2 3 15
205 # echo Running "$setup" "$@"
206 if [ "$fatal" -eq 0 ]; then
207 "$setup" "$@"
208 failed="$?"
209 else
210 "$setup" "$@" 2>> $NULL
211 failed="$?"
213 if [ "$absolute" -eq 0 ]
214 then
215 # don't attempt removal when we are passed an absolute path
216 # no, I don't want to imagine a faulty try_run as root on /bin/su
217 rm -f "$setup"
219 return "$failed"
222 # if we have not been through the auth yet, and if we need to get root, then prompt
223 if [ "$auth" -eq 0 ] && [ "$GET_ROOT" -ne 0 ]
224 then
225 GOT_ROOT=`id -u`
226 if [ "$GOT_ROOT" != "0" ]
227 then
228 if [ "$USE_XHOST" -eq 1 ]; then
229 xhost +127.0.0.1 2> $NULL > $NULL
231 try_run xsu -e -a -u root -c "sh `pwd`/setup.sh -auth" $XSU_ICON
232 status="$?"
233 # echo "got $status"
234 # if try_run successfully executed xsu, it will return xsu's exit code
235 # xsu returns 2 if ran and cancelled (i.e. the user 'doesn't want' to auth)
236 # it will return 0 if the command was executed correctly
237 # summing up, if we get 1, something failed
238 if [ "$status" -eq 0 ]
239 then
240 # the auth command was properly executed
241 exit 0
242 elif [ "$status" -eq 1 ]
243 then
244 # xsu wasn't found, or failed to run
245 # if xsu actually ran and the auth was cancelled, $status is 2
246 # try with su
247 printf "$SU_MESSAGE\n"
248 try_run -absolute $SU_CMD root -c "export DISPLAY=$DISPLAY;sh `pwd`/setup.sh -auth"
249 status="$?"
250 if [ "$status" -eq 0 ]; then
251 # the auth command was properly executed
252 exit 0
253 else
254 exit 1
256 elif [ "$status" -eq 3 ]
257 then
258 # the auth failed or was canceled
259 # we don't want to even start the setup if not root
260 echo "Please run this installation as the super user"
261 exit 1
263 # continue running as is
267 # See if we can find the LGP update and uninstall tools
268 CheckPATH()
270 echo "$PATH" | tr ':' '\n' | sed -e 's/^$/./g' -e "s,~,$HOME," |
271 while read path
272 do if [ -f "$path/$1" -a -x "$path/$1" ]; then
273 echo "$path/$1"
274 break
276 done
279 # Try to run the setup program
280 try_run setup $args $*
281 status=$?
282 if [ $status -eq 2 ] || [ $status -eq 127 ]; then # setup.gtk couldn't connect to X11 server - ignore
283 try_run setup $args $* || {
284 if [ $status -ne 2 ]; then
285 echo "The setup program seems to have failed on $arch/$libc"
286 echo
287 echo $FATAL_ERROR
289 status=1
292 exit $status