maemo-sdk-install_5.0.sh 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  1. #!/bin/sh
  2. # Copyright (C) 2006-2009 Nokia Corporation
  3. #
  4. # This is proprietary software owned by Nokia Corporation.
  5. #
  6. # Contact: Maemo Integration <integration@maemo.org>
  7. # Version: $Revision: 2041 $
  8. # TODO: * document examples of commandline usage, "-d -f -y"
  9. #
  10. __self=`basename $0`
  11. # Release configuration
  12. __version=5.0
  13. __release=fremantle
  14. __repository=explicit
  15. __url=http://repository.maemo.org/stable/5.0/
  16. __maemo_sdk_version=_20.2010.36-2
  17. # Target configurations
  18. __target_toolchain=cs2007q3-glibc2.5
  19. __target_prefix=FREMANTLE
  20. __rootstrap_prefix=maemo-sdk-rootstrap
  21. __rootstrap_suffix=tgz
  22. # Target configuration for armel
  23. __armel_toolchain=${__target_toolchain}-arm7
  24. __armel_target=${__target_prefix}_ARMEL
  25. __armel_devkits=perl:debian-etch:qemu:doctools:autotools-legacy:python-legacy:svn:git
  26. __armel_cputransp=qemu-arm-sb
  27. # Target configuration for i386
  28. __i386_toolchain=${__target_toolchain}-i486
  29. __i386_target=${__target_prefix}_X86
  30. __i386_devkits=perl:debian-etch:doctools:autotools-legacy:python-legacy:svn:git
  31. # Scratchbox
  32. __scratchbox_group=sbox
  33. __scratchbox_require=1.0.26
  34. __scratchbox_devkits=`echo "$__armel_devkits $__i386_devkits" | sed 's,:,\n,g' | sort -u`
  35. # SDK module
  36. __installed_module=maemo-sdk-dev
  37. __clear=`which clear`
  38. if [ ! -n "$TERMINFO_DIRS" ]; then
  39. export TERMINFO_DIRS=/etc/terminfo:/usr/share/terminfo:/lib/terminfo
  40. fi
  41. # Shows usage text
  42. usage () {
  43. cat <<EOF
  44. Usage: $__self [OPTIONS]
  45. Installer for Maemo $__version $__release release.
  46. Scratchbox installation is a precondition of running this script.
  47. Creates '$__armel_target' and '$__i386_target' scratchbox targets, downloads
  48. and installs the maemo $__version rootstraps and installs system files
  49. to these targets.
  50. If you choose not to accept the license or download the installer (e.g.
  51. using the '-f' option), these components will not be installable and
  52. they are not available anywhere else.
  53. Options:
  54. -v Display version and exit.
  55. -h Show this usage guide.
  56. -y Yes, force remove of existing targets.
  57. -d Use defaults. Non-interactive mode.
  58. -p URI Specify http_proxy for scratchbox user (default no proxy).
  59. -s PATH Specify Scratchbox installation path (default /scratchbox).
  60. -q NAME Specify Qemu version (default $__armel_cputransp).
  61. -a FILE Specify alternative sources.list file for both targets.
  62. -A Advanced mode
  63. -D Set the DISPLAY to export (default :2, noop if already set)
  64. -n Specify a prefix for the target names.
  65. -m PKG Specify the installed module for non-interactive mode.
  66. (default options: none, maemo-sdk-runtime, maemo-sdk-dev,
  67. maemo-sdk-debug. Defaults to maemo-sdk-dev.)
  68. EOF
  69. }
  70. # Show the 'open source license'
  71. license () {
  72. more <<EOF
  73. 1) IMPORTANT: READ CAREFULLY BEFORE INSTALLING, DOWNLOADING, OR USING THE
  74. SOFTWARE DEVELOPMENT KIT ("SDK" AS DEFINED BELOW) AND/OR SOFTWARE INCLUDED INTO
  75. THE SDK
  76. 2) The SDK comprises of a) some software copyrighted by Nokia Corporation or
  77. third parties in binary form (collectively "Licensed Software") and/or b) Open
  78. Source Software in binary and source code form.
  79. 3) Licensed Software (including, without limitation, the downloading,
  80. installation and/or the use thereof) is subject to, and licensed to you under,
  81. the Nokia Software Development Kit Agreement, which you have to accept if you
  82. choose to download the Licensed Software. Licensed Software is distributed to
  83. you only in binary form.
  84. 4) The SDK is provided to you "AS IS" and Nokia, its affiliates and/or its
  85. licensors do not make any representations or warranties, express or implied,
  86. including, without any limitation, the warranties of merchantability or
  87. fittness for a particular purpose, or that the SDK will not infringe any any
  88. third party patents, copyrights, trademarks or other rights, or that the SDK
  89. will meet your requirements or that the operation of the SDK will be
  90. uninterrupted and/or error-free. By downloading and/or using the SDK you accept
  91. that installation, any use and the results of the installation and/or happens
  92. and is solely at your own risk and that Nokia assumes no liability whatsoever
  93. for any damages that you may incur or suffer in connection with the SDK and/or
  94. the installation or use thereof.
  95. 5) The Open Source Software is licensed and distributed under the GNU General
  96. Public License (GPL), the GNU lesser General Public License (LGPL, aka. The GNU
  97. Library General Public License) and/or other copyright licenses, permissions,
  98. notices or disclaimers containing obligation or permission to provide the
  99. source code of such software with the binary / executable form delivery of the
  100. said software. Any source code of such software that is not part of this
  101. delivery is made available to you in accordance with the referred license terms
  102. and conditions on http://www.maemo.org. Alternatively, Nokia offers to provide
  103. any such source code to you on CD-ROM for a charge covering the cost of
  104. performing such distribution, such as the cost of media, shipping and handling,
  105. upon written request to Nokia at:
  106. Source Code Requests
  107. Nokia Corporation
  108. P.O.Box 407
  109. FIN00045 Nokia Group
  110. Finland.
  111. This offer is valid for a period of three (3) years.
  112. The exact license terms of GPL, LGPL and said certain other licenses, as well
  113. as the required copyright and other notices, permissions and acknowledgements
  114. are reproduced in and delivered to you as part of the referred source code.
  115. EOF
  116. echo "Press Enter to accept (Crtl+C to cancel)."
  117. read agree
  118. }
  119. # Show version information
  120. version () {
  121. echo "Installer for Maemo $__version $__release release."
  122. }
  123. # Fail in case str is empty and print out message
  124. # empty (str,msg)
  125. empty () {
  126. local str
  127. local message
  128. str=$1
  129. message=$2
  130. if [ "x$str" = "x" ] ; then
  131. echo "E: Program error. $message"
  132. echo "E: If this problem persists please report to <integration@maemo.org>"
  133. exit 1
  134. fi
  135. }
  136. # Downloads file in url given with parameter
  137. # download (outdir,url)
  138. # outdir must be non-empty
  139. # url must be non-empty
  140. download () {
  141. local outdir
  142. local url
  143. local file
  144. outdir=$1
  145. url=$2
  146. file=`basename $url`
  147. empty "$outdir" "Download output directory string must be non-empty."
  148. empty "$url" "Download URI string must be non-empty."
  149. # TODO Add timeout to file download
  150. wget -nd -P $outdir $url
  151. if [ $? != 0 ] ; then
  152. echo "E: Couldn't retrieve file '$file'."
  153. exit 1
  154. fi
  155. # TODO Check that downloaded file is readable from path
  156. }
  157. # Run gunzip archive integrity check on file
  158. # test_integrity (file)
  159. # file must be non-empty
  160. test_integrity () {
  161. local file
  162. file=$1
  163. empty "$file" "File to be checked must be non-empty."
  164. gunzip -qt $file 2>/dev/null
  165. return $?
  166. }
  167. # Taken from earlier maemo installer
  168. # This function takes two version number strings as an argument.
  169. # Return value is
  170. # 0, if the version numbers are identical
  171. # 1, if the first version number is greater
  172. # 2, if the second version number is greater
  173. # TODO Check that arguments lhs and rhs are in the form DIGIT.DIGIT.DIGIT
  174. # compare_version_numbers (lhs,rhs)
  175. # FIXME: This function breaks if the version numbers have characters
  176. compare_version_numbers () {
  177. local lhs
  178. local rhs
  179. local c
  180. lhs=$1
  181. rhs=$2
  182. c=1
  183. if [ -n $__dpkg ] ; then
  184. $__dpkg --compare-versions lhs eq rhs
  185. if [ $? -eq 0 ] ; then
  186. return 0
  187. fi
  188. $__dpkg --compare-versions lhs gt rhs
  189. if [ $? -eq 0 ] ; then
  190. return 1
  191. fi
  192. $__dpkg --compare-versions lhs lt rhs
  193. if [ $? -eq 0 ] ; then
  194. return 2
  195. fi
  196. else
  197. while [ 1 ]; do
  198. V1=`echo $lhs | cut -d . -f $c`
  199. V2=`echo $rhs | cut -d . -f $c`
  200. LEN1=`echo $V1 | wc -c`
  201. LEN2=`echo $V2 | wc -c`
  202. if [ "$LEN1" -le "1" ] && [ "$LEN2" -le "1" ]; then
  203. return 0
  204. fi
  205. if [ "$LEN2" -le "1" ] || [ "$V1" -gt "$V2" ]; then
  206. return 1
  207. fi
  208. if [ "$LEN1" -le "1" ] || [ "$V1" -lt "$V2" ]; then
  209. return 2
  210. fi
  211. c=`expr $c + 1`
  212. done
  213. fi
  214. }
  215. # Scratchbox installation has minimum Qemu version
  216. # TODO Add more cputransp sanity tests
  217. # has_cputransp (scratchbox,cputransp)
  218. # cputransp must be non-empty
  219. has_cputransp () {
  220. local scratchbox
  221. local cputransp
  222. scratchbox=$1
  223. cputransp=$2
  224. empty "$cputransp" "Scratchbox CPU transparency string must be non-empty."
  225. if [ -x $scratchbox/devkits/qemu/bin/$cputransp ] ; then
  226. return 0
  227. fi
  228. return 1
  229. }
  230. # Scratchbox installation has toolchain installed
  231. # TODO Add more toolchain sanity tests
  232. # has_toolchain (scratchbox,toolchain)
  233. # toolchain must be non-empty
  234. has_toolchain () {
  235. local scratchbox
  236. local toolchain
  237. scratchbox=$1
  238. toolchain=$2
  239. empty "$toolchain" "Scratchbox toolchain string must be non-empty."
  240. if [ -d $scratchbox/compilers/$toolchain ] ; then
  241. return 0
  242. fi
  243. return 1
  244. }
  245. # Scratchbox installation has devkit installed
  246. # TODO Add more devkit sanity tests
  247. # TODO Required devkit minimum version check
  248. # has_devkit (scratchbox,devkit)
  249. # devkit must be non-empty
  250. has_devkit () {
  251. local scratchbox
  252. local devkit
  253. scratchbox=$1
  254. devkit=$2
  255. empty "$devkit" "Scratchbox devkit string must be non-empty."
  256. if [ -d $scratchbox/devkits/$devkit ] ; then
  257. return 0
  258. fi
  259. return 1
  260. }
  261. # Scratchbox installation has target installed
  262. # has_target (scratchbox,target)
  263. # target must be non-empty
  264. has_target () {
  265. local scratchbox
  266. local target
  267. scratchbox=$1
  268. target=$2
  269. empty "$target" "Scratchbox target string must be non-empty."
  270. if [ -d $scratchbox/users/$USER/targets/$target ] ; then
  271. return 0
  272. fi
  273. return 1
  274. }
  275. # Scratchbox installation has sessions running
  276. # has_sessions (scratchbox)
  277. has_sessions () {
  278. local scratchbox
  279. scratchbox=$1
  280. if ! $scratchbox/tools/bin/sb-conf list --targets 2>&1 | \
  281. grep -q "^sbrsh-conf: No current target$" 1>/dev/null; then
  282. if [ `$scratchbox/tools/bin/sb-conf list --sessions | grep '^/dev' | wc -l` -gt 1 ] ; then
  283. return 0
  284. fi
  285. fi
  286. return 1
  287. }
  288. # Download a file from url to dest directory
  289. # get_file (url, dest, cached, description)
  290. get_file () {
  291. local url
  292. local dest
  293. local cached
  294. local description
  295. local file
  296. local destfile
  297. url=$1
  298. dest=$2
  299. cached=$3
  300. description=$4
  301. file=`basename $url`
  302. destfile=$dest/$file
  303. empty "$dest" "Download output directory string must be non-empty."
  304. empty "$url" "Download URI string must be non-empty."
  305. # Remove files downloaded earlier (default yes)
  306. if [ "x$cached" != "xyes" ] && [ -r $destfile ] ; then
  307. rm -f $destfile
  308. fi
  309. # Check integrity of already downloaded rootstrap if one exists
  310. if [ -r $destfile ] ; then
  311. # check existing file for integrity
  312. if ! test_integrity $destfile ; then
  313. echo "W: Previously downloaded $__arch rootstrap file failed integrity test."
  314. rm $destfile
  315. fi
  316. fi
  317. # Download file found from URI if not already found
  318. if [ ! -r $destfile ] ; then
  319. echo "Downloading $description."
  320. download $dest $url
  321. else
  322. echo "Using previously downloaded $description."
  323. fi
  324. }
  325. # Set up Scratchbox target
  326. # setup_target (scratchbox,target, rootstrap, toolchain, devkits, cputransp)
  327. setup_target () {
  328. local scratchbox
  329. local target
  330. local rootstrap
  331. local toolchain
  332. local devkits
  333. local cputransp
  334. scratchbox=$1
  335. target=$2
  336. rootstrap=$3
  337. toolchain=$4
  338. devkits=$5
  339. cputransp=$6
  340. empty "$target" "Scratchbox target name must be non-empty."
  341. empty "$rootstrap" "Scratchbox target rootstrap filename must be non-empty."
  342. empty "$toolchain" "Scratchbox target toolchain must be non-empty."
  343. echo "Setting up '$target' target."
  344. # Settings string
  345. local setup_string
  346. setup_string="--compiler=$toolchain"
  347. if [ "x$devkits" != "x" ] ; then
  348. setup_string="$setup_string --devkits=$devkits"
  349. fi
  350. if [ "x$cputransp" != "x" ] ; then
  351. setup_string="$setup_string --cputransp=$cputransp"
  352. fi
  353. # Setup
  354. $scratchbox/tools/bin/sb-conf setup $target --force $setup_string
  355. if [ $? != 0 ] ; then
  356. echo "E: Scratchbox command 'sb-conf setup' returned error $?."
  357. exit 1
  358. fi
  359. # Reset
  360. $scratchbox/tools/bin/sb-conf reset -f $target
  361. if [ $? != 0 ] ; then
  362. echo "E: Scratchbox command 'sb-conf reset' returned error $?."
  363. exit 1
  364. fi
  365. # Select
  366. $scratchbox/tools/bin/sb-conf select $target
  367. if [ $? != 0 ] ; then
  368. echo "E: Scratchbox command 'sb-conf select' returned error $?."
  369. exit 1
  370. fi
  371. # Rootstrap
  372. $scratchbox/tools/bin/sb-conf rootstrap $target $rootstrap
  373. if [ $? != 0 ] ; then
  374. echo "E: Scratchbox command 'sb-conf rootstrap' returned error $?."
  375. exit 1
  376. fi
  377. # Install
  378. $scratchbox/tools/bin/sb-conf install $target -L --etc --devkits --fakeroot
  379. if [ $? != 0 ] ; then
  380. echo "E: Scratchbox command 'sb-conf install' returned error $?."
  381. exit 1
  382. fi
  383. cp $scratchbox/etc/resolv.conf $scratchbox/users/$USER/targets/$target/etc/
  384. if [ -h "$scratchbox/users/$USER/targets/$target/opt" ] ; then
  385. rm $scratchbox/users/$USER/targets/$target/opt
  386. mkdir $scratchbox/users/$USER/targets/$target/opt
  387. fi
  388. echo "Target '$target' has been created."
  389. echo
  390. }
  391. # Prints out an underlined text banner
  392. # phase (text)
  393. phase () {
  394. local text
  395. local underline
  396. text=$1
  397. underline=`echo $text | sed 's,.,-,g'`
  398. echo
  399. echo "$text"
  400. echo "$underline"
  401. echo
  402. }
  403. run_dialog () {
  404. exec 3>&1
  405. __answer=$($__dialog "$@" 2>&1 1>&3)
  406. __retval=$?
  407. exec 3>&-
  408. }
  409. # Print Canceling notification
  410. cancel_installation () {
  411. if [ $# != 0 ] ; then
  412. $__dialog --msgbox "Installation Canceled\n$*" 6 40
  413. else
  414. $__dialog --msgbox "Installation Canceled" 5 30
  415. fi
  416. exit 0
  417. }
  418. # Main
  419. # TODO Add long command line options
  420. while getopts "Aa:cD:dhm:n:p:q:s:vy" opt ; do
  421. case "$opt" in
  422. h)
  423. usage
  424. exit 0
  425. ;;
  426. v)
  427. version
  428. exit 0
  429. ;;
  430. m)
  431. if [ "$OPTARG" = "none" ] ; then
  432. __installed_module=
  433. else
  434. __installed_module=$OPTARG
  435. fi
  436. ;;
  437. n)
  438. __target_prefix=$OPTARG
  439. __armel_target=${__target_prefix}_ARMEL
  440. __i386_target=${__target_prefix}_X86
  441. ;;
  442. y)
  443. __force=yes
  444. ;;
  445. d)
  446. __defaults=yes
  447. ;;
  448. p)
  449. __proxy=$OPTARG
  450. ;;
  451. s)
  452. __scratchbox=$OPTARG
  453. ;;
  454. q)
  455. __armel_cputransp=$OPTARG
  456. ;;
  457. a)
  458. __sources_list=$OPTARG
  459. if [ "x$__sources_list" != "x" ] && [ ! -r $__sources_list ] ; then
  460. echo "E: Alternative sources.list '$__sources_list' file not found."
  461. echo "E: Please check that '-a FILE' option arg file exists."
  462. exit 1
  463. fi
  464. ;;
  465. A)
  466. __advanced_mode=yes
  467. ;;
  468. D)
  469. __display=$OPTARG
  470. ;;
  471. *)
  472. echo "W: Unknown option '$opt'"
  473. ;;
  474. esac
  475. done
  476. # Runtime options
  477. if [ -z $__scratchbox ] ; then
  478. __scratchbox=/scratchbox
  479. fi
  480. __sbhome=$__scratchbox/users/$USER/home/$USER
  481. # Set defaults
  482. if [ -z $__defaults ] ; then
  483. __defaults=no
  484. else
  485. __cached=yes
  486. fi
  487. if [ -z $__force ] ; then
  488. __force=no
  489. fi
  490. if [ -z $__cached ] ; then
  491. __cached=yes
  492. fi
  493. if [ -z $__display ] ; then
  494. __display=":2"
  495. fi
  496. # If no proxy is given use the same as the host environment
  497. if [ -z $__proxy ] ; then
  498. __proxy=$http_proxy
  499. fi
  500. if [ -z $__advanced_mode ] ; then
  501. __advanced_mode=no
  502. fi
  503. cat <<END
  504. This script will install maemo SDK $__version $__release release to your computer.
  505. Install options
  506. Force remove of existing targets ($__force)
  507. Alternative sources.list ('$__sources_list')
  508. Target configuration for armel ($__armel_target)
  509. compiler=$__armel_toolchain
  510. devkits=$__armel_devkits
  511. cputransp=$__armel_cputransp
  512. Target configuration for i386 ($__i386_target)
  513. compiler=$__i386_toolchain
  514. devkits=$__i386_devkits
  515. END
  516. phase "Checking for prerequisites"
  517. # TODO Check that all parameters are non-empty
  518. # Check for wget
  519. __wget=`which wget`
  520. echo -n "wget tool in path... "
  521. if [ -z $__wget ] || [ ! -x $__wget ] ; then
  522. echo "not found"
  523. echo "E: This script requires wget to download rootstraps and installer files."
  524. echo "E: On most Linux distributions this is provided by the 'wget' package."
  525. exit 1
  526. else
  527. echo "$__wget"
  528. fi
  529. # Check for dpkg, optional, only used for comparing version numbers
  530. echo -n "Checking for dpkg tool in path... "
  531. __dpkg=`which dpkg`
  532. if [ -z $__dpkg ] || [ ! -x $__dpkg ] ; then
  533. echo "not found."
  534. else
  535. echo $__dpkg
  536. fi
  537. # Check for running inside scratchbox
  538. echo -n "Running outside of scratchbox... "
  539. if [ -r /targets/links/scratchbox.config ] ; then
  540. echo "no"
  541. echo "E: This script needs to be run outside of scratchbox."
  542. exit 1
  543. else
  544. echo "yes"
  545. fi
  546. # Check not run as user root
  547. echo -n "Script not run as user root... "
  548. __user=`whoami`
  549. if [ x$__user = "xroot" ] ; then
  550. echo "no"
  551. echo "E: This script should NOT be run as user root."
  552. exit 1
  553. else
  554. echo "yes"
  555. fi
  556. # Check for scratchbox installation
  557. echo -n "Scratchbox installation found... "
  558. if [ ! -d $__scratchbox ] ; then
  559. echo "no"
  560. echo "E: Scratchbox not found in installation path '$__scratchbox'."
  561. echo "E: Please complete scratchbox installation first."
  562. echo "E: Specify an alternative installation path using '-s PATH' option."
  563. exit 1
  564. else
  565. echo "yes"
  566. fi
  567. # Check for scratchbox user
  568. echo -n "Scratchbox home directory... "
  569. if [ ! -d $__scratchbox/users/$USER ] ; then
  570. echo "no"
  571. echo "E: Scratchbox directory for user not present."
  572. echo "E: Add user with '$__scratchbox/sbin/sbox_adduser $USER'."
  573. echo "E: Specify an alternative installation path using '-s PATH' option."
  574. exit 1
  575. else
  576. echo "yes"
  577. fi
  578. # Check for dialog tool
  579. # set __dialog only if using interactive setup
  580. if [ "$__defaults" = "no" ] ; then
  581. # sb dialog won't work outside sb if sb is not installed in default path
  582. if [ "$__scratchbox" = "/scratchbox" ] ||
  583. [ "$__scratchbox" = "/scratchbox/" ]; then
  584. __dialog=$__scratchbox/tools/bin/dialog
  585. else
  586. __dialog=`which dialog`
  587. if [ -z "$__dialog" ] ; then
  588. echo "E: Dialog not found in default path."
  589. echo "E: For interactive installation please install dialog."
  590. echo "E: Or use the non-interactive mode using -d option."
  591. exit 1
  592. fi
  593. fi
  594. fi
  595. # Check for sb-conf tool
  596. echo -n "Scratchbox sb-conf tool... "
  597. if [ ! -x $__scratchbox/tools/bin/sb-conf ] ; then
  598. echo "no"
  599. echo "E: Scratchbox sb-conf tool not found in '$__scratchbox'."
  600. echo "E: This is most likely due to old version of scratchbox."
  601. echo "E: Please complete scratchbox installation first."
  602. echo "E: Specify an alternative installation path using '-s PATH' option."
  603. exit 1
  604. else
  605. echo "yes"
  606. fi
  607. # Check for scratchbox bind mount
  608. echo -n "Scratchbox user's bind mount... "
  609. if [ ! -d $__scratchbox/users/$USER/scratchbox ] ; then
  610. echo "no"
  611. echo "E: Scratchbox bind mount for user not present."
  612. echo "E: Start scratchbox service with 'sudo $__scratchbox/sbin/sbox_ctl start'."
  613. echo "E: Specify an alternative installation path using '-s PATH' option."
  614. exit 1
  615. else
  616. echo "yes"
  617. fi
  618. # Check for scratchbox properly set up
  619. echo -n "Scratchbox user's /dev set up... "
  620. if [ ! -r $__scratchbox/users/$USER/dev/null ]; then
  621. echo "no"
  622. echo "E: Scratchbox user's /dev is not properly set up. Couldn't read /dev/null."
  623. echo "E: Start scratchbox service with 'sudo $__scratchbox/sbin/sbox_ctl start'."
  624. echo "E: Specify an alternative installation path using '-s PATH' option."
  625. exit 1
  626. else
  627. echo "yes"
  628. fi
  629. # Check for home directory inside scratchbox
  630. echo -n "Scratchbox home directory... "
  631. if [ ! -d $__sbhome ] ; then
  632. echo "no"
  633. echo "E: Scratchbox home directory '$__sbhome' not found."
  634. echo "E: Add user with '$__scratchbox/sbin/sbox_adduser $USER'."
  635. echo "E: Specify an alternative installation path using '-s PATH' option."
  636. exit 1
  637. else
  638. echo "yes"
  639. fi
  640. # Check for scratchbox login
  641. echo -n "Scratchbox login... "
  642. if [ ! -r $__scratchbox/login ] ; then
  643. echo "no"
  644. echo "E: Scratchbox login not found in '$__scratchbox'."
  645. echo "E: Please complete scratchbox installation first."
  646. echo "E: Specify an alternative installation path using '-s PATH' option."
  647. exit 1
  648. else
  649. echo "yes"
  650. fi
  651. # Check for scratchbox login
  652. # User in sbox group
  653. echo -n "Scratchbox login executable... "
  654. if [ ! -x $__scratchbox/login ] ; then
  655. echo "no"
  656. echo "E: Scratchbox login found but not executable by user."
  657. echo "E: Please check that user is member of the group specified in scratchbox"
  658. echo "E: installation (default '$__scratchbox_group')."
  659. echo "E: Also start a new login terminal after adding group membership."
  660. exit 1
  661. else
  662. echo "yes"
  663. fi
  664. # Execute sb-conf tool
  665. # TODO Check that version string is in the form DIGIT.DIGIT.DIGIT
  666. echo -n "Scratchbox sb-conf tool works... "
  667. __scratchbox_version=`$__scratchbox/tools/bin/sb-conf version 2>/dev/null | tail -1`
  668. if [ $? != 0 ] ; then
  669. echo "no"
  670. echo "E: Couldn't execute scratchbox utility sb-conf."
  671. echo "E: Please complete scratchbox installation first."
  672. echo "E: Specify an alternative installation path using '-s PATH' option."
  673. exit 1
  674. else
  675. echo "yes"
  676. fi
  677. # Check for scratchbox version
  678. echo -n "Scratchbox version requirement met... "
  679. compare_version_numbers $__scratchbox_require $__scratchbox_version
  680. if [ $? = 1 ] ; then
  681. echo "no"
  682. echo "E: Scratchbox version is too old (scratchbox-core $__scratchbox_version)."
  683. echo "E: The minimum required scratchbox-core version is $__scratchbox_require."
  684. echo "E: Please refer to http://scratchbox.org/"
  685. echo "E: Specify an alternative installation path using '-s PATH' option."
  686. exit 1
  687. else
  688. echo "yes"
  689. fi
  690. # Check for CPU transparency method
  691. echo -n "Scratchbox CPU transparency method for ARMEL is present... "
  692. if ! has_cputransp $__scratchbox $__armel_cputransp ; then
  693. echo "no"
  694. echo "E: CPU transparency method '$__armel_cputransp' not found."
  695. echo "E: Please complete scratchbox installation first."
  696. echo "E: Specify an alternative CPU transparency method using '-q NAME' option."
  697. exit 1
  698. else
  699. echo "yes"
  700. fi
  701. # Check that toolchains are found
  702. echo -n "Scratchbox toolchains... "
  703. if ! has_toolchain $__scratchbox $__armel_toolchain || ! has_toolchain $__scratchbox $__i386_toolchain ; then
  704. echo "no"
  705. echo "E: Toolchain $__armel_toolchain required for '$__armel_target' target."
  706. echo "E: Toolchain $__i386_toolchain required for '$__i386_target' target."
  707. echo "E: Please complete scratchbox installation first."
  708. echo "E: Specify an alternative installation path using '-s PATH' option."
  709. exit 1
  710. else
  711. echo "yes"
  712. fi
  713. # Check that devkits are found
  714. # TODO: This detects only the first missing devkit, should check all
  715. # missing devkits
  716. echo -n "Scratchbox required devkits... "
  717. for __devkit in $__scratchbox_devkits ; do
  718. if ! has_devkit $__scratchbox $__devkit ; then
  719. echo "no"
  720. echo "E: Scratchbox devkit $__devkit not found."
  721. echo "E: Please complete scratchbox installation first."
  722. echo "E: Specify an alternative installation path using '-s PATH' option."
  723. exit 1
  724. fi
  725. done
  726. echo "yes"
  727. # Check for scratchbox sessions running
  728. echo "Check for scratchbox sessions running..."
  729. if has_sessions $__scratchbox ; then
  730. echo "E: You must close your other scratchbox sessions first"
  731. echo "E: Specify an alternative installation path using '-s PATH' option."
  732. exit 1
  733. fi
  734. # Show the license before modifications
  735. license
  736. # Set the display
  737. if [ -r $__sbhome/.bashrc ] && grep -q "DISPLAY" $__sbhome/.bashrc ; then
  738. echo "DISPLAY already set."
  739. else
  740. echo "Setting DISPLAY..."
  741. echo "export DISPLAY=$__display" >> $__sbhome/.bashrc
  742. fi
  743. # Set installation environment
  744. if [ -r $__sbhome/.bashrc ] && grep -q ".installation_environment" $__sbhome/.bashrc ; then
  745. echo "Installation environment already set."
  746. else
  747. echo "Setting installation environment..."
  748. echo "if [ -f ~/.installation_environment ]; then" >> $__sbhome/.bashrc
  749. echo " . ~/.installation_environment" >> $__sbhome/.bashrc
  750. echo "fi" >> $__sbhome/.bashrc
  751. fi
  752. # Debian frontend to noninteractive
  753. echo "export DEBIAN_FRONTEND=noninteractive" > $__sbhome/.installation_environment
  754. echo "export DEBIAN_PRIORITY=critical" >> $__sbhome/.installation_environment
  755. echo "Added debconf frontend setting in scratchbox."
  756. echo >> $__sbhome/.installation_environment
  757. # Don't start stuff
  758. echo "# fake start-stop-daemon" >> $__sbhome/.installation_environment
  759. echo "SBOX_REDIRECT_BINARIES=\$SBOX_REDIRECT_BINARIES,/sbin/start-stop-daemon:$__scratchbox/tools/bin/true" >> $__sbhome/.installation_environment
  760. echo "SBOX_REDIRECT_BINARIES=\$SBOX_REDIRECT_BINARIES,$__scratchbox/devkits/debian/bin/start-stop-daemon:$__scratchbox/tools/bin/true" >> $__sbhome/.installation_environment
  761. echo >> $__sbhome/.installation_environment
  762. echo "# fake invoke-rc.d " >> $__sbhome/.installation_environment
  763. echo "SBOX_REDIRECT_BINARIES=\$SBOX_REDIRECT_BINARIES,/usr/sbin/invoke-rc.d:$__scratchbox/tools/bin/true " >> $__sbhome/.installation_environment
  764. echo "SBOX_REDIRECT_BINARIES=\$SBOX_REDIRECT_BINARIES,$__scratchbox/devkits/debian/bin/invoke-rc.d:$__scratchbox/tools/bin/true" >> $__sbhome/.installation_environment
  765. echo >> $__sbhome/.installation_environment
  766. echo "# fake install-info " >> $__sbhome/.installation_environment
  767. echo "SBOX_REDIRECT_BINARIES=\$SBOX_REDIRECT_BINARIES,/usr/sbin/install-info:$__scratchbox/tools/bin/true " >> $__sbhome/.installation_environment
  768. echo "SBOX_REDIRECT_BINARIES=\$SBOX_REDIRECT_BINARIES,$__scratchbox/devkits/debian/bin/install-info:$__scratchbox/tools/bin/true" >> $__sbhome/.installation_environment
  769. echo >> $__sbhome/.installation_environment
  770. echo "# fake dpkg-divert " >> $__sbhome/.installation_environment
  771. echo "SBOX_REDIRECT_BINARIES=\$SBOX_REDIRECT_BINARIES,/usr/sbin/dpkg-divert:$__scratchbox/tools/bin/true " >> $__sbhome/.installation_environment
  772. echo "SBOX_REDIRECT_BINARIES=\$SBOX_REDIRECT_BINARIES,$__scratchbox/devkits/debian/bin/dpkg-divert:$__scratchbox/tools/bin/true" >> $__sbhome/.installation_environment
  773. echo >> $__sbhome/.installation_environment
  774. echo "# fake update-alternatives " >> $__sbhome/.installation_environment
  775. echo "SBOX_REDIRECT_BINARIES=\$SBOX_REDIRECT_BINARIES,/usr/sbin/update-alternatives:$__scratchbox/tools/bin/true " >> $__sbhome/.installation_environment
  776. echo "SBOX_REDIRECT_BINARIES=\$SBOX_REDIRECT_BINARIES,$__scratchbox/devkits/debian/bin/update-alternatives:$__scratchbox/tools/bin/true" >> $__sbhome/.installation_environment
  777. #echo "export SBOX_REDIRECT_TO_DIRS=\`echo -n \"\$SBOX_REDIRECT_TO_DIRS\" | tr -s :\`" >> $__sbhome/.installation_environment
  778. __log_file=maemo-sdk-install.log
  779. ## If dialog is found and defaults are not used, start the interactive setup
  780. if [ $__dialog ] ; then
  781. # Select the desired module
  782. run_dialog --title "Package Selection" \
  783. --radiolist "Select Installed Packages:" 10 60 5 \
  784. 1 "Minimal Rootstrap only" off \
  785. 2 "Runtime Environment" off \
  786. 3 "Runtime Environment + All Dev Packages" on \
  787. 4 "Runtime Environment + All Dev and Dbg Packages" off
  788. if [ $__retval -eq 0 ] ; then
  789. case $__answer in
  790. 1)
  791. __installed_module=
  792. ;;
  793. 2)
  794. __installed_module=maemo-sdk-runtime
  795. ;;
  796. 3)
  797. __installed_module=maemo-sdk-dev
  798. ;;
  799. 4)
  800. __installed_module=maemo-sdk-debug
  801. ;;
  802. esac
  803. else
  804. cancel_installation
  805. fi
  806. # Advanced questions for those who want them
  807. if [ $__advanced_mode = "yes" ] ; then
  808. # Target names
  809. __loop=yes
  810. until [ $__loop = "no" ]
  811. do
  812. # X86 target
  813. run_dialog --inputbox "Enter name for X86 target:" 8 40 $__i386_target
  814. if [ $__retval -eq 0 ] ; then
  815. if [ $__answer ] ; then
  816. __i386_target=$__answer
  817. __loop=no
  818. fi
  819. else
  820. cancel_installation
  821. fi
  822. done
  823. __loop=yes
  824. until [ $__loop = "no" ]
  825. do
  826. # ARMEL target
  827. run_dialog --inputbox "Enter name for ARMEL target:" 8 40 $__armel_target
  828. if [ $__retval -eq 0 ] ; then
  829. if [ $__answer ] ; then
  830. __armel_target=$__answer
  831. __loop=no
  832. fi
  833. else
  834. cancel_installation
  835. fi
  836. done
  837. fi
  838. # Check existing targets
  839. if [ "x$__force" != "xyes" ] && ( has_target $__scratchbox $__i386_target || has_target $__scratchbox $__armel_target ) ; then
  840. __targets=""
  841. if ( has_target $__scratchbox $__i386_target ) &&
  842. ( has_target $__scratchbox $__armel_target ) ; then
  843. __targets="s $__i386_target and $__armel_target"
  844. elif ( has_target $__scratchbox $__i386_target ) ; then
  845. __targets=" $__i386_target"
  846. else
  847. __targets=" $__armel_target"
  848. fi
  849. run_dialog --title "Targets with the same name found" --defaultno --yesno "Do you wish to remove the existing target$__targets?" 7 48
  850. if [ $__retval -eq 0 ] ; then
  851. __force=yes
  852. else
  853. cancel_installation 'Conflicting target names found.'
  854. fi
  855. fi
  856. # Advanced questions for those who want them
  857. if [ $__advanced_mode = "yes" ] ; then
  858. # Proxy settings
  859. __loop=yes
  860. until [ $__loop = "no" ]
  861. do
  862. run_dialog --inputbox "Enter proxy server:" 8 40 $__proxy
  863. if [ $__retval -eq 0 ] ; then
  864. if [ "x$__answer" != "x" ] && [ `expr match "$__answer" \
  865. 'http://'` -ne 7 ] ; then
  866. run_dialog --title 'Malformed Proxy URI' \
  867. --msgbox 'Proxy has to start with http://' 5 38
  868. else
  869. __proxy=$__answer
  870. __loop=no
  871. fi
  872. else
  873. cancel_installation
  874. fi
  875. done
  876. # Alternative sources.list
  877. __loop=yes
  878. until [ $__loop = "no" ]
  879. do
  880. run_dialog --inputbox "Enter alternative sources.list:" 8 40 $__sources_list
  881. if [ $__retval -eq 0 ] ; then
  882. if [ ! -r $__answer ] ; then
  883. run_dialog --title 'Alternative sources.list not found' \
  884. --msgbox "File: $__answer not found" 6 50
  885. else
  886. __sources_list=$__answer
  887. __loop=no
  888. fi
  889. else
  890. cancel_installation
  891. fi
  892. done
  893. # End advanced
  894. fi
  895. run_dialog --title "Selection summary" --yes-label Continue \
  896. --no-label Cancel --yesno "Installation about to begin with following settings:\n\nInstalled component: $__installed_module\nX86 target name: $__i386_target\nArmel target name: $__armel_target\nOverwrite existing targets: $__force\nProxy server: $__proxy\nAlternative sources.list: $__sources_list" 15 60
  897. if [ $__retval -ne 0 ] ; then
  898. cancel_installation
  899. fi
  900. $__clear
  901. # End interactive
  902. else
  903. # Acceptance
  904. echo -n "Acceptance to reset existing targets... "
  905. if [ "x$__force" != "xyes" ] && \
  906. ( has_target $__scratchbox $__i386_target || \
  907. has_target $__scratchbox $__armel_target ) ; then
  908. echo "no"
  909. echo "E: Targets already exist ($__i386_target and $__armel_target)"
  910. echo "E: You need to force overwriting existing targets with '-y'."
  911. exit 1
  912. else
  913. echo "not needed"
  914. fi
  915. # Alternative sources.list
  916. echo -n "Alternative sources.list file exists... "
  917. if [ "x$__sources_list" != "x" ] && [ ! -r $__sources_list ] ; then
  918. echo "no"
  919. echo "E: Alternative sources.list '$__sources_list' file not found."
  920. echo "E: Please check that '-a FILE' option arg file exists."
  921. exit 1
  922. else
  923. echo "yes"
  924. fi
  925. # Check that http_proxy URI is formed correctly
  926. echo -n "Checking http_proxy URI format... "
  927. if [ "x$__proxy" != "x" ] && \
  928. [ `expr match "$__proxy" 'http://'` -ne 7 ] ; then
  929. echo "wrong"
  930. echo "E: Proxy URI is malformed. Must start with 'http://'."
  931. echo "E: Specify an alternative http proxy URI using '-p URI' option."
  932. exit 1
  933. else
  934. echo "ok"
  935. fi
  936. fi
  937. # Set http_proxy URI in .bashrc
  938. if [ "x$__proxy" != "x" ] ; then
  939. if [ -r $__sbhome/.bashrc ] && grep -q "^export http_proxy=" $__sbhome/.bashrc ; then
  940. echo "Found http_proxy setting in scratchbox user's .bashrc , not set."
  941. else
  942. echo "export http_proxy=$__proxy" >> $__sbhome/.bashrc
  943. echo "Added http_proxy setting to scratchbox user's .bashrc ."
  944. fi
  945. fi
  946. echo
  947. echo "Everything seems to be ok."
  948. phase "Downloading rootstraps and installer files"
  949. # Download i386 and armel rootstraps, check for archive integrity
  950. for __arch in armel i386 ; do
  951. get_file ${__url}/${__arch}/${__rootstrap_prefix}_${__version}${__maemo_sdk_version}_${__arch}.${__rootstrap_suffix} $__sbhome $__cached "$__arch rootstrap"
  952. echo "Testing downloaded $__arch rootstrap integrity."
  953. if ! test_integrity ${__sbhome}/${__rootstrap_prefix}_${__version}${__maemo_sdk_version}_${__arch}.${__rootstrap_suffix} ; then
  954. echo "E: Downloaded $__arch rootstrap file failed integrity test."
  955. exit 1
  956. fi
  957. done
  958. phase "Setting up scratchbox targets"
  959. # Setup and create SDK_ARMEL targets
  960. setup_target $__scratchbox \
  961. $__armel_target \
  962. ${__rootstrap_prefix}_${__version}${__maemo_sdk_version}_armel.${__rootstrap_suffix} \
  963. $__armel_toolchain \
  964. $__armel_devkits \
  965. $__armel_cputransp
  966. # Setup and create SDK_X86 target
  967. setup_target $__scratchbox \
  968. $__i386_target \
  969. ${__rootstrap_prefix}_${__version}${__maemo_sdk_version}_i386.${__rootstrap_suffix} \
  970. $__i386_toolchain \
  971. $__i386_devkits
  972. # TODO Setup and create SDK_KERNEL target
  973. # Set build flags for ARMEL target
  974. echo "export DEB_BUILD_OPTIONS=maemo-launcher,thumb,vfp" > $__scratchbox/users/$USER/targets/$__armel_target.environment
  975. # Replace sources.list on both targets
  976. if [ "x$__sources_list" != "x" ] ; then
  977. for __update_target in $__armel_target $__i386_target ; do
  978. echo "Replacing sources.list on '$__update_target' target."
  979. cp $__sources_list $__scratchbox/users/$USER/targets/$__update_target/etc/apt/sources.list
  980. done
  981. fi
  982. # Add proxy configuration to apt on both targets
  983. if [ "x$__proxy" != "x" ] ; then
  984. for __update_target in $__armel_target $__i386_target ; do
  985. echo "Adding proxy configuration for apt in $__update_target..."
  986. echo "Acquire::http::Proxy \"$__proxy\";" > $__scratchbox/users/$USER/targets/$__update_target/etc/apt/apt.conf.d/99proxy
  987. done
  988. fi
  989. phase "Update list of available packages"
  990. # Run apt-get update on both targets
  991. for __update_target in $__armel_target $__i386_target ; do
  992. echo "Running apt-get update on '$__update_target'."
  993. $__scratchbox/tools/bin/sb-conf select $__update_target
  994. $__scratchbox/login apt-get -o Acquire::http::TimeOut=15 -o Acquire::http::Retries=2 update
  995. __sb_return=$?
  996. if [ $__sb_return != 0 ] ; then
  997. echo "E: Unable to run 'apt-get update' on the target."
  998. echo "E: Please correct any network problems."
  999. echo "E: Scratchbox login returned error $__sb_return."
  1000. echo
  1001. echo "The installation process was unable to run 'apt-get update' inside"
  1002. echo "the installed targets in order to update the local package database."
  1003. echo "This could be due to an error in network configuration inside scratchbox."
  1004. echo "Common causes are incorrect proxy settings and the 'hosts' line in"
  1005. echo "$__scratchbox/etc/nsswitch.conf."
  1006. echo "For the 'hosts' line in /scratchbox/etc/nsswitch.conf the following"
  1007. echo "should usually be enough:"
  1008. echo "hosts: files dns"
  1009. echo
  1010. echo "Once network issues have been resolved, you should run the installer again."
  1011. exit 1
  1012. fi
  1013. echo
  1014. done
  1015. # Install the requested metapackage
  1016. if [ x$__installed_module != "x" ] ; then
  1017. for __update_target in $__armel_target $__i386_target ; do
  1018. echo "Installing packages on '$__update_target'."
  1019. $__scratchbox/tools/bin/sb-conf select $__update_target
  1020. $__scratchbox/login fakeroot apt-get install -y --force-yes -o Acquire::http::Pipeline-Depth=0 -o Acquire::http::Retries=10 $__installed_module 2>&1
  1021. __sb_return=$?
  1022. if [ $__sb_return != 0 ] ; then
  1023. echo "E: Unable to install $__installed_module on $__update_target target."
  1024. echo "E: Please check the sources.list for errors."
  1025. echo "E: Scratchbox login returned error $__sb_return."
  1026. exit 1
  1027. fi
  1028. done
  1029. fi
  1030. phase "Installation was successful!"
  1031. # Remove the installation time environment
  1032. rm $__sbhome/.installation_environment
  1033. cat <<END
  1034. IMPORTANT! Please read this.
  1035. You now have the maemo $__version $__release installed on your computer.
  1036. You can now start your maemo SDK session with $__scratchbox/login and
  1037. then select your target with 'sb-conf select $__armel_target' for the
  1038. armel target or 'sb-conf select $__i386_target' for the i386 target.
  1039. If you have any problems with targets' package databases, you can try
  1040. running 'fakeroot apt-get -f install' on your scratchbox target.
  1041. This command will try to fix any problems with the package database.
  1042. ***NOKIA BINARIES***
  1043. In order to obtain Nokia-closed binaries, visit
  1044. http://tablets-dev.nokia.com/eula/index.php to accept the End User
  1045. License Agreement. You will be given a token to access the Nokia
  1046. binaries repository with further instructions.
  1047. END
  1048. echo "Happy hacking!"
  1049. echo