]> icculus.org git repositories - divverent/netradiant.git/blob - setup/linux/setup.sh
add all the missing stuff.
[divverent/netradiant.git] / setup / linux / setup.sh
1 #! /bin/sh
2 #
3 # Product setup script - Loki Entertainment Software
4
5 # TTimo FIXME need a way to configure this easily
6 critical_error="Please contact Id software technical support at bugs@idsoftware.com"
7
8 # Go to the proper setup directory (if not already there)
9 cd `dirname $0`
10
11 # Return the appropriate architecture string
12 DetectARCH()
13 {
14         status=1
15         case `uname -m` in
16                 i?86)  echo "x86"
17                         status=0;;
18                 *)     echo "`uname -m`"
19                         status=0;;
20         esac
21         return $status
22 }
23
24 # Return the appropriate version string
25 DetectLIBC()
26 {
27       status=1
28           if [ `uname -s` != Linux ]; then
29                   echo "glibc-2.1"
30                   return $status
31           fi
32       if [ -f `echo /lib/libc.so.6* | tail -1` ]; then
33               if fgrep GLIBC_2.1 /lib/libc.so.6* 2>&1 >/dev/null; then
34                       echo "glibc-2.1"
35                       status=0
36               else    
37                       echo "glibc-2.0"
38                       status=0
39               fi        
40       elif [ -f /lib/libc.so.5 ]; then
41               echo "libc5"
42               status=0
43       else
44               echo "unknown"
45       fi
46       return $status
47 }
48
49 # Detect the Linux environment
50 arch=`DetectARCH`
51 libc=`DetectLIBC`
52 os=`uname -s`
53
54 # Find the installation program
55 # try_run INSTALLER_NAME [-fatal] [PARAMETERS_PASSED]
56 #   INSTALLER_NAME: setup.gtk or setup
57 #   -fatal option: if you want verbose messages in case
58 #      - the script could not be found
59 #      - it's execution would fail
60 #   PARAMETERS_PASSED: additional arguments passed to the setup script
61 try_run()
62 {
63     setup=$1
64     shift
65     # added safe check, direct test seems buggy on older bash
66     if [ "$#" > 0 ]; then
67       # looks like bash < 2.* don't like == operator, using = instead
68       if [ "$1" = "-fatal" ]; then
69         # got fatal
70         fatal=$1
71         shift
72       fi
73     fi
74
75     # First find the binary we want to run
76     failed=0
77     setup_bin="setup.data/bin/$os/$arch/$libc/$setup"
78     # trying $setup_bin
79     if [ ! -f "$setup_bin" ]; then
80         setup_bin="setup.data/bin/$os/$arch/$setup"
81         # libc dependant version failed, trying again
82         if [ ! -f "$setup_bin" ]; then
83             failed=1
84         fi
85     fi
86     if [ "$failed" -eq 1 ]; then
87         if [ "$fatal" != "" ]; then
88             cat <<__EOF__
89 This installation doesn't support $libc on $os / $arch
90
91 $critical_error
92 __EOF__
93             exit 1
94         fi
95         return $failed
96     fi
97
98     # Try to run the binary ($setup_bin)
99     # The executable is here but we can't execute it from CD
100     setup="$HOME/.setup$$"
101     cp "$setup_bin" "$setup"
102     chmod 700 "$setup"
103     if [ "$fatal" != "" ]; then
104         "$setup" $*
105         failed=$?
106     else
107         "$setup" $* 2>/dev/null
108         failed=$?
109     fi
110     rm -f "$setup"
111     return $failed
112 }
113
114
115 # Try to run the setup program
116 status=0
117 rm -f "$setup"
118 try_run setup.gtk $* || try_run setup -fatal $* || {
119     echo "The setup program seems to have failed on $arch/$libc"
120     echo
121     echo $critical_error
122     status=1
123 }
124 exit $status