]> icculus.org git repositories - divverent/netradiant.git/blob - setup/linux/setup_image/setup.sh.in
git-svn-id: svn://svn.icculus.org/netradiant/trunk@55 61c419a2-8eb2-4b30-bcec-8cead03...
[divverent/netradiant.git] / setup / linux / setup_image / setup.sh.in
1 dnl `uname -m` quoting is a nightmare
2 dnl <sander> TTimo: You could do:  &#96;uname -a&#96;
3 changequote([[, ]])
4
5 #! /bin/sh
6 #
7 # Product setup script
8 #
9 # TTimo - run in fink environement
10 # I am not entirely sure this is needed
11 # but in any case, it doesn't hurt
12 ifdef([[M4_OSX]], [[source /sw/bin/init.sh]])
13 # Go to the proper setup directory (if not already there)
14 cd `dirname $0`
15
16 # defaults
17 FATAL_ERROR="Fatal error, no tech support email configured in this setup"
18 # try to get root prior to running setup?
19 # 0: no
20 # 1: prompt, but run anyway if fails
21 # 2: require, abort if root fails
22 GET_ROOT=0
23 XSU_ICON=""
24 # You may want to set USE_XHOST to 1 if you want an X11 application to
25 # be launched with root privileges right after installation
26 USE_XHOST=0
27 # this is the message for su call, printf
28 SU_MESSAGE="You need to run this installation as the super user.\nPlease enter the root password."
29
30 NULL=/dev/null
31 # See if we have the XPG4 utilities (Solaris)
32 if test -d /usr/xpg4/bin; then
33         PATH=/usr/xpg4/bin:$PATH
34 fi
35
36 # Return the appropriate architecture string
37 DetectARCH()
38 {
39         status=1
40         case `uname -m` in
41             i?86)
42                 echo "x86"
43                 status=0;;
44             90*/*) 
45                 echo "hppa"
46                 status=0;;
47             *)
48                 case `uname -s` in
49                     IRIX*)
50                         echo "mips"
51                         status=0;;
52                     *)
53                         arch=`uname -p 2> /dev/null || uname -m`
54                         if test "$arch" = powerpc; then
55                                 echo "ppc"
56                         else
57                                 echo $arch
58                         fi
59                         status=0;;
60                 esac
61         esac
62         return $status
63 }
64
65 # Return the appropriate version string
66 DetectLIBC()
67 {
68     status=1
69           if [ `uname -s` != Linux ]; then
70                   echo "glibc-2.1"
71                   return $status
72           fi
73       if [ -f `echo /lib/libc.so.6* | tail -1` ]; then
74               if fgrep GLIBC_2.1 /lib/libc.so.6* 2> $NULL >> $NULL; then
75                       echo "glibc-2.1"
76                       status=0
77               else    
78                       echo "glibc-2.0"
79                       status=0
80               fi        
81       elif [ -f /lib/libc.so.5 ]; then
82               echo "libc5"
83               status=0
84       else
85               echo "unknown"
86       fi
87       return $status
88 }
89
90 DetectOS()
91 {
92         os=`uname -s`
93         if test "$os" = "OpenUNIX"; then
94                 echo SCO_SV
95         else
96                 echo $os
97         fi
98         return 0
99 }
100
101 # Detect the environment
102 arch=`DetectARCH`
103 libc=`DetectLIBC`
104 os=`DetectOS`
105
106 # Import preferences from a secondary script
107 if [ -f setup.data/config.sh ]; then
108     . setup.data/config.sh
109 elif [ -f SETUP.DAT/CONFIG.SH\;1 ]; then
110         # HP-UX and other systems unable to get LFN correctly
111         . SETUP.DAT/CONFIG.SH\;1
112 fi
113
114 # Add some standard paths for compatibility
115 PATH=$PATH:/usr/ucb
116
117 # call setup with -auth when ran through su/xsu
118 auth=0
119 if [ "$1" = "-auth" ]
120 then
121   auth=1
122   [[shift]]
123 fi
124
125 if [ "$auth" -eq 1 ]
126 then
127   # if root is absolutely required
128   # this happens if xsu/su execs setup.sh but it still doesn't have root rights
129   if [ "$GET_ROOT" -eq 2 ]
130   then
131     # NOTE TTimo: this causes the following error message in some cases:
132     # return: can only `return' from a function or sourced script
133     # BUT: in other cases, the return is legit, if you replace by an exit call, it's broken
134     return 1
135   fi
136 fi
137
138 # Feel free to add some additional command-line arguments for setup here.
139 args=""
140
141 # Find the installation program
142 # try_run [-absolute] [-fatal] INSTALLER_NAME [PARAMETERS_PASSED]
143 #   -absolute option: if what you are trying to execute has an absolute path
144 #   NOTE: maybe try_run_absolute would be easier
145 #   -fatal option: if you want verbose messages in case
146 #      - the script could not be found
147 #      - it's execution would fail
148 #   INSTALLER_NAME: setup.gtk or setup
149 #   PARAMETERS_PASSED: additional arguments passed to the setup script
150 try_run()
151 {
152     absolute=0
153     if [ "$1" = "-absolute" ]; then
154       absolute=1
155       [[shift]]
156     fi
157
158     fatal=0
159     # older bash < 2.* don't like == operator, using =
160     if [ "$1" = "-fatal" ]; then
161       # got fatal
162       fatal=1
163       [[shift]]
164     fi
165
166     setup=$1
167     [[shift]]
168     
169     # First find the binary we want to run
170     failed=0
171     if [ "$absolute" -eq 0 ]
172     then
173       setup_bin="setup.data/bin/$os/$arch/$libc/$setup"
174       # trying $setup_bin
175       if [ ! -f "$setup_bin" ]; then
176           setup_bin="setup.data/bin/$os/$arch/$setup"
177                 # libc dependant version failed, trying again
178           if [ ! -f "$setup_bin" ]; then
179               failed=1
180           fi
181       fi
182       if [ "$failed" -eq 1 ]; then
183           if [ "$fatal" -eq 1 ]; then
184               cat <<__EOF__
185 This installation doesn't support $libc on $os / $arch
186 (tried to run $setup)
187 $FATAL_ERROR
188 __EOF__
189           fi
190           return $failed
191       fi
192
193       # Try to run the binary ($setup_bin)
194       # The executable is here but we can't execute it from CD
195       # NOTE TTimo: this is dangerous, we also use $setup to store the name of the try_run
196       setup="$HOME/.setup$$"
197       rm -f "$setup"
198       cp "$setup_bin" "$setup"    
199       chmod 700 "$setup"    
200     fi
201         # echo Running "$setup" "$@"
202     if [ "$fatal" -eq 0 ]; then
203         "$setup" "$@"
204         failed="$?"
205     else
206         "$setup" "$@" 2>> $NULL
207         failed="$?"
208     fi
209     if [ "$absolute" -eq 0 ]
210     then
211       # don't attempt removal when we are passed an absolute path
212       # no, I don't want to imagine a faulty try_run as root on /bin/su
213       rm -f "$setup"
214     fi
215     return "$failed"
216 }
217
218 # if we have not been through the auth yet, and if we need to get root, then prompt
219 if [ "$auth" -eq 0 ] && [ "$GET_ROOT" -ne 0 ]
220 then
221   GOT_ROOT=`id -u`
222   if [ "$GOT_ROOT" != "0" ]
223   then
224
225         if [ "$USE_XHOST" -eq 1 ]; then
226                 xhost +127.0.0.1 2> $NULL > $NULL
227         fi
228     try_run xsu -e -a -u root -c "sh `pwd`/setup.sh -auth" $XSU_ICON
229     status="$?"
230     # echo "got $status"
231     # if try_run successfully executed xsu, it will return xsu's exit code
232     # xsu returns 2 if ran and cancelled (i.e. the user 'doesn't want' to auth)
233     # it will return 0 if the command was executed correctly
234     # summing up, if we get 1, something failed
235     if [ "$status" -eq 0 ]
236     then
237       # the auth command was properly executed
238       exit 0
239     elif [ "$status" -eq 1 ]
240     then
241       ifdef([[M4_OSX]], [[echo "You need to run the installer as root" ; exit 1]])
242       # xsu wasn't found, or failed to run
243       # if xsu actually ran and the auth was cancelled, $status is 2
244       # try with su
245       printf "$SU_MESSAGE\n"
246       try_run -absolute /bin/su root -c "export DISPLAY=$DISPLAY;sh `pwd`/setup.sh -auth"
247       status="$?"
248     elif [ "$status" -eq 3 ]
249     then
250       # the auth failed or was canceled
251       # we don't want to even start the setup if not root
252       echo "Please run this installation as the super user"
253       exit 1
254     fi
255     # continue running as is
256   fi
257 fi
258
259 # Try to run the setup program
260 # TTimo - setup.gtk only
261 # try_run setup.gtk $args $*
262 # status=$?
263 # if [ $status -eq 2 ]; then  # setup.gtk couldn't connect to X11 server - ignore
264         try_run -fatal setup.gtk $args $* || {
265                 # TTimo
266                 echo "setup.gtk failed to start?"
267                 echo "DISPLAY: $DISPLAY"
268                 echo "Do you need to issue an xhost + command to let root access X11?"
269                 ifdef([[M4_OSX]], [[echo "See http://www.qeradiant.com/wikifaq/index.php?OSX%20fink%20installer%20known%20issues for details"]])
270                 echo "The setup program seems to have failed on $arch/$libc"
271                 echo
272                 echo $FATAL_ERROR
273                 status=1
274         }
275 #fi
276 exit $status