install-build-deps.sh 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. #!/bin/bash -e
  2. # Copyright (c) 2012 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. # Script to install everything needed to build chromium (well, ideally, anyway)
  6. # See https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_instructions.md
  7. usage() {
  8. echo "Usage: $0 [--options]"
  9. echo "Options:"
  10. echo "--[no-]syms: enable or disable installation of debugging symbols"
  11. echo "--lib32: enable installation of 32-bit libraries, e.g. for V8 snapshot"
  12. echo "--[no-]arm: enable or disable installation of arm cross toolchain"
  13. echo "--[no-]chromeos-fonts: enable or disable installation of Chrome OS"\
  14. "fonts"
  15. echo "--[no-]nacl: enable or disable installation of prerequisites for"\
  16. "building standalone NaCl and all its toolchains"
  17. echo "--[no-]backwards-compatible: enable or disable installation of packages
  18. that are no longer currently needed and have been removed from this
  19. script. Useful for bisection."
  20. echo "--no-prompt: silently select standard options/defaults"
  21. echo "--quick-check: quickly try to determine if dependencies are installed"
  22. echo " (this avoids interactive prompts and sudo commands,"
  23. echo " so might not be 100% accurate)"
  24. echo "--unsupported: attempt installation even on unsupported systems"
  25. echo "Script will prompt interactively if options not given."
  26. exit 1
  27. }
  28. # Checks whether a particular package is available in the repos.
  29. # USAGE: $ package_exists <package name>
  30. package_exists() {
  31. # 'apt-cache search' takes a regex string, so eg. the +'s in packages like
  32. # "libstdc++" need to be escaped.
  33. local escaped="$(echo $1 | sed 's/[\~\+\.\:-]/\\&/g')"
  34. [ ! -z "$(apt-cache search --names-only "${escaped}" | \
  35. awk '$1 == "'$1'" { print $1; }')" ]
  36. }
  37. # These default to on because (some) bots need them and it keeps things
  38. # simple for the bot setup if all bots just run the script in its default
  39. # mode. Developers who don't want stuff they don't need installed on their
  40. # own workstations can pass --no-arm --no-nacl when running the script.
  41. do_inst_arm=1
  42. do_inst_nacl=1
  43. while [ "$1" != "" ]
  44. do
  45. case "$1" in
  46. --syms) do_inst_syms=1;;
  47. --no-syms) do_inst_syms=0;;
  48. --lib32) do_inst_lib32=1;;
  49. --arm) do_inst_arm=1;;
  50. --no-arm) do_inst_arm=0;;
  51. --chromeos-fonts) do_inst_chromeos_fonts=1;;
  52. --no-chromeos-fonts) do_inst_chromeos_fonts=0;;
  53. --nacl) do_inst_nacl=1;;
  54. --no-nacl) do_inst_nacl=0;;
  55. --backwards-compatible) do_inst_backwards_compatible=1;;
  56. --no-backwards-compatible) do_inst_backwards_compatible=0;;
  57. --add-cross-tool-repo) add_cross_tool_repo=1;;
  58. --no-prompt) do_default=1
  59. do_quietly="-qq --assume-yes"
  60. ;;
  61. --quick-check) do_quick_check=1;;
  62. --unsupported) do_unsupported=1;;
  63. *) usage;;
  64. esac
  65. shift
  66. done
  67. if [ "$do_inst_arm" = "1" ]; then
  68. do_inst_lib32=1
  69. fi
  70. # Check for lsb_release command in $PATH
  71. if ! which lsb_release > /dev/null; then
  72. echo "ERROR: lsb_release not found in \$PATH" >&2
  73. exit 1;
  74. fi
  75. distro_codename=$(lsb_release --codename --short)
  76. distro_id=$(lsb_release --id --short)
  77. supported_codenames="(trusty|xenial|artful|bionic)"
  78. supported_ids="(Debian)"
  79. if [ 0 -eq "${do_unsupported-0}" ] && [ 0 -eq "${do_quick_check-0}" ] ; then
  80. if [[ ! $distro_codename =~ $supported_codenames &&
  81. ! $distro_id =~ $supported_ids ]]; then
  82. echo -e "ERROR: The only supported distros are\n" \
  83. "\tUbuntu 14.04 LTS (trusty)\n" \
  84. "\tUbuntu 16.04 LTS (xenial)\n" \
  85. "\tUbuntu 17.10 (artful)\n" \
  86. "\tUbuntu 18.04 LTS (bionic)\n" \
  87. "\tDebian 8 (jessie) or later" >&2
  88. exit 1
  89. fi
  90. if ! uname -m | egrep -q "i686|x86_64"; then
  91. echo "Only x86 architectures are currently supported" >&2
  92. exit
  93. fi
  94. fi
  95. if [ "x$(id -u)" != x0 ] && [ 0 -eq "${do_quick_check-0}" ]; then
  96. echo "Running as non-root user."
  97. echo "You might have to enter your password one or more times for 'sudo'."
  98. echo
  99. fi
  100. # Packages needed for chromeos only
  101. chromeos_dev_list="libbluetooth-dev libxkbcommon-dev"
  102. if package_exists realpath; then
  103. chromeos_dev_list="${chromeos_dev_list} realpath"
  104. fi
  105. # Packages needed for development
  106. dev_list="\
  107. binutils
  108. bison
  109. bzip2
  110. cdbs
  111. curl
  112. dbus-x11
  113. dpkg-dev
  114. elfutils
  115. devscripts
  116. fakeroot
  117. flex
  118. g++
  119. git-core
  120. git-svn
  121. gperf
  122. libappindicator3-dev
  123. libasound2-dev
  124. libatspi2.0-dev
  125. libbrlapi-dev
  126. libbz2-dev
  127. libcairo2-dev
  128. libcap-dev
  129. libcups2-dev
  130. libcurl4-gnutls-dev
  131. libdrm-dev
  132. libelf-dev
  133. libffi-dev
  134. libgbm-dev
  135. libglib2.0-dev
  136. libglu1-mesa-dev
  137. libgnome-keyring-dev
  138. libgtk-3-dev
  139. libkrb5-dev
  140. libnspr4-dev
  141. libnss3-dev
  142. libpam0g-dev
  143. libpci-dev
  144. libpulse-dev
  145. libsctp-dev
  146. libspeechd-dev
  147. libsqlite3-dev
  148. libssl-dev
  149. libudev-dev
  150. libwww-perl
  151. libxslt1-dev
  152. libxss-dev
  153. libxt-dev
  154. libxtst-dev
  155. locales
  156. openbox
  157. p7zip
  158. patch
  159. perl
  160. pkg-config
  161. python
  162. python-cherrypy3
  163. python-crypto
  164. python-dev
  165. python-numpy
  166. python-opencv
  167. python-openssl
  168. python-psutil
  169. python-yaml
  170. rpm
  171. ruby
  172. subversion
  173. uuid-dev
  174. wdiff
  175. x11-utils
  176. xcompmgr
  177. xz-utils
  178. zip
  179. $chromeos_dev_list
  180. "
  181. # 64-bit systems need a minimum set of 32-bit compat packages for the pre-built
  182. # NaCl binaries.
  183. if file -L /sbin/init | grep -q 'ELF 64-bit'; then
  184. dev_list="${dev_list} libc6-i386 lib32gcc1 lib32stdc++6"
  185. fi
  186. # Run-time libraries required by chromeos only
  187. chromeos_lib_list="libpulse0 libbz2-1.0"
  188. # List of required run-time libraries
  189. common_lib_list="\
  190. libappindicator3-1
  191. libasound2
  192. libatk1.0-0
  193. libatspi2.0-0
  194. libc6
  195. libcairo2
  196. libcap2
  197. libcups2
  198. libexpat1
  199. libffi6
  200. libfontconfig1
  201. libfreetype6
  202. libglib2.0-0
  203. libgnome-keyring0
  204. libgtk-3-0
  205. libpam0g
  206. libpango1.0-0
  207. libpci3
  208. libpcre3
  209. libpixman-1-0
  210. libspeechd2
  211. libstdc++6
  212. libsqlite3-0
  213. libuuid1
  214. libwayland-egl1-mesa
  215. libx11-6
  216. libx11-xcb1
  217. libxau6
  218. libxcb1
  219. libxcomposite1
  220. libxcursor1
  221. libxdamage1
  222. libxdmcp6
  223. libxext6
  224. libxfixes3
  225. libxi6
  226. libxinerama1
  227. libxrandr2
  228. libxrender1
  229. libxtst6
  230. zlib1g
  231. "
  232. # Full list of required run-time libraries
  233. lib_list="\
  234. $common_lib_list
  235. $chromeos_lib_list
  236. "
  237. # 32-bit libraries needed e.g. to compile V8 snapshot for Android or armhf
  238. lib32_list="linux-libc-dev:i386 libpci3:i386"
  239. # 32-bit libraries needed for a 32-bit build
  240. lib32_list="$lib32_list libx11-xcb1:i386"
  241. # Packages that have been removed from this script. Regardless of configuration
  242. # or options passed to this script, whenever a package is removed, it should be
  243. # added here.
  244. backwards_compatible_list="\
  245. 7za
  246. fonts-indic
  247. fonts-ipafont
  248. fonts-stix
  249. fonts-thai-tlwg
  250. fonts-tlwg-garuda
  251. language-pack-da
  252. language-pack-fr
  253. language-pack-he
  254. language-pack-zh-hant
  255. libappindicator-dev
  256. libappindicator1
  257. libappindicator3-1:i386
  258. libdconf-dev
  259. libdconf-dev:i386
  260. libdconf1
  261. libdconf1:i386
  262. libexif-dev
  263. libexif12
  264. libexif12:i386
  265. libgbm-dev
  266. libgconf-2-4:i386
  267. libgconf2-dev
  268. libgl1-mesa-dev
  269. libgl1-mesa-glx:i386
  270. libgles2-mesa-dev
  271. libgtk2.0-0
  272. libgtk2.0-0:i386
  273. libgtk2.0-dev
  274. mesa-common-dev
  275. msttcorefonts
  276. ttf-dejavu-core
  277. ttf-indic-fonts
  278. ttf-kochi-gothic
  279. ttf-kochi-mincho
  280. ttf-mscorefonts-installer
  281. xfonts-mathml
  282. "
  283. case $distro_codename in
  284. trusty)
  285. backwards_compatible_list+=" \
  286. libgbm-dev-lts-trusty
  287. libgl1-mesa-dev-lts-trusty
  288. libgl1-mesa-glx-lts-trusty:i386
  289. libgles2-mesa-dev-lts-trusty
  290. mesa-common-dev-lts-trusty"
  291. ;;
  292. xenial)
  293. backwards_compatible_list+=" \
  294. libgbm-dev-lts-xenial
  295. libgl1-mesa-dev-lts-xenial
  296. libgl1-mesa-glx-lts-xenial:i386
  297. libgles2-mesa-dev-lts-xenial
  298. mesa-common-dev-lts-xenial"
  299. ;;
  300. esac
  301. # arm cross toolchain packages needed to build chrome on armhf
  302. EM_REPO="deb http://emdebian.org/tools/debian/ jessie main"
  303. EM_SOURCE=$(cat <<EOF
  304. # Repo added by Chromium $0
  305. ${EM_REPO}
  306. # deb-src http://emdebian.org/tools/debian/ jessie main
  307. EOF
  308. )
  309. EM_ARCHIVE_KEY_FINGER="084C6C6F39159EDB67969AA87DE089671804772E"
  310. GPP_ARM_PACKAGE="g++-arm-linux-gnueabihf"
  311. case $distro_codename in
  312. jessie)
  313. eval $(apt-config shell APT_SOURCESDIR 'Dir::Etc::sourceparts/d')
  314. CROSSTOOLS_LIST="${APT_SOURCESDIR}/crosstools.list"
  315. arm_list="libc6-dev:armhf
  316. linux-libc-dev:armhf"
  317. if [ "$do_inst_arm" = "1" ]; then
  318. if $(dpkg-query -W ${GPP_ARM_PACKAGE} &>/dev/null); then
  319. arm_list+=" ${GPP_ARM_PACKAGE}"
  320. else
  321. if [ "${add_cross_tool_repo}" = "1" ]; then
  322. gpg --keyserver pgp.mit.edu --recv-keys ${EM_ARCHIVE_KEY_FINGER}
  323. gpg -a --export ${EM_ARCHIVE_KEY_FINGER} | sudo apt-key add -
  324. if ! grep "^${EM_REPO}" "${CROSSTOOLS_LIST}" &>/dev/null; then
  325. echo "${EM_SOURCE}" | sudo tee -a "${CROSSTOOLS_LIST}" >/dev/null
  326. fi
  327. arm_list+=" ${GPP_ARM_PACKAGE}"
  328. else
  329. echo "The Debian Cross-toolchains repository is necessary to"
  330. echo "cross-compile Chromium for arm."
  331. echo "Rerun with --add-deb-cross-tool-repo to have it added for you."
  332. fi
  333. fi
  334. fi
  335. ;;
  336. # All necessary ARM packages are available on the default repos on
  337. # Debian 9 and later.
  338. *)
  339. arm_list="libc6-dev-armhf-cross
  340. linux-libc-dev-armhf-cross
  341. ${GPP_ARM_PACKAGE}"
  342. ;;
  343. esac
  344. # Work around for dependency issue Ubuntu/Trusty: http://crbug.com/435056
  345. case $distro_codename in
  346. trusty)
  347. arm_list+=" g++-4.8-multilib-arm-linux-gnueabihf
  348. gcc-4.8-multilib-arm-linux-gnueabihf"
  349. ;;
  350. xenial|artful|bionic)
  351. arm_list+=" g++-5-multilib-arm-linux-gnueabihf
  352. gcc-5-multilib-arm-linux-gnueabihf
  353. gcc-arm-linux-gnueabihf"
  354. ;;
  355. esac
  356. # Packages to build NaCl, its toolchains, and its ports.
  357. naclports_list="ant autoconf bison cmake gawk intltool xutils-dev xsltproc"
  358. nacl_list="\
  359. g++-mingw-w64-i686
  360. lib32z1-dev
  361. libasound2:i386
  362. libcap2:i386
  363. libelf-dev:i386
  364. libfontconfig1:i386
  365. libglib2.0-0:i386
  366. libgpm2:i386
  367. libgtk-3-0:i386
  368. libncurses5:i386
  369. lib32ncurses5-dev
  370. libnss3:i386
  371. libpango1.0-0:i386
  372. libssl-dev:i386
  373. libtinfo-dev
  374. libtinfo-dev:i386
  375. libtool
  376. libuuid1:i386
  377. libxcomposite1:i386
  378. libxcursor1:i386
  379. libxdamage1:i386
  380. libxi6:i386
  381. libxrandr2:i386
  382. libxss1:i386
  383. libxtst6:i386
  384. texinfo
  385. xvfb
  386. ${naclports_list}
  387. "
  388. if package_exists libssl1.1; then
  389. nacl_list="${nacl_list} libssl1.1:i386"
  390. elif package_exists libssl1.0.2; then
  391. nacl_list="${nacl_list} libssl1.0.2:i386"
  392. else
  393. nacl_list="${nacl_list} libssl1.0.0:i386"
  394. fi
  395. # Some package names have changed over time
  396. if package_exists libpng16-16; then
  397. lib_list="${lib_list} libpng16-16"
  398. else
  399. lib_list="${lib_list} libpng12-0"
  400. fi
  401. if package_exists libnspr4; then
  402. lib_list="${lib_list} libnspr4 libnss3"
  403. else
  404. lib_list="${lib_list} libnspr4-0d libnss3-1d"
  405. fi
  406. if package_exists libjpeg-dev; then
  407. dev_list="${dev_list} libjpeg-dev"
  408. else
  409. dev_list="${dev_list} libjpeg62-dev"
  410. fi
  411. if package_exists libudev1; then
  412. dev_list="${dev_list} libudev1"
  413. nacl_list="${nacl_list} libudev1:i386"
  414. else
  415. dev_list="${dev_list} libudev0"
  416. nacl_list="${nacl_list} libudev0:i386"
  417. fi
  418. if package_exists libbrlapi0.6; then
  419. dev_list="${dev_list} libbrlapi0.6"
  420. else
  421. dev_list="${dev_list} libbrlapi0.5"
  422. fi
  423. if package_exists apache2.2-bin; then
  424. dev_list="${dev_list} apache2.2-bin"
  425. else
  426. dev_list="${dev_list} apache2-bin"
  427. fi
  428. if package_exists libav-tools; then
  429. dev_list="${dev_list} libav-tools"
  430. fi
  431. if package_exists php7.2-cgi; then
  432. dev_list="${dev_list} php7.2-cgi libapache2-mod-php7.2"
  433. elif package_exists php7.1-cgi; then
  434. dev_list="${dev_list} php7.1-cgi libapache2-mod-php7.1"
  435. elif package_exists php7.0-cgi; then
  436. dev_list="${dev_list} php7.0-cgi libapache2-mod-php7.0"
  437. else
  438. dev_list="${dev_list} php5-cgi libapache2-mod-php5"
  439. fi
  440. # Some packages are only needed if the distribution actually supports
  441. # installing them.
  442. if package_exists appmenu-gtk; then
  443. lib_list="$lib_list appmenu-gtk"
  444. fi
  445. # Cross-toolchain strip is needed for building the sysroots.
  446. if package_exists binutils-arm-linux-gnueabihf; then
  447. dev_list="${dev_list} binutils-arm-linux-gnueabihf"
  448. fi
  449. if package_exists binutils-aarch64-linux-gnu; then
  450. dev_list="${dev_list} binutils-aarch64-linux-gnu"
  451. fi
  452. if package_exists binutils-mipsel-linux-gnu; then
  453. dev_list="${dev_list} binutils-mipsel-linux-gnu"
  454. fi
  455. if package_exists binutils-mips64el-linux-gnuabi64; then
  456. dev_list="${dev_list} binutils-mips64el-linux-gnuabi64"
  457. fi
  458. # When cross building for arm/Android on 64-bit systems the host binaries
  459. # that are part of v8 need to be compiled with -m32 which means
  460. # that basic multilib support is needed.
  461. if file -L /sbin/init | grep -q 'ELF 64-bit'; then
  462. # gcc-multilib conflicts with the arm cross compiler (at least in trusty) but
  463. # g++-X.Y-multilib gives us the 32-bit support that we need. Find out the
  464. # appropriate value of X and Y by seeing what version the current
  465. # distribution's g++-multilib package depends on.
  466. multilib_package=$(apt-cache depends g++-multilib --important | \
  467. grep -E --color=never --only-matching '\bg\+\+-[0-9.]+-multilib\b')
  468. lib32_list="$lib32_list $multilib_package"
  469. fi
  470. if [ "$do_inst_syms" = "1" ]; then
  471. echo "Including debugging symbols."
  472. # Debian is in the process of transitioning to automatic debug packages, which
  473. # have the -dbgsym suffix (https://wiki.debian.org/AutomaticDebugPackages).
  474. # Untransitioned packages have the -dbg suffix. And on some systems, neither
  475. # will be available, so exclude the ones that are missing.
  476. dbg_package_name() {
  477. if package_exists "$1-dbgsym"; then
  478. echo "$1-dbgsym"
  479. elif package_exists "$1-dbg"; then
  480. echo "$1-dbg"
  481. fi
  482. }
  483. for package in "${common_lib_list}"; do
  484. dbg_list="$dbg_list $(dbg_package_name ${package})"
  485. done
  486. # Debugging symbols packages not following common naming scheme
  487. if [ "$(dbg_package_name libstdc++6)" == "" ]; then
  488. if package_exists libstdc++6-8-dbg; then
  489. dbg_list="${dbg_list} libstdc++6-8-dbg"
  490. elif package_exists libstdc++6-7-dbg; then
  491. dbg_list="${dbg_list} libstdc++6-7-dbg"
  492. elif package_exists libstdc++6-6-dbg; then
  493. dbg_list="${dbg_list} libstdc++6-6-dbg"
  494. elif package_exists libstdc++6-5-dbg; then
  495. dbg_list="${dbg_list} libstdc++6-5-dbg"
  496. elif package_exists libstdc++6-4.9-dbg; then
  497. dbg_list="${dbg_list} libstdc++6-4.9-dbg"
  498. elif package_exists libstdc++6-4.8-dbg; then
  499. dbg_list="${dbg_list} libstdc++6-4.8-dbg"
  500. elif package_exists libstdc++6-4.7-dbg; then
  501. dbg_list="${dbg_list} libstdc++6-4.7-dbg"
  502. elif package_exists libstdc++6-4.6-dbg; then
  503. dbg_list="${dbg_list} libstdc++6-4.6-dbg"
  504. fi
  505. fi
  506. if [ "$(dbg_package_name libatk1.0-0)" == "" ]; then
  507. dbg_list="$dbg_list $(dbg_package_name libatk1.0)"
  508. fi
  509. if [ "$(dbg_package_name libpango1.0-0)" == "" ]; then
  510. dbg_list="$dbg_list $(dbg_package_name libpango1.0-dev)"
  511. fi
  512. else
  513. echo "Skipping debugging symbols."
  514. dbg_list=
  515. fi
  516. if [ "$do_inst_lib32" = "1" ]; then
  517. echo "Including 32-bit libraries."
  518. else
  519. echo "Skipping 32-bit libraries."
  520. lib32_list=
  521. fi
  522. if [ "$do_inst_arm" = "1" ]; then
  523. echo "Including ARM cross toolchain."
  524. else
  525. echo "Skipping ARM cross toolchain."
  526. arm_list=
  527. fi
  528. if [ "$do_inst_nacl" = "1" ]; then
  529. echo "Including NaCl, NaCl toolchain, NaCl ports dependencies."
  530. else
  531. echo "Skipping NaCl, NaCl toolchain, NaCl ports dependencies."
  532. nacl_list=
  533. fi
  534. filtered_backwards_compatible_list=
  535. if [ "$do_inst_backwards_compatible" = "1" ]; then
  536. echo "Including backwards compatible packages."
  537. for package in ${backwards_compatible_list}; do
  538. if package_exists ${package}; then
  539. filtered_backwards_compatible_list+=" ${package}"
  540. fi
  541. done
  542. fi
  543. # The `sort -r -s -t: -k2` sorts all the :i386 packages to the front, to avoid
  544. # confusing dpkg-query (crbug.com/446172).
  545. packages="$(
  546. echo "${dev_list} ${lib_list} ${dbg_list} ${lib32_list} ${arm_list}" \
  547. "${nacl_list}" ${filtered_backwards_compatible_list} | tr " " "\n" | \
  548. sort -u | sort -r -s -t: -k2 | tr "\n" " "
  549. )"
  550. if [ 1 -eq "${do_quick_check-0}" ] ; then
  551. if ! missing_packages="$(dpkg-query -W -f ' ' ${packages} 2>&1)"; then
  552. # Distinguish between packages that actually aren't available to the
  553. # system (i.e. not in any repo) and packages that just aren't known to
  554. # dpkg (i.e. managed by apt).
  555. missing_packages="$(echo "${missing_packages}" | awk '{print $NF}')"
  556. not_installed=""
  557. unknown=""
  558. for p in ${missing_packages}; do
  559. if apt-cache show ${p} > /dev/null 2>&1; then
  560. not_installed="${p}\n${not_installed}"
  561. else
  562. unknown="${p}\n${unknown}"
  563. fi
  564. done
  565. if [ -n "${not_installed}" ]; then
  566. echo "WARNING: The following packages are not installed:"
  567. echo -e "${not_installed}" | sed -e "s/^/ /"
  568. fi
  569. if [ -n "${unknown}" ]; then
  570. echo "WARNING: The following packages are unknown to your system"
  571. echo "(maybe missing a repo or need to 'sudo apt-get update'):"
  572. echo -e "${unknown}" | sed -e "s/^/ /"
  573. fi
  574. exit 1
  575. fi
  576. exit 0
  577. fi
  578. if [ "$do_inst_lib32" = "1" ] || [ "$do_inst_nacl" = "1" ]; then
  579. sudo dpkg --add-architecture i386
  580. fi
  581. sudo apt-get update
  582. # We initially run "apt-get" with the --reinstall option and parse its output.
  583. # This way, we can find all the packages that need to be newly installed
  584. # without accidentally promoting any packages from "auto" to "manual".
  585. # We then re-run "apt-get" with just the list of missing packages.
  586. echo "Finding missing packages..."
  587. # Intentionally leaving $packages unquoted so it's more readable.
  588. echo "Packages required: " $packages
  589. echo
  590. new_list_cmd="sudo apt-get install --reinstall $(echo $packages)"
  591. if new_list="$(yes n | LANGUAGE=en LANG=C $new_list_cmd)"; then
  592. # We probably never hit this following line.
  593. echo "No missing packages, and the packages are up to date."
  594. elif [ $? -eq 1 ]; then
  595. # We expect apt-get to have exit status of 1.
  596. # This indicates that we cancelled the install with "yes n|".
  597. new_list=$(echo "$new_list" |
  598. sed -e '1,/The following NEW packages will be installed:/d;s/^ //;t;d')
  599. new_list=$(echo "$new_list" | sed 's/ *$//')
  600. if [ -z "$new_list" ] ; then
  601. echo "No missing packages, and the packages are up to date."
  602. else
  603. echo "Installing missing packages: $new_list."
  604. sudo apt-get install ${do_quietly-} ${new_list}
  605. fi
  606. echo
  607. else
  608. # An apt-get exit status of 100 indicates that a real error has occurred.
  609. # I am intentionally leaving out the '"'s around new_list_cmd,
  610. # as this makes it easier to cut and paste the output
  611. echo "The following command failed: " ${new_list_cmd}
  612. echo
  613. echo "It produces the following output:"
  614. yes n | $new_list_cmd || true
  615. echo
  616. echo "You will have to install the above packages yourself."
  617. echo
  618. exit 100
  619. fi
  620. # Install the Chrome OS default fonts. This must go after running
  621. # apt-get, since install-chromeos-fonts depends on curl.
  622. if [ "$do_inst_chromeos_fonts" != "0" ]; then
  623. echo
  624. echo "Installing Chrome OS fonts."
  625. dir=`echo $0 | sed -r -e 's/\/[^/]+$//'`
  626. if ! sudo $dir/linux/install-chromeos-fonts.py; then
  627. echo "ERROR: The installation of the Chrome OS default fonts failed."
  628. if [ `stat -f -c %T $dir` == "nfs" ]; then
  629. echo "The reason is that your repo is installed on a remote file system."
  630. else
  631. echo "This is expected if your repo is installed on a remote file system."
  632. fi
  633. echo "It is recommended to install your repo on a local file system."
  634. echo "You can skip the installation of the Chrome OS default founts with"
  635. echo "the command line option: --no-chromeos-fonts."
  636. exit 1
  637. fi
  638. else
  639. echo "Skipping installation of Chrome OS fonts."
  640. fi
  641. echo "Installing locales."
  642. CHROMIUM_LOCALES="da_DK.UTF-8 fr_FR.UTF-8 he_IL.UTF-8 zh_TW.UTF-8"
  643. LOCALE_GEN=/etc/locale.gen
  644. if [ -e ${LOCALE_GEN} ]; then
  645. OLD_LOCALE_GEN="$(cat /etc/locale.gen)"
  646. for CHROMIUM_LOCALE in ${CHROMIUM_LOCALES}; do
  647. sudo sed -i "s/^# ${CHROMIUM_LOCALE}/${CHROMIUM_LOCALE}/" ${LOCALE_GEN}
  648. done
  649. # Regenerating locales can take a while, so only do it if we need to.
  650. if (echo "${OLD_LOCALE_GEN}" | cmp -s ${LOCALE_GEN}); then
  651. echo "Locales already up-to-date."
  652. else
  653. sudo locale-gen
  654. fi
  655. else
  656. for CHROMIUM_LOCALE in ${CHROMIUM_LOCALES}; do
  657. sudo locale-gen ${CHROMIUM_LOCALE}
  658. done
  659. fi