]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/sys/linux/setup/image-base/setup.sh
hello world
[icculus/iodoom3.git] / neo / sys / linux / setup / image-base / setup.sh
1 #! /bin/sh
2 #
3 # Product setup script
4 #
5 # Go to the proper setup directory (if not already there)
6 cd `dirname $0`
7
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."
21
22 NULL=/dev/null
23 # See if we have the XPG4 utilities (Solaris)
24 if test -d /usr/xpg4/bin; then
25         PATH=/usr/xpg4/bin:$PATH
26 fi
27
28 # Return the appropriate architecture string
29 DetectARCH()
30 {
31         status=1
32         case `uname -m` in
33             amd64 | x86_64)
34                 echo "amd64"
35                 status=0;;
36             i?86 | i86*)
37                 echo "x86"
38                 status=0;;
39             90*/*) 
40                 echo "hppa"
41                 status=0;;
42             *)
43                 case `uname -s` in
44                     IRIX*)
45                         echo "mips"
46                         status=0;;
47             AIX*)
48             echo "ppc"
49             status=0;;
50                     *)
51                         arch=`uname -p 2> /dev/null || uname -m`
52                         if test "$arch" = powerpc; then
53                                 echo "ppc"
54                         else
55                                 echo $arch
56                         fi
57                         status=0;;
58                 esac
59         esac
60         return $status
61 }
62
63 # Return the appropriate version string
64 DetectLIBC()
65 {
66         status=1
67         if [ `uname -s` != Linux ]; then
68                 echo "glibc-2.1"
69                 return $status
70         fi
71         if [ -f `echo /lib/libc.so.6* | tail -n 1` ]; then
72                 # I'm not using glibc-specific binaries
73                 # this step even fails on amd64 gentoo, only has GLIBC_2.2 2.3 in it's strings
74                 echo "glibc-2.1"
75                 status=0
76 #               if [ fgrep GLIBC_2.1 /lib/libc.so.6* 2> $NULL >> $NULL ]; then
77 #                       echo "glibc-2.1"
78 #                       status=0
79 #               else    
80 #                       echo "glibc-2.0"
81 #                       status=0
82 #               fi        
83         elif [ -f /lib/libc.so.5 ]; then
84                         echo "libc5"
85                         status=0
86         else
87                         echo "unknown"
88         fi
89         return $status
90 }
91
92 DetectOS()
93 {
94         os=`uname -s`
95         if test "$os" = "OpenUNIX"; then
96                 echo SCO_SV
97         else
98                 echo $os
99         fi
100         return 0
101 }
102
103 # Detect the environment
104 arch=`DetectARCH`
105 libc=`DetectLIBC`
106 os=`DetectOS`
107
108 args=""
109
110 # Import preferences from a secondary script
111 if [ -f setup.data/config.sh ]; then
112     . setup.data/config.sh
113 elif [ -f SETUP.DAT/CONFIG.SH\;1 ]; then
114         # HP-UX and other systems unable to get LFN correctly
115         . SETUP.DAT/CONFIG.SH\;1
116 fi
117
118 # Add some standard paths for compatibility
119 PATH=$PATH:/usr/ucb
120
121 # call setup with -auth when ran through su/xsu
122 auth=0
123 if [ "$1" = "-auth" ]
124 then
125   auth=1
126   shift
127 fi
128
129 # Find the installation program
130 # try_run [-absolute] [-fatal] INSTALLER_NAME [PARAMETERS_PASSED]
131 #   -absolute option: if what you are trying to execute has an absolute path
132 #   NOTE: maybe try_run_absolute would be easier
133 #   -fatal option: if you want verbose messages in case
134 #      - the script could not be found
135 #      - it's execution would fail
136 #   INSTALLER_NAME: setup.gtk or setup
137 #   PARAMETERS_PASSED: additional arguments passed to the setup script
138 try_run()
139 {
140     absolute=0
141     if [ "$1" = "-absolute" ]; then
142       absolute=1
143       shift
144     fi
145
146     fatal=0
147     # older bash < 2.* don't like == operator, using =
148     if [ "$1" = "-fatal" ]; then
149       # got fatal
150       fatal=1
151       shift
152     fi
153
154     setup=$1
155     shift
156     
157     # First find the binary we want to run
158     failed=0
159     if [ "$absolute" -eq 0 ]
160     then
161       setup_bin="setup.data/bin/$os/$arch/$libc/$setup"
162       # trying $setup_bin
163       if [ ! -f "$setup_bin" ]; then
164           setup_bin="setup.data/bin/$os/$arch/$setup"
165                 # libc dependant version failed, trying again
166           if [ ! -f "$setup_bin" ]; then
167               failed=1
168           fi
169       fi
170       if [ "$failed" -eq 1 ]; then
171           if [ "$fatal" -eq 1 ]; then
172               cat <<__EOF__
173 This installation doesn't support $libc on $os / $arch
174 (tried to run $setup)
175 $FATAL_ERROR
176 __EOF__
177           fi
178           return $failed
179       fi
180
181       # Try to run the binary ($setup_bin)
182       # The executable is here but we can't execute it from CD
183       # NOTE TTimo: this is dangerous, we also use $setup to store the name of the try_run
184       setup="$HOME/.setup$$"
185       rm -f "$setup"
186       cp "$setup_bin" "$setup"    
187       chmod 700 "$setup"
188           trap "rm -f $setup" 1 2 3 15
189     fi
190         # echo Running "$setup" "$@"
191     if [ "$fatal" -eq 0 ]; then
192         "$setup" "$@"
193         failed="$?"
194     else
195         "$setup" "$@" 2>> $NULL
196         failed="$?"
197     fi
198     if [ "$absolute" -eq 0 ]
199     then
200       # don't attempt removal when we are passed an absolute path
201       # no, I don't want to imagine a faulty try_run as root on /bin/su
202       rm -f "$setup"
203     fi
204     return "$failed"
205 }
206
207 if [ "$GET_ROOT" -eq 3 ]
208 then
209         GOT_ROOT=`id -u`
210         if [ "$GOT_ROOT" != "0" ]
211         then
212                 printf "$SU_MESSAGE\n"
213                 echo "Press Enter to continue or Ctrl-C to abort"
214                 read
215         fi
216         GET_ROOT=0
217 fi
218
219 # if we have not been through the auth yet, and if we need to get root, then prompt
220 if [ "$auth" -eq 0 ] && [ "$GET_ROOT" -ne 0 ]
221 then
222   GOT_ROOT=`id -u`
223   if [ "$GOT_ROOT" != "0" ]
224   then
225         if [ "$USE_XHOST" -eq 1 ]; then
226                 xhost +127.0.0.1 2> $NULL > $NULL
227         fi
228     if [ "$GET_ROOT" -eq 1 ]
229     then
230       try_run xsu -e -a -u root -c "sh `pwd`/setup.sh -auth" $XSU_ICON -m "$XSU_MESSAGE"
231     else
232     try_run xsu -e -a -u root -c "sh `pwd`/setup.sh -auth" $XSU_ICON
233     fi
234     status="$?"
235     # echo "got $status"
236     # if try_run successfully executed xsu, it will return xsu's exit code
237     # xsu returns 2 if ran and cancelled (i.e. the user 'doesn't want' to auth)
238     # it will return 0 if the command was executed correctly
239     # summing up, if we get 1, something failed
240     if [ "$status" -eq 0 ]
241     then
242       # the auth command was properly executed
243       exit 0
244     elif [ "$status" -eq 1 ]
245     then
246       # xsu wasn't found, or failed to run
247       # if xsu actually ran and the auth was cancelled, $status is > 1
248       # try with su
249       # su will return 1 if auth failed
250       # we need to distinguish between su auth failed and su working, and still get setup.sh return code
251       printf "$SU_MESSAGE\n"
252       try_run -absolute /bin/su root -c "export DISPLAY=$DISPLAY;sh `pwd`/setup.sh -auth"
253       status="$?"
254           if [ "$status" -eq 1 ] && [ "$GET_ROOT" -eq 1 ]
255       then
256         echo "Running setup as user"
257       else
258         exit $status
259       fi
260     elif [ "$status" -eq 3 ]
261     then
262       if [ "$GET_ROOT" -eq 1 ]
263       then
264         echo "Running setup as user"
265       else
266         # the auth failed or was canceled
267         # we don't want to even start the setup if not root
268         echo "Please run this installation as the super user"
269         exit 1
270       fi
271     fi
272     # continue running as is
273   fi
274 fi
275
276 # run the setup program (setup.gtk first, then setup)
277 # except when trying setup.gtk first then console setup, always exit with 0
278 # if the setup was cancelled, it is not our problem
279 try_run setup.gtk $args $*
280 status="$?"
281 if [ "$status" -ne 0 ] && [ "$status" -ne 3 ]; then  # setup.gtk couldn't connect to X11 server - ignore
282 try_run setup $args $*
283   status="$?"
284   if [ "$auth" -eq 1 ] && [ "$status" -ne 0 ]
285   then
286     # distinguish between failed su and failed su'ed setup.sh
287     exit 2
288   fi
289   exit $status
290 fi