setup.sh 7.3 KB

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