在centos6.X和redhat enterprise 中安装chrome,我找了很久都不行,今天终于找到了可以用下脚本那安装:

  1. #! /bin/bash
  2.  
  3. # Google Chrome Installer/Uninstaller for CentOS or
  4. # (C) Richard K. Lloyd <rklloyd@gmail.com>
  5. # See http://chrome.richardlloyd.org.uk/ for further details.
  6.  
  7. # This script is in the public domain and has no warranty.
  8. # It needs to be run as root because it installs/uninstalls RPMs.
  9.  
  10. # Minimum system requirements:
  11. # - -bit or -bit CentOS 6.5 or later (you will be asked to
  12. # upgrade the OS and reboot if you're running 6.4 or earlier) or
  13. # any -bit CentOS version (including pre-releases)
  14. # - At least 250MB free in each of the temporary directory, /opt and /root
  15. # - A working yum system (including http proxy configured if needed)
  16. # - http_proxy env var set if you are using an http proxy
  17. # - Google Chrome should not be running at the same time as this script
  18.  
  19. show_syntax()
  20. # Show syntax of script
  21. {
  22. cat <<@EOF
  23. Syntax: ./install_chrome.sh [-b] [-d] [-f [-f [-f]]] [-h] [-n] [-q] [-s]
  24. [-t tmpdir] [-u] [-U]
  25.  
  26. -b (or --beta) will switch to beta versions (google-chrome-beta).
  27. -d (or --delete) will delete the temporary directory used for downloads
  28. if an installation was successful.
  29. -f (or --force) forces an automatic "y" for any interactive prompting
  30. except for OS mismatch/OS upgrade/reboot prompts. Specify -f twice to force
  31. it for OS mismatches or OS upgrades as well and three times for reboots
  32. on top of that.
  33. -h (or -? or --help) will display this syntax message.
  34. -n (or --dryrun) will show what actions the script will take,
  35. but it won't actually perform those actions.
  36. -q (or --quiet) will switch to "quiet mode" where minimal info is displayed.
  37. Specify -q twice to go completely silent except for errors.
  38. -s (or --stable) will switch to stable versions (google-chrome-stable),
  39. which is the default if -b or -U haven't previously been specified.
  40. -t tmpdir (or --tmpdir tmpdir) will use tmpdir as the temporary directory
  41. parent tree rather than \$TMPDIR (if set) or /tmp.
  42. -u performs an uninstallation of Google Chrome and chrome-deps rather the
  43. default action of an installation.
  44. -U (or --unstable) will switch to unstable versions (google-chrome-unstable).
  45. @EOF
  46. }
  47.  
  48. # Current version of this script
  49. version="5.01"
  50.  
  51. # This script will download/install the following for an installation:
  52.  
  53. # These CentOS RPMs and their (many!) deps that aren't already installed:
  54. # redhat-lsb, wget, xdg-utils, GConf2, libXSCrnSaver, libX11,
  55. # gcc, glibc-devel, nss, rpm-build and rpmdevtools.
  56. # These CentOS RPMs and their (many!) deps that aren't already installed:
  57. # redhat-lsb, wget, xdg-utils, GConf2, libXSCrnSaver. libX11 and nss.
  58. # The latest Google Chrome RPM if not already downloaded (or out-of-date).
  59. # CentOS only: RPM packages from Fedora if not already fully downloaded.
  60. # CentOS only: RPM package from Fedora if not already fully downloaded.
  61.  
  62. # For CentOS only:
  63. # It then copies libraries from the F15/F17 packages into
  64. # /opt/google/chrome/lib.
  65. # It also changes ld library references in four F15 libraries to end
  66. # in .so. instead of .so. so that they avoid the system ld library.
  67. # It sets SELinux context user/type for the F15/F17 libraries as well if
  68. # SELinux is enabled on the system.
  69.  
  70. # Next, it C-compiles an LD_PRELOAD library that's installed as
  71. # /opt/google/chrome/lib/unset_var.so, which saves/unsets LD_LIBRARY_PATH
  72. # and LD_PRELOAD before calling exec*() routines and then restores the
  73. # environmental variables afterwards.
  74. # /opt/google/chrome/google-chrome is also modified to point LD_PRELOAD
  75. # to the installed library. This is avoids having LD_LIBRARY_PATH and
  76. # LD_PRELOAD set when sub-processes are run.
  77.  
  78. # Finally, it creates and installs a chrome-deps RPM which includes the
  79. # F15/F17 libraries, unset_var.so and code to modify the google-chrome wrapper.
  80. # (End of CentOS only actions)
  81.  
  82. # Note that you can't run Google Chrome as root - it stops you from doing so.
  83.  
  84. # Revision history:
  85.  
  86. # 5.01 - 26th June
  87. # - Fix for latest CentOS pre-release repo detection, because the latest
  88. # pre-release bizarrely includes placeholder .repo files that don't do
  89. # anything.
  90.  
  91. # 5.00 - 21st June
  92. # - Added support for pre-release CentOS , which mainly means no RPM building
  93. # and also the installation of missing dependencies. If no CentOS repos are
  94. # detected - which is the current case with pre-release CentOS versions -
  95. # in /etc/yum.repos.d, a "chrome-deps-updates" repo will be created (this
  96. # will be removed on later runs if any other .repo files are created, on the
  97. # assumption that the user has added their own repos for installing/updating
  98. # RPMs instead or the final CentOS repos are already present).
  99. # - Minimum CentOS release supported is now 6.5, which has been out for over
  100. # months at the time of writing. This means libX11 and nss should be
  101. # up-to-date versions, avoiding run-time problems with older versions of
  102. # those packages.
  103. # - Tidied up final messages e.g. it now says the latest version was already
  104. # installed if that was the case.
  105. #
  106. # 4.70 - 17th May
  107. # - Added -f option to auto-force a "y" answer to any interactive prompt
  108. # without bothering to actually prompt you (thanks to Steve Cleveland for the
  109. # idea). The only exceptions to this are the prompts for an OS mismatch, OS
  110. # upgrade or reboot, but even those can be forced by specifying -f twice (or
  111. # three times for reboots).
  112. # - Fixed the -hourly bash segfault recorded in syslog. It was caused by the
  113. # chrome binary self-calling the google-chrome bash script to get its version,
  114. # which is bizarre since surely it could just call one of its own functions
  115. # to get that? By unsetting LD_LIBRARY_PATH on the self-call, the segfault
  116. # was avoided. Bumped chrome-deps to version 1.21 because of this.
  117.  
  118. # 4.60 - 12th April
  119. # - The latest Google Chrome releases kept prompting me for a keyring
  120. # password when starting up. It turns out they were using the
  121. # gnome_keyring_attribute_list_new function, which didn't exist until Fedora
  122. # 's libgnome-keyring.so.0 library! Luckily, the F17 library works in
  123. # CentOS , so that's been added and the chrome-deps RPM has been bumped
  124. # to version 1.20.
  125. # - Added nss to the list of possible CentOS RPMs that are installed (thanks
  126. # to Ravi Saive at tecmint.com for this, though no-one told me directly...).
  127. # - Check the size and cksum of downloaded RPMs and delete them (and quit) if
  128. # they are bad.
  129.  
  130. # 4.50 - 11th December
  131. # - A user reported that file-roller wouldn't work when opening downloaded
  132. # .tar.gz files inside Google Chrome. It turns out LD_PRELOAD was still set
  133. # when file-roller tried to exec() sub-processes like gzip, so I now unset
  134. # LD_PRELOAD (as well as LD_LIBRARY_PATH) when exec'ing from within Google
  135. # Chrome, which fixes the issue. chrome-deps version was bumped to 1.10
  136. # because of this change. Another user suggested checking previously
  137. # downloaded F15 RPMs have the right checksum/size (and a fresh download is
  138. # forced if they don't), which has been implemented.
  139.  
  140. # 4.41 - 9th December
  141. # - Added glibc-devel to the list of dependencies because a user reported
  142. # that it wasn't dragged in by gcc. With the imminent release of Fedora 20,
  143. # Fedora has been archived and the code has been changed to reflect that.
  144. # Removed SELinux warning at end of install - the last few releases of
  145. # Google Chrome don't seem to have a problem with enforcing mode w.r.t.
  146. # nacl_helper. Future releases of this script may remove all SELinux-related
  147. # code if enforcing mode remains OK. Google Chrome is displaying a
  148. # manifestTypes error to the console in some setups, but this doesn't seem
  149. # to affect the running of Google Chrome.
  150.  
  151. # 4.40 - 5th October
  152. # - A similar issue to the 4.30 release cropped up again (reported by
  153. # the same user!) that I still can't reproduce. This time it was a missing
  154. # gdk_pixbuf_format_get_type symbol in F15's libgtk-x11-2.0. This was fixed
  155. # by additonally downloading F15's gdk-pixbuf2 RPM and extracting
  156. # libgdk_pixbuf-2.0 from it. This prompted a bump of the chrome-deps RPM to
  157. # version 1.03.
  158.  
  159. # 4.30 - 4th October
  160. # - The g_desktop_app_info_get_filename symbol in the F15 libgdk-x11-2.0
  161. # library is present in the F15 libgio-2.0 library (but not in CentOS's).
  162. # The script used the former library, but not the latter and a user reported
  163. # a missing symbol crash due to this, despite my testing not showing the
  164. # issue. This release is therefore purely to add libgio-2.0 and its
  165. # libgobject-2.0 dependency to the set of extracted F15 libraries and has
  166. # also been tested against Google Chrome and Google Talk Plugin 4.7.0.0.
  167. # The chrome-deps RPM is now at version 1.02 because of the two extra
  168. # libraries.
  169.  
  170. # 4.20 - 22nd August
  171. # - If the Google Chrome repo is enabled and a Google Chrome RPM is already
  172. # installed, use "yum check-update google-chrome-stable" to determine if
  173. # there is a newer version available and then fallback to using the
  174. # OmahaProxy site if there isn't.
  175. # - Any newer version than what's been previously downloaded or installed
  176. # can now be downloaded/installed, rather than being exactly the version
  177. # displayed on the OmahaProxy site (which was out of date for a full day when
  178. # Chrome was released, stopping this script from updating to version ).
  179. # - Removed terminal messages warning because this is fixed with Google Chrome
  180. # .
  181. # - Used extra parameters in the OmahaProxy request to narrow the data down to
  182. # the exact channel and platform (linux).
  183.  
  184. # 4.10 - 8th August
  185. # - Fixed Google Talk (Hangouts) plugin crash - it was because, unlike Google
  186. # Chrome itself, the plugin hasn't been built with later libraries, so it
  187. # needs LD_LIBRARY_PATH to be unset. There still appears to be other
  188. # library issues with the Hangouts plugin, mainly because the older libraries
  189. # don't implement certain calls it uses. Google need to update the plugin!
  190. # Bumped chrome-deps version to 1.01 because of the unset_var.c change.
  191. # - Catered for non-standard i686 RPM build trees on -bit systems. I couldn't
  192. # reproduce this myself (it uses i386 for me all the time in CentOS and
  193. # Scientific Linux -bit VMs) but the code is in place anyway for the users
  194. # that reported the issue.
  195. # - modify_wrapper (now bumped to version 1.01) no longer echoes anything to
  196. # stdout after a successful update of /opt/google/chrome/google-chrome.
  197.  
  198. # 4.01 - 30th July
  199. # - Emergency -char change fix due to a terrible spec parsing bug in rpmbuild.
  200. # It appears that it tries to parse % directives in comment lines.
  201. # Strangely, three different build envs of mine didn't have the bug, but
  202. # a fourth one I tried did.
  203. #
  204. # 4.00 - 30th July
  205. # - Creates a new chrome-deps RPM that it installs alongside the
  206. # google-chrome-stable RPM. It contains the Fedora libraries, the
  207. # built unset_var.so library and a script which is run post-install
  208. # to add code to /etc/default/google-chrome to modify google-chrome if
  209. # its LD_PRELOAD addition isn't present. This gets sourced daily by
  210. # /etc/cron.daily/google-chrome and is a way to auto-modify google-chrome
  211. # within a day of a Google Chrome update (this is because google-chrome
  212. # isn't marked as a config file by Google Chrome's spec file, so updates
  213. # will overwrite any changes made to it). The new code will also enable the
  214. # Google Chrome repo of course. Many thanks to Marcus Sandberg
  215. # for his spec file at https://github.com/adamel/chrome-deps which
  216. # I used as the initial basis for the spec file I create.
  217. # - Adjusted unset_var code to not unset LD_LIBRARY_PATH if a full file
  218. # path (i.e. one containing a slash) is supplied to exec*() routines.
  219. # - Download/installation of google-chrome-stable/chrome-deps dependencies
  220. # is now prompted for (if you decline, the script aborts).
  221. # - Moved out-of-date OS check right to the end of the script and it also
  222. # now offers to reboot the machine after a successful OS update. Warn user
  223. # not to run Google Chrome if either the OS update or reboot are declined
  224. # until they complete the OS update and reboot.
  225. # - Don't remove /etc/cron.daily/google-chrome or
  226. # /etc/yum.conf.d/google-chrome.repo any more because we actually want
  227. # people to use those (they won't be happy cron'ing this script or having
  228. # to regularly run it manually to check for updates).
  229. # - Added -t option to specify the temporary directory parent tree.
  230. # - Added -s (stable), -b (beta) and -U (unstable) options to switch
  231. # release channels. Yes, it remembers the switch, so you only have to
  232. # specify once time.
  233. # - Added libdl.so. to the Fedora library list (for unset_var.so).
  234.  
  235. # 3.20 - 27th July
  236. # - Initial attempt to stop helper apps crashing by wrapping exec*() routines
  237. # with LD_PRELOAD functions that save/blank LD_LIBRARY_PATH, call the
  238. # original routines and, if they return, restore LD_LIBRARY_PATH. Seems to
  239. # stop crashes previously logged to syslog on startup at least, but does
  240. # require gcc and its dependencies to be installed now of course.
  241.  
  242. # 3.11 - 25th July
  243. # - If SELinux is enabled, set appropriate SELinux contexts on Fedora libraries
  244. # in /opt/google/chrome/lib and that directory itself. Investigation shows
  245. # that if you enable SELinux and set it to enforcing, nacl_helper appears to
  246. # fail to start correctly, possibly disabling sandboxing. The script warns
  247. # about this and suggests a temporary workaround of setting
  248. # SELINUX=permissive in /etc/selinux/config and rebooting. It's hoped to fix
  249. # this SELinux issue more permanently in a future release soon (any help is
  250. # most welcome!).
  251.  
  252. # 3.10 - 24th July
  253. # - Use .so. extension (instead of .so.) for renamed Fedora ld-linux library
  254. # and change ld-linux*.so. references to ld-linux*.so. in ld-linux, libc
  255. # and libstdc++. Thanks to Marcus Sundberg for this suggestion.
  256. # - Dependency list for Google Chrome RPM is now redhat-lsb, wget, xdg-utils,
  257. # GConf2, libXSCrnSaver and libX11 (not 1.3* or 1.4* though).
  258. # - If OS version ("lsb_release -rs") is less than 6.4 then
  259. # offer to "yum update" and refuse to continue if the user declines.
  260. # If you don't update to at least 6.4, bad things can
  261. # happen (I got a hang and a memory allocation error when starting Google
  262. # Chrome on a CentOS 6.0 VM for example).
  263.  
  264. # 3.00 - 21st July
  265. # - Command-line options now supported including -d (delete temp dir),
  266. # -h (syntax help), -n (dry run), -q (quiet) and -u (uninstall).
  267. # - Abort if Google Chrome is running when the script is started.
  268. # - Display any non-zero disk space figures for /opt/google/chrome and the
  269. # temporary download directory at the start and end of the script.
  270.  
  271. # 2.10 - 20th July
  272. # - Can now detect if Fedora RPMs have been archived and will download
  273. # them from the archive site if they're found there instead.
  274. # - Fixed lsb package check, so lsb deps will actually be downloaded now.
  275. # - Follow Fedora library soft-links to determine the actual filenames
  276. # that need to be copied.
  277. # - Removed /etc/cron.daily/google-chrome and
  278. # /etc/yum.repos.d/google-chrome.repo straight after the Google Chrome RPM
  279. # is installed to avoid any potential conflict with old releases.
  280. # - Simplistic check for RHEL derivatives (initially a prompt if the
  281. # script thinks you aren't running one, but a future release will block
  282. # non-derivatives).
  283. # - Early exits due to errors or an interrupt (CTRL-C) will now properly
  284. # tidy up files in the temporary directory and uninstall the Google Chrome
  285. # RPM if it was installed.
  286. # - All downloads now go via a common function, which saves any pre-existing
  287. # file as a .old version and renames it back if the download fails.
  288.  
  289. # 2.00 - 14th July
  290. # - Installed a -bit CentOS 6.4 VM and this enabled me to add initial -bit
  291. # support, though there is an nacl_helper issue that I display a warning for.
  292. # Thanks to Seva Epsteyn for a -bit patch that got the ball rolling.
  293. # - Check for version number of latest Google Chrome and download/install it
  294. # if it hasn't been already.
  295. # - Use updated Fedora RPMs rather than the original ISO versions.
  296. # - Warn if an enabled Google Chrome repo is detected (we don't want it).
  297. # - Tidied main code into separate functions.
  298. # - Added blank lines before/after messages and prefixed them with three stars.
  299. # - Displayed more messages now they're easier to read.
  300.  
  301. # 1.10 - 13th July
  302. # - Added an update check for a new version of this script.
  303. # It will always download/install the new version, but will ask
  304. # if you want to run the new version or exit in case you want to
  305. # code inspect it first.
  306. # - Always force-install a downloaded Google RPM, even if a version
  307. # is already installed. Yes, very obvious it should do this but it
  308. # didn't (slaps forehead).
  309.  
  310. # 1.02 - 13th July
  311. # - Second emergency fix today as someone spotted that wget needed
  312. # "--no-check-certificate" to talk to Google's https download site.
  313. # I didn't need it for the two machines I tested it on though!
  314. # - Added in a check for wget as well while I was at it and it will
  315. # yum install wget if it's not found.
  316.  
  317. # 1.01 - 13th July
  318. # - Bad variable fix if you've not downloaded Google Chrome's RPM yet.
  319. # Serves me right for making a last minute change and not testing it :-(
  320.  
  321. # 1.00 - 13th July
  322. # - Tested on -bit CentOS 6.4 using Fedora libraries. Code is there
  323. # for -bit but has not been tested at all because I have no such systems.
  324.  
  325. message_blank_line()
  326. # $ != "n" (and no quiet mode) to display blank line
  327. {
  328. if [ $quiet -eq -a "$1" != "n" ]
  329. then
  330. echo
  331. fi
  332. }
  333.  
  334. message_output()
  335. # Display $ depending on the quiet mode
  336. {
  337. case "$quiet" in
  338. ) echo "*** $1 ..." ;;
  339. ) echo "$1" ;;
  340. esac
  341. }
  342.  
  343. message()
  344. # Display a message (passed in $) prominently
  345. # $ = "n" to avoid displaying blank lines before or after the message
  346. {
  347. if [ $quiet -eq ]
  348. then
  349. return
  350. fi
  351.  
  352. if [ $dry_run -eq ]
  353. then
  354. echo "Would display the following message:"
  355. message_output "$1"
  356. echo
  357. return
  358. fi
  359.  
  360. message_blank_line "$2"
  361. message_output "$1"
  362. message_blank_line "$2"
  363. }
  364.  
  365. warning()
  366. # $ = Warning message to display to stderr
  367. # $ = "n" to avoid displaying blank lines before or after the message
  368. {
  369. message "WARNING: $1" "$2" >&
  370. }
  371.  
  372. show_space_used()
  373. # Calculate disk space and number of files in install and temp dirs
  374. # and display it if there actually any installed files
  375. {
  376. for each_tree in "$inst_tree" "$tmp_tree"
  377. do
  378. if [ -d "$each_tree" ]
  379. then
  380. num_files="`find \"$each_tree/.\" -type f | wc -l`"
  381. if [ $num_files -gt ]
  382. then
  383. size_files="`du -s \"$each_tree/.\" | awk '{ printf(\"%d\",$1/1024); }'`"
  384. message "$each_tree tree contains $num_files files totalling $size_files MB" "n"
  385. fi
  386. fi
  387. done
  388. }
  389.  
  390. clean_up()
  391. # Remove the stuff we don't want to keep once script finishes
  392. {
  393. # Make sure we don't trash system directories!
  394. if [ "$tmp_tree" != "" -a "$tmp_tree" != "/" -a "$tmp_tree" != "/tmp" ]
  395. then
  396. if [ $delete_tmp -eq ]
  397. then
  398. if [ -d "$tmp_tree" ]
  399. then
  400. if [ $dry_run -eq ]
  401. then
  402. echo "Would delete temporary dir $tmp_tree"
  403. echo
  404. else
  405. cd /
  406. rm -rf "$tmp_tree"
  407. if [ -d "$tmp_tree" ]
  408. then
  409. warning "Failed to delete temporary directory $tmp_tree"
  410. else
  411. message "Deleted temporary directory $tmp_tree"
  412. fi
  413. fi
  414. fi
  415. else
  416. rm_dir_list="etc lib lib64 usr sbin usr var"
  417. if [ $dry_run -eq ]
  418. then
  419. echo "Would delete these directories from inside of $tmp_tree:"
  420. echo "$rm_dir_list"
  421. else
  422. # We delete specific directories so that RPM downloads/builds
  423. # remain and can be re-used if the script is run again
  424. for each_dir in $rm_dir_list
  425. do
  426. rm -rf "$tmp_tree/$each_dir"
  427. done
  428. fi
  429. fi
  430.  
  431. show_space_used
  432. fi
  433. }
  434.  
  435. is_installed()
  436. # See if $ package is installed (returns non-null string if it is)
  437. {
  438. rpm -q "$1" | egrep "($rpmarch|$arch|noarch)" | grep "^$1"
  439. }
  440.  
  441. uninstall_rpms()
  442. # Uninstall $* RPMs if they are installed
  443. {
  444. uninstall_list=""
  445. for each_pack in $*
  446. do
  447. if [ "`is_installed $each_pack`" != "" ]
  448. then
  449. uninstall_list="$uninstall_list $each_pack"
  450. fi
  451. done
  452.  
  453. if [ "$uninstall_list" != "" ]
  454. then
  455. if [ $dry_run -eq ]
  456. then
  457. echo "Would uninstall $uninstall_list using \"yum remove\""
  458. echo
  459. else
  460. message "Uninstalling $uninstall_list"
  461. yum $yum_options remove $uninstall_list
  462. fi
  463. fi
  464. }
  465.  
  466. uninstall_google_chrome()
  467. # Uninstall the Google Chrome and chrome-deps RPMs if they are installed
  468. {
  469. uninstall_rpms $rpm_name $deps_name
  470.  
  471. # Do a final cleanup if /opt/google/chrome persists
  472. if [ "$inst_tree" != "" -a "$inst_tree" != "/" -a "$inst_tree" != "/tmp" ]
  473. then
  474. if [ -d "$inst_tree" -a $dry_run -eq ]
  475. then
  476. warning "$inst_tree install tree still present - deleting it" "n"
  477. cd /
  478. rm -rf "$inst_tree"
  479. if [ -d "$inst_tree" ]
  480. then
  481. warning "Failed to delete $inst_tree install tree" "n"
  482. fi
  483. fi
  484. fi
  485. }
  486.  
  487. error()
  488. # $ = Error message
  489. # Exit script after displaying error message
  490. {
  491. if [ $dry_run -eq ]
  492. then
  493. echo "Would display this error message to stderr:"
  494. echo "ERROR: $1 - aborted"
  495. else
  496. echo >&
  497. echo "ERROR: $1 - aborted" >&
  498. echo >&
  499. fi
  500.  
  501. # A failure means we have to uninstall Google Chrome
  502. # if it got on the system and we were installing, but only
  503. # if we got past the check that it was running
  504. if [ $do_install -eq -a $past_run_check -eq ]
  505. then
  506. uninstall_google_chrome
  507. fi
  508.  
  509. clean_up
  510.  
  511. exit
  512. }
  513.  
  514. interrupt()
  515. # Interrupt received (usually CTRL-C)
  516. {
  517. error "Interrupt (usually CTRL-C) received"
  518. }
  519.  
  520. set_tmp_tree()
  521. # Set tmp_tree variable to $/chrome_install
  522. {
  523. if [ "$1" = "" -o "$1" = "/" -o "`echo \"x$1\" | grep ^x-`" != "" ]
  524. then
  525. error "Invalid temporary directory parent specified ($1)"
  526. fi
  527.  
  528. if [ ! -d "$1" ]
  529. then
  530. warning "Temporary directory parent $1 doesn't exist - will be created"
  531. fi
  532.  
  533. tmp_tree="$1/chrome_install"
  534. unsetsrc="$tmp_tree/unset_var.c"
  535. }
  536.  
  537. check_binary_not_running()
  538. # See if the Google Chrome binary is running and abort if it is
  539. {
  540. if [ $dry_run -eq ]
  541. then
  542. echo "Would check to see if $chrome_name is running and abort if it is."
  543. echo
  544. else
  545. if [ "`ps -ef | grep \"$inst_tree/chrome\" | grep -v grep`" != "" ]
  546. then
  547. error "$chrome_name is running - exit it then re-run this script"
  548. fi
  549. fi
  550. past_run_check=
  551. }
  552.  
  553. yesno()
  554. # $ = Message prompt
  555. # $ = Minimal force level required ( if not stated)
  556. # Returns ans= for no, ans= for yes
  557. {
  558. ans=
  559. if [ $dry_run -eq ]
  560. then
  561. echo "Would be asked here if you wanted to"
  562. echo "$1 (y/n - y is assumed)"
  563. else
  564. if [ "$2" = "" ]
  565. then
  566. minforce=
  567. else
  568. minforce=$
  569. fi
  570.  
  571. if [ $force -lt $minforce ]
  572. then
  573. ans=
  574. fi
  575. fi
  576.  
  577. while [ $ans -eq ]
  578. do
  579. echo -n "Do you want to $1 (y/n) ?" ; read reply
  580. case "$reply" in
  581. Y*|y*) ans= ;;
  582. N*|n*) ans= ;;
  583. *) echo "Please answer y or n" ;;
  584. esac
  585. done
  586. }
  587.  
  588. set_rpm_type()
  589. # Set RPM type to $
  590. # $ = stable, beta or unstable
  591. {
  592. if [ $do_install -eq -a "$1" != "$old_rpm_type" ]
  593. then
  594. case "$1" in
  595. stable|beta|unstable)
  596. if [ $dry_run -eq ]
  597. then
  598. echo "Would prompt to confirm switch to $1 channel"
  599. echo "(assuming y is input)"
  600. echo
  601. else
  602. warning "You have requested to switch to the $1 channel"
  603. if [ $quiet -eq ]
  604. then
  605. echo "This script will uninstall all previously installed $chrome_name"
  606. echo "packages that originated from non-$1 channels."
  607. echo
  608. fi
  609. yesno "install the $1 release (and uninstall all non-$1s)"
  610. if [ $ans -eq ]
  611. then
  612. error "Did not switch to the $1 channel"
  613. fi
  614. fi ;;
  615. *) error "Invalid $chrome_name channel ($1)" ;;
  616. esac
  617.  
  618. check_binary_not_running
  619. uninstall_rpms \
  620. `echo google-chrome-stable google-chrome-beta google-chrome-unstable | \
  621. sed -e "s/google-chrome-$1//g"`
  622. fi
  623.  
  624. case "$1" in
  625. stable|beta|unstable)
  626. rpm_type="$1"
  627. case "$1" in
  628. unstable) csv_type="dev" ;;
  629. *) csv_type="$1" ;;
  630. esac
  631. rpm_name="google-chrome-$1"
  632. chrome_csv="http://omahaproxy.appspot.com/all?os=linux&channel=$csv_type"
  633. chrome_rpm="${rpm_name}_current_$rpmarch.rpm" ;;
  634. *) error "Invalid $chrome_name type ($1)" ;;
  635. esac
  636. }
  637.  
  638. init_vars()
  639. # Initialise variables
  640. # $ = Original $ (i.e. script name)
  641. {
  642. # Set option variables to temporary values so that errors prior to the
  643. # actual option parsing behave sensibly
  644. dry_run= ; do_install= ; delete_tmp=
  645. past_run_check= ; force=
  646.  
  647. # Avoid picking up the Fedora libs for any binaries
  648. # run by this script
  649. unset LD_LIBRARY_PATH
  650.  
  651. if [ "$TMPDIR" = "" ]
  652. then
  653. set_tmp_tree "/tmp"
  654. else
  655. set_tmp_tree "$TMPDIR"
  656. fi
  657.  
  658. arch="`uname -m`"
  659. case "$arch" in
  660. x86_64) rellib="lib64" ; ld_linux="ld-linux-x86-64" ; rpmarch="$arch" ;;
  661. i686) rellib="lib" ; ld_linux="ld-linux" ; rpmarch="i386" ;;
  662. *) error "Unsupported architecture ($arch)" ;;
  663. esac
  664. relusrlib="usr/$rellib"
  665.  
  666. chrome_name="Google Chrome"
  667. chrome_defaults="/etc/default/google-chrome"
  668. chrome_repo="/etc/yum.conf.d/google-chrome.repo"
  669.  
  670. # Find the most stable installed Google Chrome and use that
  671. # as the default for the rest of the script (override with -b, -s or -U)
  672. old_rpm_type=""
  673. for each_old_rpm_type in stable beta unstable
  674. do
  675. if [ "$old_rpm_type" = "" ]
  676. then
  677. if [ "`is_installed google-chrome-$each_old_rpm_type`" != "" ]
  678. then
  679. old_rpm_type="$each_old_rpm_type"
  680. fi
  681. fi
  682. done
  683.  
  684. # If nothing installed at all, default to stable
  685. if [ "$old_rpm_type" = "" ]
  686. then
  687. old_rpm_type="stable"
  688. fi
  689. set_rpm_type "$old_rpm_type"
  690.  
  691. inst_tree="/opt/google/chrome"
  692. libdir="$inst_tree/lib"
  693. chrome_wrapper="$inst_tree/google-chrome"
  694. modify_wrapper="$inst_tree/modify_wrapper"
  695.  
  696. deps_name="chrome-deps"
  697. deps_version="1.21"
  698. deps_latest="`is_installed $deps_name | grep $deps_version`"
  699. wrapper_mod_version="1.01"
  700. install_message="already installed"
  701. trap "interrupt"
  702.  
  703. fedver= # Fedora version with most of the needed libs (F16 doesn't work!)
  704. keyringver= # Fedora version needed for libgnome-keyring package
  705. suffix="$arch.rpm"
  706. # $fedver archived updated packages directory
  707. baseurl="http://archives.fedoraproject.org/pub/archive/fedora/linux/updates/$fedver/$rpmarch"
  708. # Fedora archived libgnome-keyring package directory
  709. baseurlkeyring="http://archives.fedoraproject.org/pub/archive/fedora/linux/releases/$keyringver/Fedora/$rpmarch/os/Packages/l/"
  710. wget="/usr/bin/wget"
  711. wget_options="--no-check-certificate"
  712. yum_options="-y"
  713. rpm_options="-U --force --nodeps"
  714. chcon_options="-u system_u"
  715. rpmbuild_options="-bb"
  716. new_ld_suff=."so.0"
  717.  
  718. # Update checker URL
  719. checksite="http://chrome.richardlloyd.org.uk/"
  720. checkfile="version.dat"
  721. checkurl="$checksite$checkfile"
  722. scriptname="install_chrome.sh"
  723. upgradeurl="$checksite$scriptname"
  724.  
  725. unsetlib="$libdir/unset_var.so"
  726.  
  727. script="$1"
  728. case "$script" in
  729. ./*) script="`pwd`/`basename $script`" ;;
  730. /*) script="$script" ;;
  731. *) script="`pwd`/$script" ;;
  732. esac
  733. }
  734.  
  735. download_file()
  736. # $1 = Full URL to download
  737. # $2 = Optional basename to save to (if omitted, then = basename $1)
  738. # Also allow download to fail without exit if $2 is set
  739. # $3 = Optional cksum value to compare download against
  740. {
  741. if [ "$2" = "" ]
  742. then
  743. dlbase="`basename \"$1\"`"
  744. else
  745. dlbase="$2"
  746. fi
  747.  
  748. if [ $dry_run -eq 1 ]
  749. then
  750. echo "Would download this URL to $tmp_tree/$dlbase :"
  751. echo $1 ; echo
  752. return
  753. fi
  754.  
  755. old_dlbase="$dlbase.old"
  756. if [ -f "$dlbase" ]
  757. then
  758. rm -f "$old_dlbase"
  759. mv -f "$dlbase" "$old_dlbase"
  760. fi
  761.  
  762. message "Downloading $dlbase (please wait)"
  763. $wget $wget_options -O "$dlbase" "$1"
  764.  
  765. if [ -s "$dlbase" -a "$3" != "" ]
  766. then
  767. if [ "`cksum $dlbase`" != "$3" ]
  768. then
  769. rm -f "$dlbase"
  770. warning "Deleted downloaded $dlbase - checksum or size incorrect"
  771. fi
  772. fi
  773.  
  774. if [ ! -s "$dlbase" ]
  775. then
  776. if [ -f "$old_dlbase" ]
  777. then
  778. mv -f "$old_dlbase" "$dlbase"
  779. fi
  780. if [ "$2" = "" -o "$3" != "" ]
  781. then
  782. error "Failed to download $dlbase correctly"
  783. fi
  784. fi
  785. }
  786.  
  787. change_se_context()
  788. # $1 = File or directory name
  789. # Change SELinux context type for $1 to lib_t (or other
  790. # types depending on its name)
  791. {
  792. if [ $selinux_enabled -eq 0 ]
  793. then
  794. # chcon commands fail if SELinux is disabled
  795. return
  796. fi
  797.  
  798. if [ -s "$1" -o -d "$1" ]
  799. then
  800. case "$1" in
  801. *$ld_linux*) con_type="ld_so_t" ;;
  802. $chrome_wrapper) con_type="execmem_exec_t" ;;
  803. $unsetlib) con_type="textrel_shlib_t" ;;
  804. *) con_type="lib_t" ;;
  805. esac
  806.  
  807. if [ $dry_run -eq 1 ]
  808. then
  809. echo "Would change SELinux context type of $1 to $con_type"
  810. echo
  811. else
  812. chcon $chcon_options -t $con_type "$1"
  813. fi
  814. else
  815. if [ $dry_run -eq 0 ]
  816. then
  817. error "Couldn't change SELinux context type of $1 - not found"
  818. fi
  819. fi
  820. }
  821.  
  822. install_ld_preload_lib()
  823. # Compile and install LD_PRELOAD lib as $libdir/unset_var.so
  824. {
  825. if [ $dry_run -eq 1 ]
  826. then
  827. echo "Would compile/install $unsetlib and"
  828. echo "add LD_PRELOAD=$unsetlib to $chrome_wrapper"
  829. echo
  830. return
  831. fi
  832.  
  833. cat <<@EOF >"$unsetsrc"
  834. /* unset_var.c 1.10 (C) Richard K. Lloyd 2014 <rklloyd@gmail.com>
  835.  
  836. LD_PRELOAD code to save LD_LIBRARY_PATH, blank LD_LIBRARY_PATH
  837. if the file to be exec'd isn't a full path, unset LD_PRELOAD,
  838. run the original exec*() library routine and then restore
  839. LD_LIBRARY_PATH and LD_PRELOAD.
  840.  
  841. This way, we can avoid Fedora 15/17 libraries being picked up
  842. by helper apps or plugins that are subsequently loaded by
  843. Google Chrome.
  844.  
  845. strings -a /opt/google/chrome/chrome | grep ^exec
  846. reveals three exec* routines used by the binary:
  847. execvp(), execve() and execlp().
  848.  
  849. Compile with:
  850. gcc -O -fpic -shared -s -o unset_var.so unset_var.c -ldl
  851.  
  852. Run with:
  853. export LD_PRELOAD=/path/to/unset_var.so
  854. /opt/google/chrome/google-chrome
  855. */
  856.  
  857. /* Have to build with this flag defined */
  858. #ifndef _GNU_SOURCE
  859. #define _GNU_SOURCE
  860. #endif
  861.  
  862. /* The environmental variables we're going to unsetenv() */
  863. #define PATH_ENV_VAR "LD_LIBRARY_PATH"
  864. #define PRELOAD_ENV_VAR "LD_PRELOAD"
  865.  
  866. /* Some system headers */
  867. #include <stdio.h>
  868. #include <dlfcn.h>
  869. #include <stdlib.h>
  870. #include <sys/socket.h>
  871. #include <stdarg.h>
  872. #include <string.h>
  873.  
  874. /* Each routine we intercept is likely to have different parameter types
  875. and return types too, so firstly, we create common code macros */
  876.  
  877. /* Define local variables for function, passing in the function return type */
  878. #define INTERCEPT_LOCAL_VARS(return_type) \
  879. char *pathenvptr=getenv(PATH_ENV_VAR), \
  880. *preloadenvptr=getenv(PRELOAD_ENV_VAR); \
  881. static char pathsavebuf[BUFSIZ],preloadsavebuf[BUFSIZ]; \
  882. /* FILE *outhand=fopen("/tmp/exec.log","a"); */ \
  883. return_type retval
  884.  
  885. /* Save PATH_ENV_VAR and PRELOAD_ENV_VAR values in local buffers and then
  886. unset the former if it's not a full path or is a Google Talk plugin path
  887. and always unset the latter */
  888. #define INTERCEPT_SAVE_VAR(fname) \
  889. if (pathenvptr!=(char *)NULL && pathenvptr[]!='\0') \
  890. (void)snprintf(pathsavebuf,BUFSIZ,PATH_ENV_VAR "=%s",pathenvptr); \
  891. else pathsavebuf[]='\0'; \
  892. if (preloadenvptr!=(char *)NULL && preloadenvptr[]!='\0') \
  893. (void)snprintf(preloadsavebuf,BUFSIZ,PRELOAD_ENV_VAR "=%s",preloadenvptr); \
  894. else preloadsavebuf[]='\0'; \
  895. /* if (outhand!=(FILE *)NULL) { fprintf(outhand,"%s\n",fname); (void)fclose(outhand); } */ \
  896. if (strstr(fname,"/")==(char *)NULL || \
  897. strstr(fname,"/opt/google/talkplugin/")!=(char *)NULL || \
  898. !strcmp(fname,"/opt/google/chrome/google-chrome")) unsetenv(PATH_ENV_VAR); \
  899. unsetenv(PRELOAD_ENV_VAR)
  900.  
  901. /* Restore PATH_ENV_VAR and PRELOAD_ENV_VAR values if they had any previously
  902. and then return the value from the function. */
  903. #define INTERCEPT_RESTORE_VAR \
  904. if (pathsavebuf[]) putenv(pathsavebuf); else unsetenv(PATH_ENV_VAR); \
  905. if (preloadsavebuf[]) putenv(preloadsavebuf); else unsetenv(PRELOAD_ENV_VAR); \
  906. return(retval)
  907.  
  908. /* Now string it into macros for different numbers of parameters. */
  909.  
  910. /* execvp() */
  911. #define INTERCEPT_2_PARAMS(return_type,function_name,function_name_str,param_1_type,param_1_name,param_2_type,param_2_name) \
  912. return_type function_name(param_1_type param_1_name,param_2_type param_2_name) \
  913. { \
  914. INTERCEPT_LOCAL_VARS(return_type); \
  915. return_type (*original_##function_name)(param_1_type,param_2_type); \
  916. original_##function_name=dlsym(RTLD_NEXT,function_name_str); \
  917. INTERCEPT_SAVE_VAR(param_1_name); \
  918. retval=(*original_##function_name)(param_1_name,param_2_name); \
  919. INTERCEPT_RESTORE_VAR; \
  920. }
  921.  
  922. /* execve() */
  923. #define INTERCEPT_3_PARAMS(return_type,function_name,function_name_str,param_1_type,param_1_name,param_2_type,param_2_name,param_3_type,param_3_name) \
  924. return_type function_name(param_1_type param_1_name,param_2_type param_2_name,param_3_type param_3_name) \
  925. { \
  926. INTERCEPT_LOCAL_VARS(return_type); \
  927. return_type (*original_##function_name)(param_1_type,param_2_type,param_3_type); \
  928. original_##function_name=dlsym(RTLD_NEXT,function_name_str); \
  929. INTERCEPT_SAVE_VAR(param_1_name); \
  930. retval=(*original_##function_name)(param_1_name,param_2_name,param_3_name); \
  931. INTERCEPT_RESTORE_VAR; \
  932. }
  933.  
  934. /* execlp() - I'm not fully sure I've done the va_list stuff right here! */
  935. #define INTERCEPT_2_VARARGS(return_type,function_name,function_name_str,param_1_type,param_1_name,param_2_type,param_2_name) \
  936. return_type function_name(param_1_type param_1_name,param_2_type param_2_name,...) \
  937. { \
  938. va_list args; \
  939. INTERCEPT_LOCAL_VARS(return_type); \
  940. return_type (*original_##function_name)(param_1_type,param_2_type,...); \
  941. original_##function_name=dlsym(RTLD_NEXT,function_name_str); \
  942. INTERCEPT_SAVE_VAR(param_1_name); \
  943. va_start(args,param_2_name); \
  944. retval=(*original_##function_name)(param_1_name,param_2_name,args); \
  945. va_end(args); \
  946. INTERCEPT_RESTORE_VAR; \
  947. }
  948.  
  949. /* Only 3 routines intercepted so far - may be more in the future */
  950. INTERCEPT_2_PARAMS(int,execvp,"execvp",const char *,file,const char **,argv);
  951. INTERCEPT_3_PARAMS(int,execve,"execve",const char *,filename,const char **,argv,const char **,envp);
  952. INTERCEPT_2_VARARGS(int,execlp,"execlp",const char *,file,const char *,arg);
  953. @EOF
  954.  
  955. if [ -s "$unsetsrc" ]
  956. then
  957. gcc -O -fpic -shared -s -o "$unsetlib" "$unsetsrc" -ldl
  958. rm -f "$unsetsrc"
  959. if [ -s "$unsetlib" ]
  960. then
  961. chmod a+rx "$unsetlib"
  962. change_se_context "$unsetlib"
  963. message "Compiled/installed $unsetlib"
  964. else
  965. error "Failed to compile/install $unsetlib"
  966. fi
  967. else
  968. error "Unable to create $unsetsrc source file"
  969. fi
  970. }
  971.  
  972. install_library()
  973. # $ = Core of basename of RPM filename
  974. # $ = cksum of -bit RPM
  975. # $ = Size of -bit RPM (in bytes)
  976. # $ = cksum of -bit RPM
  977. # $ = Size of -bit RPM (in bytes)
  978. # $ = After unpacking, relative path to library soft-link
  979. # $ = Optional rename filename
  980. {
  981. if [ "$7" = "" ]
  982. then
  983. lib_name="`basename $6`"
  984. else
  985. lib_name="$7"
  986. fi
  987. fname="$libdir/$lib_name"
  988. nonorig="$libdir/`basename $lib_name .orig`"
  989.  
  990. if [ "$fname" != "$nonorig" ]
  991. then
  992. # We hit here if library is patchable -
  993. # we must leave function with the .orig file existing
  994. if [ -s "$nonorig" -a ! -s "$fname" ]
  995. then
  996. # We have the non-.orig file and don't have the .orig one,
  997. # rename one to the other. It will get patched later on.
  998. mv -f "$nonorig" "$fname"
  999. fi
  1000. fi
  1001.  
  1002. # Obvious optimisation here - if Fedora library is already installed,
  1003. # we only change SELinux context (no RPM or extraction needed)
  1004. # as long as patching isn't needed (the patching changed in 3.10+
  1005. # so we can't be sure the patch has been applied).
  1006. if [ -s "$fname" -a "$7" = "" ]
  1007. then
  1008. change_se_context "$fname"
  1009. return
  1010. fi
  1011.  
  1012. rpmfile="$1.$suffix"
  1013. case "$arch" in
  1014. x86_64) rpmcksum="$2 $3 $rpmfile" ;;
  1015. *) rpmcksum="$4 $5 $rpmfile" ;;
  1016. esac
  1017.  
  1018. if [ -s $rpmfile ]
  1019. then
  1020. if [ "`cksum $rpmfile`" != "$rpmcksum" ]
  1021. then
  1022. rm -f $rpmfile
  1023. warning "Deleted pre-existing $rpmfile - checksum or size incorrect"
  1024. fi
  1025. fi
  1026.  
  1027. if [ ! -s $rpmfile ]
  1028. then
  1029. case "$rpmfile" in
  1030. libgnome-keyring*) download_file "$baseurlkeyring/$rpmfile" "$rpmfile" "$rpmcksum" ;;
  1031. *) download_file "$baseurl/$rpmfile" "$rpmfile" "$rpmcksum" ;;
  1032. esac
  1033. fi
  1034.  
  1035. message "Installing $fname" "n"
  1036.  
  1037. if [ $dry_run -eq ]
  1038. then
  1039. echo "Would unpack $rpmfile using rpm2cpio/cpio and"
  1040. echo "then copy $6 to $fname" ; echo
  1041. return
  1042. fi
  1043.  
  1044. rpm2cpio "$rpmfile" | cpio -id >/dev/null
  1045.  
  1046. rel_link="`dirname \"$6\"`/`basename \"$6\" .orig`"
  1047. if [ ! -h "$rel_link" ]
  1048. then
  1049. error "Failed to find $rel_link soft-link (couldn't install $fname)"
  1050. fi
  1051.  
  1052. rel_file="`dirname \"$6\"`/`readlink \"$rel_link\"`"
  1053. if [ ! -s "$rel_file" ]
  1054. then
  1055. error "Failed to find $rel_file file (couldn't install $fname)"
  1056. fi
  1057.  
  1058. rm -f "$fname"
  1059. cp -fp "$rel_file" "$fname"
  1060. if [ -s "$fname" ]
  1061. then
  1062. change_se_context "$fname"
  1063. else
  1064. error "Failed to install $fname"
  1065. fi
  1066. }
  1067.  
  1068. check_version()
  1069. # Make sure that we are running the latest version
  1070. # $* = Params passed to script
  1071. {
  1072. message "Checking for an update to $scriptname" "n"
  1073. download_file "$checkurl"
  1074.  
  1075. if [ $dry_run -eq ]
  1076. then
  1077. echo "Would check if this running script (version $version) is out of date."
  1078. echo "If it's been superseded, the new version would be downloaded and you'd be asked"
  1079. echo "if you want to upgrade to it and run the new version."
  1080. echo
  1081. return
  1082. fi
  1083.  
  1084. newversion="`cat \"$checkfile\"`"
  1085. newversion="`echo $newversion`"
  1086. rm -f "$checkfile"
  1087.  
  1088. if [ "$newversion" = "$version" ]
  1089. then
  1090. message "$scriptname is already the latest version ($version) - continuing" "n"
  1091. else
  1092. message "New version ($newversion) of $scriptname detected - downloading it now"
  1093. download_file "$upgradeurl"
  1094.  
  1095. if [ "$scriptname" -ef "$script" ]
  1096. then
  1097. let a=
  1098. else
  1099. mv -f "$scriptname" "$script"
  1100. fi
  1101. chmod u+x "$script"
  1102. message "Download of $scriptname $newversion successful"
  1103.  
  1104. yesno "run $scriptname $newversion now"
  1105. if [ $ans -eq ]
  1106. then
  1107. message "OK, executing $script $*"
  1108. exec "$script" $*
  1109. error "Failed to run $script $*"
  1110. else
  1111. if [ $quiet -lt ]
  1112. then
  1113. echo
  1114. echo "$scriptname $newversion is available as $script"
  1115. echo "Please inspect the new code and then run the new script."
  1116. echo
  1117. fi
  1118. clean_up
  1119. exit
  1120. fi
  1121. fi
  1122. }
  1123.  
  1124. find_latest_chrome_version()
  1125. # Look on OmahaProxy CSV site or in yum repo for latest version number of linux/$csv_type/current
  1126. {
  1127. message "Determining latest $chrome_name version number (please wait)" "n"
  1128. chrome_latest=""
  1129.  
  1130. # Do we have a Google Chrome RPM already installed and also
  1131. # an enabled yum repo for it too?
  1132. if [ "$chrome_installed" != "" -a "`yum repolist google-chrome enabled | grep ^google-chrome`" != "" ]
  1133. then
  1134. if [ $dry_run -eq ]
  1135. then
  1136. echo "Would use yum check-update to determine if there was a later $chrome_name available."
  1137. echo
  1138. return
  1139. fi
  1140.  
  1141. # We have an enabled repo, do use check-update option to look for an update
  1142. chrome_latest="`yum check-update google-chrome-$rpm_type | grep ^google-chrome-$rpm_type |
  1143. awk '{ print $2; }' | cut -d- -f1`"
  1144. fi
  1145.  
  1146. if [ "$chrome_latest" = "" ]
  1147. then
  1148. # No repo update, so now use OmahaProxy's current CSV to find latest version
  1149. csv_name="chrome_versions.csv"
  1150. download_file "$chrome_csv" "$csv_name"
  1151.  
  1152. if [ $dry_run -eq ]
  1153. then
  1154. echo "Would use OmahaProxy current CSV to determine latest $chrome_name version number"
  1155. echo
  1156. return
  1157. fi
  1158.  
  1159. if [ -s "$csv_name" ]
  1160. then
  1161. chrome_latest="`grep ^linux,$csv_type, \"$csv_name\" | head -1 | cut -d, -f3`"
  1162. fi
  1163. rm -f "$csv_name"
  1164. fi
  1165.  
  1166. if [ "$chrome_latest" = "" ]
  1167. then
  1168. warning "Unable to determine latest $chrome_name version number" "n"
  1169. else
  1170. message "Latest $rpm_name version number is $chrome_latest" "n"
  1171. chrome_name="$chrome_name $chrome_latest"
  1172. fi
  1173. }
  1174.  
  1175. get_installed_version()
  1176. # Find out what version of Google Chrome is installed
  1177. {
  1178. if [ $dry_run -eq ]
  1179. then
  1180. echo "Would use \"$inst_tree/google-chrome --version\" or"
  1181. echo "\"rpm -q $rpm_name\" to determine installed Google Chrome version"
  1182. echo
  1183. return
  1184. fi
  1185.  
  1186. # Look for the installed RPM first and get version from that
  1187. chrome_installed="`is_installed $rpm_name | cut -d- -f4`"
  1188.  
  1189. # If RPM not installed, see if we can use the shell wrapper for the version
  1190. if [ "$chrome_installed" = "" -a -x "$inst_tree/google-chrome" ]
  1191. then
  1192. # This may fail of course if Google Chrome + installed without Fedora libs
  1193. chrome_installed="`\"$inst_tree/google-chrome\" --version 2>/dev/null | awk '{ print $3; }'`"
  1194. fi
  1195.  
  1196. }
  1197.  
  1198. get_downloaded_version()
  1199. # Find out what version of Google Chrome RPM was downloaded
  1200. {
  1201. if [ $dry_run -eq ]
  1202. then
  1203. chrome_downloaded=""
  1204. echo "Would use \"rpm -qp\" on downloaded Google Chrome RPM to find its version"
  1205. echo
  1206. return
  1207. fi
  1208.  
  1209. if [ -s $chrome_rpm ]
  1210. then
  1211. chrome_downloaded="`rpm -qp \"$chrome_rpm\" | cut -d- -f4`"
  1212. if [ "$chrome_downloaded" = "" ]
  1213. then
  1214. error "Can't find version number of $chrome_rpm"
  1215. fi
  1216. else
  1217. chrome_downloaded=""
  1218. fi
  1219. }
  1220.  
  1221. download_chrome_rpm()
  1222. # Download latest RPM because we don't have it downloaded and don't have
  1223. # the latest release installed either
  1224. {
  1225. download_file "https://dl.google.com/linux/direct/$chrome_rpm"
  1226. get_downloaded_version
  1227.  
  1228. if [ $dry_run -eq ]
  1229. then
  1230. return
  1231. fi
  1232.  
  1233. if [ "$chrome_latest" = "" ]
  1234. then
  1235. chrome_latest="$chrome_downloaded"
  1236. fi
  1237.  
  1238. if [ "$chrome_downloaded" != "$chrome_latest" ]
  1239. then
  1240. # Downloaded version is different from what OmahaProxy claims is
  1241. # the latest version, so we need to compare the four dot-separated
  1242. # fields of the version numbers to judge which is the higher.
  1243. dotfield=
  1244. while [ $dotfield -le ]
  1245. do
  1246. dlfield="`echo $chrome_downloaded | cut -d. -f$dotfield`"
  1247. ltfield="`echo $chrome_latest | cut -d. -f$dotfield`"
  1248. if [ "$dlfield" != "" -a "$ltfield" != "" ]
  1249. then
  1250. if [ $dlfield -lt $ltfield ]
  1251. then
  1252. error "Downloaded Google Chrome RPM version ($chrome_downloaded) is older than the latest one ($chrome_latest)"
  1253. else
  1254. # If the downloaded version field is definitely higher, then
  1255. # it's the new latest version and we exit the loop early
  1256. if [ $dlfield -gt $ltfield ]
  1257. then
  1258. chrome_latest="$chrome_downloaded"
  1259. dotfield=
  1260. fi
  1261. fi
  1262. fi
  1263. let dotfield=$dotfield+
  1264. done
  1265. fi
  1266.  
  1267. message "$chrome_name downloaded successfully" "n"
  1268. }
  1269.  
  1270. install_chrome_rpm()
  1271. # We force install the RPM because CentOS 's packages
  1272. # are below the minimum requirements now
  1273. {
  1274. message "Installing $chrome_name RPM (please wait)"
  1275.  
  1276. if [ $dry_run -eq ]
  1277. then
  1278. echo "Would force-install $chrome_rpm RPM and"
  1279. echo "then check the installed version number is the one it should be"
  1280. return
  1281. fi
  1282.  
  1283. check_binary_not_running
  1284. rm -f "$inst_tree/chrome"
  1285. rpm $rpm_options "$chrome_rpm"
  1286. if [ ! -x "$inst_tree/chrome" ]
  1287. then
  1288. error "Failed to install $chrome_name"
  1289. else
  1290. get_installed_version
  1291. if [ "$chrome_installed" = "$chrome_latest" ]
  1292. then
  1293. message "$chrome_name was installed successfully"
  1294. install_message="installed successfully"
  1295. else
  1296. error "Newly-installed Google Chrome version ($chrome_installed) not the latest one ($chrome_latest)"
  1297. fi
  1298. fi
  1299. }
  1300.  
  1301. update_google_chrome()
  1302. # Download and install the latest Google Chrome RPM
  1303. # if it's either out of date or not installed yet
  1304. {
  1305. get_installed_version
  1306. find_latest_chrome_version
  1307. get_downloaded_version
  1308.  
  1309. if [ $dry_run -eq ]
  1310. then
  1311. echo "Would check if installed Google Chrome is the latest version."
  1312. echo "If it isn't, the latest version would be downloaded and installed."
  1313. echo
  1314. return
  1315. fi
  1316.  
  1317. if [ "$chrome_installed" = "$chrome_latest" -a "$chrome_latest" != "" ]
  1318. then
  1319. message "$chrome_name is already installed - skipping installation"
  1320. else
  1321. if [ "$chrome_downloaded" != "$chrome_latest" -o "$chrome_latest" = "" ]
  1322. then
  1323. download_chrome_rpm
  1324. fi
  1325. install_chrome_rpm
  1326. fi
  1327. }
  1328.  
  1329. patch_libs()
  1330. # Hack references to $ld_linux.so. to be $ld_linux.so. in libc.so.,
  1331. # $ld_linux.so., libstdc++.so. and libdl.so. so that we avoid picking up
  1332. # the system version in /$rellib (yes, there's a maddeningly hard-coded path
  1333. # in the ld library that ignores LD_LIBRARY_PATH).
  1334. {
  1335. libc="$libdir/libc.so.6"
  1336. libld="$libdir/$ld_linux$new_ld_suff"
  1337. libcpp="$libdir/libstdc++.so.6"
  1338. libdl="$libdir/libdl.so.2"
  1339.  
  1340. if [ $dry_run -eq ]
  1341. then
  1342. echo "Would patch downloaded $libc, $libld, $libcpp and"
  1343. echo "$libdl to use $ld_linux$new_ld_suff and also"
  1344. echo "set their SELinux context types if necessary."
  1345. echo
  1346. return
  1347. fi
  1348.  
  1349. for each_lib in "$libc" "$libld" "$libcpp" "$libdl"
  1350. do
  1351. each_lib_orig="$each_lib.orig"
  1352. if [ -s "$each_lib_orig" ]
  1353. then
  1354. message "Patching $each_lib" "n"
  1355. sed -e "s/$ld_linux.so.2/$ld_linux$new_ld_suff/g" <"$each_lib_orig" >"$each_lib"
  1356. rm -f "$each_lib_orig"
  1357. if [ -s "$each_lib" ]
  1358. then
  1359. chmod a+rx "$each_lib"
  1360. change_se_context "$each_lib"
  1361. else
  1362. error "Failed to created patched $each_lib"
  1363. fi
  1364. else
  1365. error "$each_lib_orig missing (didn't extract from Fedora RPM)"
  1366. fi
  1367. done
  1368. }
  1369.  
  1370. init_setup()
  1371. # Get everything setup and do a few basic checks
  1372. {
  1373. if [ $quiet -lt ]
  1374. then
  1375. echo "$chrome_name $inst_str $version on the $arch platform"
  1376. echo "(C) Richard K. Lloyd `date +%Y` <rklloyd@gmail.com>"
  1377. show_space_used
  1378. echo
  1379. fi
  1380.  
  1381. if [ $dry_run -eq ]
  1382. then
  1383. echo "Running in dry-run mode (-n) - none of the actions below will be performed."
  1384. if [ $quiet -ne ]
  1385. then
  1386. echo "Please note that combining dry-run and quiet modes isn't a good idea,"
  1387. echo "but I'll continue anyway just to keep you happy."
  1388. fi
  1389. echo
  1390. fi
  1391.  
  1392. # Must run this script as root
  1393. if [ `id -u` -ne ]
  1394. then
  1395. error "You must run $scriptname as the superuser (usually root)"
  1396. fi
  1397.  
  1398. if [ "$tmp_tree" = "" -o "$tmp_tree" = "/tmp" -o "$tmp_tree" = "/" ]
  1399. then
  1400. error "Temporary directory location ($tmp_tree) incorrect"
  1401. fi
  1402.  
  1403. if [ $do_install -eq ]
  1404. then
  1405. return
  1406. fi
  1407.  
  1408. if [ $dry_run -eq ]
  1409. then
  1410. if [ ! -d "$tmp_tree" ]
  1411. then
  1412. echo "Would create temporary $tmp_tree directory"
  1413. fi
  1414. echo "Would change working directory to $tmp_tree"
  1415. echo
  1416. else
  1417. if [ ! -d "$tmp_tree" ]
  1418. then
  1419. message "Creating temporary directory $tmp_tree" "n"
  1420. mkdir -p "$tmp_tree"
  1421. if [ ! -d "$tmp_tree" ]
  1422. then
  1423. error "Couldn't create $tmp_tree directory"
  1424. fi
  1425. fi
  1426.  
  1427. message "Changing working directory to $tmp_tree" "n"
  1428. cd /
  1429. cd "$tmp_tree"
  1430. if [ "`pwd`" != "$tmp_tree" ]
  1431. then
  1432. error "Couldn't change working directory to $tmp_tree"
  1433. fi
  1434. fi
  1435. }
  1436.  
  1437. check_7_repos()
  1438. # See if there's any non-empty repos we haven't created in /etc/yum.repos.d.
  1439. # If there are any, remove the pre-release repo we created in there.
  1440. # If there aren't any, create our own pre-release repo to bring in
  1441. # dependencies from the latest pre-release CentOS .
  1442. # This code will be removed once CentOS final is out.
  1443. {
  1444. our_repo="/etc/yum.repos.d/chrome-deps-updates.repo"
  1445.  
  1446. num_repos=
  1447. repos_list="`ls /etc/yum.repos.d/*.repo 2>/dev/null |
  1448. grep -v -e $our_repo -e $chrome_repo`"
  1449. if [ "$repos_list" != "" ]
  1450. then
  1451. for each_repo in $repos_list
  1452. do
  1453. if [ -s $each_repo ]
  1454. then
  1455. if [ "`grep -v -e '^$' -e '^#' $each_repo`" != "" ]
  1456. then
  1457. let num_repos=$num_repos+
  1458. fi
  1459. fi
  1460. done
  1461. fi
  1462.  
  1463. case "$num_repos" in
  1464. ) cat <<@EOF >$our_repo
  1465. [chrome-deps-updates]
  1466. name=CentOS - Chrome Dependencies Updates
  1467. baseurl=http://buildlogs.centos.org/centos/7/os/x86_64-latest/
  1468. gpgcheck=
  1469. @EOF
  1470. message "$our_repo created" ;;
  1471. *) if [ -s $our_repo ]
  1472. then
  1473. rm -f $our_repo # More than one repo, so remove ours
  1474. message "$our_repo removed because other repos now present"
  1475. fi ;;
  1476. esac
  1477. }
  1478.  
  1479. check_derivative()
  1480. # Check for RHEL or family
  1481. {
  1482. case "`sed -e 's/ /_/g' </etc/redhat-release 2>/dev/null`" in
  1483. *_6.*) centos= ;;
  1484. *_7*) centos= ;;
  1485. *) echo
  1486. echo "This OS doesn't look like it's in the RHEL 6 or 7 family."
  1487. echo "Very bad things could happen if you continue!"
  1488. echo
  1489. yesno "you want to continue"
  1490. if [ $ans -eq ]
  1491. then
  1492. message "OK, but you've been warned (assuming RHEL 7 family)"
  1493. centos=
  1494. else
  1495. error "Probably a wise move"
  1496. fi ;;
  1497. esac
  1498.  
  1499. if [ $centos -eq ]
  1500. then
  1501. # CentOS doesn't need chrome-deps RPM or build tools,
  1502. # but we do need to check it has some updating repos
  1503. deps_name="" ; deps_latest="latest"
  1504. check_7_repos
  1505. fedlibs="was" ; scriptdeps=""
  1506. else
  1507. fedlibs="and Fedora $fedver/$keyringver libs were"
  1508. scriptdeps=" and its dependencies added by this script"
  1509. fi
  1510. }
  1511.  
  1512. yum_install()
  1513. # Download and Install specified packages if they aren't already installed
  1514. # $ = "prompt" Prompt if any of $.. aren't already installed
  1515. # $.. = List of packages to install
  1516. {
  1517. # Nothing to install yet
  1518. install_list=""
  1519.  
  1520. if [ "$1" = "prompt" ]
  1521. then
  1522. prompt= ; promptstr="ask for"
  1523. else
  1524. prompt= ; promptstr="proceed with" ; ans=
  1525. fi
  1526. shift
  1527.  
  1528. for each_dep in $*
  1529. do
  1530. if [ "`is_installed $each_dep`" = "" ]
  1531. then
  1532. install_list="$install_list $each_dep"
  1533. fi
  1534. done
  1535.  
  1536. if [ "$install_list" != "" ]
  1537. then
  1538. if [ $dry_run -eq ]
  1539. then
  1540. echo "Would $promptstr the installation of these packages and their dependencies:"
  1541. echo "$install_list"
  1542. echo
  1543. return
  1544. fi
  1545.  
  1546. echo "The following packages and their dependencies need downloading/installing:"
  1547. echo "$install_list"
  1548. if [ $prompt -eq ]
  1549. then
  1550. echo
  1551. yesno "download/install these packages and dependencies"
  1552. fi
  1553.  
  1554. if [ $ans -eq ]
  1555. then
  1556. message "Downloading/installing $install_list (please wait)"
  1557. yum $yum_options install $install_list
  1558. else
  1559. error "Those packages are required by this script"
  1560. fi
  1561. fi
  1562. }
  1563.  
  1564. check_if_os_obsolete()
  1565. # If OS version is less than 6.5, offer to upgrade (and abort if declined).
  1566. # We need at least 6.5 because bad things happen in earlier versions
  1567. {
  1568. os_version="`lsb_release -rs`"
  1569. case "$os_version" in
  1570. 6.0|6.1|6.2|6.3|6.4)
  1571. if [ $dry_run -eq ]
  1572. then
  1573. echo "Would offer to upgrade your out-of-date OS (version $os_version)."
  1574. echo "If declined, user is warned that they must upgrade their OS and reboot"
  1575. echo "before running $chrome_name."
  1576. echo
  1577. return
  1578. fi
  1579.  
  1580. echo "Your OS version ($os_version) is out-of-date and will probably not"
  1581. echo "run $chrome_name correctly."
  1582. echo
  1583. yesno "upgrade your OS"
  1584.  
  1585. if [ $ans -eq ]
  1586. then
  1587. message "Upgrading OS to latest release" "n"
  1588. message "You will have a final y/n prompt before updates are downloaded/installed"
  1589. yum update
  1590. new_os_version="`lsb_release -rs`"
  1591. if [ "$new_os_version" = "$os_version" ]
  1592. then
  1593. ans=
  1594. warning "You declined an OS update to the latest release"
  1595. else
  1596. message "Upgrade to OS version $new_os_version completed successfully"
  1597. echo "You are STRONGLY RECOMMENDED to reboot this machine to run the new $new_os_version kernel."
  1598. echo "If you don't, it's likely $chrome_name will not run correctly."
  1599. echo "Please close all applications now (except this script!) if you want to reboot."
  1600. warning "These users are logged into this machine: `users | tr ' ' '\n' | sort -u`"
  1601.  
  1602. yesno "reboot this machine immediately"
  1603. if [ $ans -eq ]
  1604. then
  1605. message "Rebooting machine now"
  1606. /sbin/shutdown -r now
  1607. exit
  1608. fi
  1609. warning "Do not run $chrome_name until after the next reboot"
  1610. ans=
  1611. fi
  1612. fi
  1613.  
  1614. if [ $ans -eq ]
  1615. then
  1616. warning "$chrome_name should not be run until you upgrade this machine's OS via \"yum update\" and reboot it after the upgrade"
  1617. fi ;;
  1618. esac
  1619. }
  1620.  
  1621. install_rpm_libraries()
  1622. # Extract and install libraries from Fedora RPMs
  1623. {
  1624. # We need to create library dir because we haven't installed
  1625. # the Google Chrome RPM yet
  1626. if [ ! -d "$libdir" ]
  1627. then
  1628. mkdir -p -m "$libdir"
  1629. if [ ! -d "$libdir" ]
  1630. then
  1631. error "Can't create $chrome_name library dir ($libdir)"
  1632. fi
  1633. fi
  1634.  
  1635. # Function RPM core filename -bit cksum -bit size -bit cksum -bit size Relative soft-link unpacked Optional rename
  1636. install_library libstdc++-4.6.-.fc$fedver $relusrlib/libstdc++.so. libstdc++.so..orig
  1637. install_library glibc-2.14.- $rellib/libc.so. libc.so..orig
  1638. install_library glibc-2.14.- $rellib/$ld_linux.so. $ld_linux$new_ld_suff.orig
  1639. install_library glibc-2.14.- $rellib/libdl.so. libdl.so..orig
  1640. install_library gtk2-2.24.-.fc$fedver $relusrlib/libgdk-x11-2.0.so.
  1641. install_library gtk2-2.24.-.fc$fedver $relusrlib/libgtk-x11-2.0.so.
  1642. install_library glib2-2.28.-.fc$fedver $rellib/libgio-2.0.so.
  1643. install_library glib2-2.28.-.fc$fedver $rellib/libglib-2.0.so.
  1644. install_library glib2-2.28.-.fc$fedver $rellib/libgobject-2.0.so.
  1645. install_library gdk-pixbuf2-2.23.-.fc$fedver $relusrlib/libgdk_pixbuf-2.0.so.
  1646. install_library libgnome-keyring-3.4.-.fc$keyringver $relusrlib/libgnome-keyring.so.
  1647. }
  1648.  
  1649. bulk_warning()
  1650. # Multi-line warning message in $, $ and $
  1651. {
  1652. if [ $dry_run -eq ]
  1653. then
  1654. echo "Would display this warning to stderr:"
  1655. echo "$1"
  1656. echo "$2"
  1657. echo "$3"
  1658. else
  1659. echo >&
  1660. echo "WARNING:" >&
  1661. echo "$1" >&
  1662. echo "$2" >&
  1663. echo "$3." >&
  1664. fi
  1665. }
  1666.  
  1667. final_messages()
  1668. # Display final installation messages before exiting
  1669. {
  1670. if [ $quiet -eq -o $do_install -eq ]
  1671. then
  1672. return
  1673. fi
  1674.  
  1675. echo
  1676. if [ $dry_run -eq ]
  1677. then
  1678. echo "Would display these final messages after a successful run:"
  1679. echo
  1680. fi
  1681.  
  1682. echo "$chrome_name $fedlibs $install_message."
  1683. echo "Please run the browser via the 'google-chrome' command as a non-root user."
  1684. echo
  1685.  
  1686. echo "To update Google Chrome, run \"yum update $rpm_name\" or"
  1687. echo "simply re-run this script with \"./$scriptname\"."
  1688. echo
  1689. echo "To uninstall Google Chrome$scriptdeps,"
  1690. echo "run \"yum remove $rpm_name $deps_name\" or \"./$scriptname -u\"."
  1691. echo
  1692. }
  1693.  
  1694. parse_options()
  1695. # Parse script options passed as $*
  1696. {
  1697. delete_tmp= ; dry_run= ; do_install=
  1698. quiet= ; inst_str="Installer"
  1699. risky_type="$old_rpm_type"
  1700.  
  1701. while [ "x$1" != "x" ]
  1702. do
  1703. case "$1" in
  1704. -\?|-h|--help) show_syntax ; exit ;;
  1705. -b|--beta) risky_type="beta" ;;
  1706. -d|--delete) delete_tmp= ;;
  1707. -f|--force) let force=$force+ ;;
  1708. -n|--dryrun) dry_run= ;;
  1709. -q|--quiet) if [ $quiet -lt ]
  1710. then
  1711. let quiet=$quiet+
  1712. fi ;;
  1713. -s|--stable) risky_type="stable" ;;
  1714. -t|--tmpdir) shift ; set_tmp_tree "$1" ;;
  1715. -u|--uninstall) do_install= ; inst_str="Uninstaller" ;;
  1716. -U|--unstable) risky_type="unstable" ;;
  1717. *) show_syntax >&
  1718. error "Invalid option ($1)" ;;
  1719. esac
  1720. shift
  1721. done
  1722.  
  1723. if [ $quiet -ne ]
  1724. then
  1725. wget_options="$wget_options -q"
  1726. yum_options="$yum_options -q"
  1727. rpm_options="$rpm_options --quiet"
  1728. rpmbuild_options="$rpmbuild_options --quiet"
  1729. else
  1730. rpm_options="$rpm_options -vh"
  1731. chcon_options="$chcon_options -v"
  1732. fi
  1733.  
  1734. if [ "$risky_type" != "$old_rpm_type" ]
  1735. then
  1736. set_rpm_type "$risky_type"
  1737. fi
  1738. }
  1739.  
  1740. create_spec_file()
  1741. # Create chrome-deps.spec file for building the chrome-deps RPM.
  1742. # Many thanks to to Marcus Sandberg for his (public domain) spec file at
  1743. # https://github.com/adamel/chrome-deps which I have used as a basis for the
  1744. # spec file that this script creates.
  1745. {
  1746. ( cat <<@EOF
  1747. # Much of this spec file was taken from Marcus Sandberg's fine (public domain)
  1748. # effort at https://github.com/adamel/chrome-deps although it has been
  1749. # modified compared to his version.
  1750.  
  1751. Name: @DEPS_NAME@
  1752. Version: @DEPS_VERSION@
  1753. Release:
  1754. Summary: Dependencies required for Google Chrome + on RHEL derivatives
  1755. License: LGPLv2+, LGPLv2+ with exceptions, GPLv2+, GPLv3+, GPLv3+ with exceptions, GPLv2+ with exceptions, BSD, public domain
  1756. Group: System Environment/Libraries
  1757. URL: @CHECKSITE@
  1758. Vendor: Richard K. Lloyd and the Fedora Project
  1759. Packager: Richard K. Lloyd <rklloyd@gmail.com>
  1760. BuildRoot: @BUILDROOT@
  1761.  
  1762. %description
  1763. Includes modified Fedora @FEDVER@ and @KEYRINGVER@ Libraries (@LD_LINUX@,
  1764. libc, libdl, libgdk-x11-2.0, libgdk_pixbuf-2.0, libgio-2.0, libglib-2.0,
  1765. libgnome-keyring, libgobject-2.0, libgtk-x11-2.0 and libstdc++) and an
  1766. LD_PRELOAD library (unset_var.so). Also modifies Google Chrome's
  1767. @CHROME_WRAPPER@ wrapper script to allow
  1768. Google Chrome or later to run on RHEL derivatives. SELinux enforcing mode
  1769. will cause startup issues, so it is recommended you switch SELinux to
  1770. permissive mode in that case. The URL for the script that downloaded, modified
  1771. and re-packaged the Fedora @FEDVER@ and @KEYRINGVER@ libraries in this RPM is
  1772. @CHECKSITE@@SCRIPTNAME@
  1773. and it is in the public domain.
  1774.  
  1775. # List of libraries to include in the RPM
  1776. %files
  1777. %defattr(-,root,root,-)
  1778. @MODIFY_WRAPPER@
  1779. @LIBDIR@/@LD_LINUX@.so.
  1780. @LIBDIR@/libc.so.
  1781. @LIBDIR@/libdl.so.
  1782. @LIBDIR@/libgdk-x11-2.0.so.
  1783. @LIBDIR@/libgdk_pixbuf-2.0.so.
  1784. @LIBDIR@/libgio-2.0.so.
  1785. @LIBDIR@/libglib-2.0.so.
  1786. @LIBDIR@/libgnome-keyring.so.
  1787. @LIBDIR@/libgobject-2.0.so.
  1788. @LIBDIR@/libgtk-x11-2.0.so.
  1789. @LIBDIR@/libstdc++.so.
  1790. @LIBDIR@/unset_var.so
  1791.  
  1792. # No prep or build rules because it's all been done by @SCRIPTNAME@
  1793.  
  1794. # Install a copy of libraries into build root
  1795. %install
  1796. rm -rf %{buildroot}
  1797. mkdir -p -m %{buildroot}@LIBDIR@
  1798. cp -pf @MODIFY_WRAPPER@ %{buildroot}@INST_TREE@
  1799. cp -pf @LIBDIR@/*.so.* @LIBDIR@/unset_var.so %{buildroot}@LIBDIR@/
  1800.  
  1801. # Run modify_wrapper once the files are installed
  1802. %post
  1803. @MODIFY_WRAPPER@
  1804.  
  1805. # At end of build, remove build root
  1806. %clean
  1807. rm -rf %{buildroot}
  1808.  
  1809. # Changelog, with annoyingly "wrong" US date format
  1810. %changelog
  1811. * Sat May 17 2014 Richard K. Lloyd <rklloyd@gmail.com> - 1.21-1
  1812. - Unset LD_LIBRARY_PATH for self-calls to the google-chrome script
  1813. Fedora @KEYRINGVER@ RPM.
  1814. * Sat Apr 12 2014 Richard K. Lloyd <rklloyd@gmail.com> - 1.20-1
  1815. - Added libgnome-keyring.so.0, extracted from the libgnome-keyring
  1816. Fedora @KEYRINGVER@ RPM.
  1817. * Wed Dec 11 2013 Richard K. Lloyd <rklloyd@gmail.com> - 1.10-1
  1818. - Additionally saved/unset/restored the LD_PRELOAD environmental
  1819. variable in unset_var.c to stop exec'ed() processes using it.
  1820. * Sat Oct 5 2013 Richard K. Lloyd <rklloyd@gmail.com> - 1.03-1
  1821. - Added libgdk_pixbuf-2.0.so.0, extracted from the gdk-pixbuf2
  1822. Fedora @FEDVER@ RPM.
  1823. * Fri Oct 4 2013 Richard K. Lloyd <rklloyd@gmail.com> - 1.02-1
  1824. - Added libgio-2.0 and libgobject-2.0 to the set of included
  1825. Fedora @FEDVER@ libraries.
  1826. * Thu Aug 8 2013 Richard K. Lloyd <rklloyd@gmail.com> - 1.01-1
  1827. - Updated unset_var.c to fix Google Talk Plugin crash.
  1828. * Sun Jul 28 2013 Richard K. Lloyd <rklloyd@gmail.com> - 1.00-1
  1829. - Initial version based on Marcus Sandberg's fine work at
  1830. https://github.com/adamel/chrome-deps (differences are below).
  1831. - All the Fedora @FEDVER@ and @KEYRINGVER@ library downloads, unpacking and modifications are
  1832. done in the @SCRIPTNAME@ script that generated this spec file, rather
  1833. than run as spec file commands.
  1834. - LD_PRELOAD @UNSETLIB@ library and @MODIFY_WRAPPER@
  1835. script are both included in the built RPM.
  1836. @EOF
  1837. ) | sed \
  1838. -e "s#@DEPS_VERSION@#$deps_version#g" \
  1839. -e "s#@LD_LINUX@#$ld_linux#g" \
  1840. -e "s#@DEPS_NAME@#$deps_name#g" \
  1841. -e "s#@CHECKSITE@#$checksite#g" \
  1842. -e "s#@FEDVER@#$fedver#g" \
  1843. -e "s#@KEYRINGVER@#$keyringver#g" \
  1844. -e "s#@SCRIPTNAME@#$scriptname#g" \
  1845. -e "s#@LIBDIR@#$libdir#g" \
  1846. -e "s#@UNSETLIB@#`basename $unsetlib`#g" \
  1847. -e "s#@CHROME_WRAPPER@#`basename $chrome_wrapper`#g" \
  1848. -e "s#@MODIFY_WRAPPER@#$modify_wrapper#g" \
  1849. -e "s#@INST_TREE@#$inst_tree#g" \
  1850. -e "s#@BUILDROOT@#$rpmbuilddir/BUILDROOT#g" \
  1851. >"$specfile"
  1852. }
  1853.  
  1854. setup_build_env()
  1855. # Create RPM build environment under ~/rpmbuild and also
  1856. # create the chrome-deps.spec file
  1857. {
  1858. rpmbuilddir=~/rpmbuild
  1859. built_rpm="$rpmbuilddir/RPMS/$rpmarch/$built_rpm_base"
  1860. specsdir="$rpmbuilddir/SPECS"
  1861. specfile="$specsdir/$deps_name.spec"
  1862. setuptree="/usr/bin/rpmdev-setuptree"
  1863.  
  1864. if [ $dry_run -eq 1 ]
  1865. then
  1866. echo "Would create the build environment tree ($rpmbuilddir)"
  1867. echo "and also the $deps_name spec file ($specfile)."
  1868. echo
  1869. return
  1870. fi
  1871.  
  1872. if [ ! -d "$specsdir" ]
  1873. then
  1874. if [ -x "$setuptree" ]
  1875. then
  1876. $setuptree
  1877. fi
  1878.  
  1879. if [ ! -d "$specsdir" ]
  1880. then
  1881. error "Unable to correctly run $setuptree to create build enviroment"
  1882. fi
  1883. fi
  1884. }
  1885.  
  1886. build_deps_rpm()
  1887. # Create chrome-deps RPM from the chrome-deps.spec file and install it
  1888. {
  1889. built_rpm_base="$deps_name-$deps_version-1.$rpmarch.rpm"
  1890. tmpdir_rpm="$tmp_tree/$built_rpm_base"
  1891.  
  1892. # Only build latest chrome-deps RPM if we haven't already got it
  1893. if [ ! -s "$tmpdir_rpm" ]
  1894. then
  1895. # Get ready for RPM build
  1896. setup_build_env
  1897.  
  1898. # Create chrome-deps.spec file
  1899. create_spec_file
  1900.  
  1901. if [ $dry_run -eq 1 ]
  1902. then
  1903. echo "Would run rpmbuild to create $tmpdir_rpm"
  1904. echo
  1905. else
  1906. cd "$specsdir"
  1907. message "Building $tmpdir_rpm"
  1908. rm -f "$tmpdir_rpm"
  1909.  
  1910. rpmbuild $rpmbuild_options "`basename \"$specfile\"`"
  1911. rm -f "$specfile"
  1912.  
  1913. # Some users claim that the i386 build tree is actually i686,
  1914. # but that's doesn't happen for me in CentOS or Scientific Linux.
  1915. # Still, let's check for it anyway
  1916. if [ ! -s "$built_rpm" -a "$rpmarch" = "i386" ]
  1917. then
  1918. built_rpm_base="$deps_name-$deps_version-1.i686.rpm"
  1919. built_rpm="$rpmbuilddir/RPMS/i686/$built_rpm_base"
  1920. # We don't change tmpdir_rpm, so this handily renames
  1921. # the final RPM to an i386-based filename below
  1922. fi
  1923.  
  1924. if [ -s "$built_rpm" ]
  1925. then
  1926. mv -f "$built_rpm" "$tmpdir_rpm"
  1927. built_rpm="$tmpdir_rpm"
  1928. fi
  1929.  
  1930. if [ ! -s "$built_rpm" ]
  1931. then
  1932. error "Failed to build $tmpdir_rpm"
  1933. fi
  1934. fi
  1935. fi
  1936.  
  1937. if [ $dry_run -eq 1 ]
  1938. then
  1939. echo "Would install $tmpdir_rpm"
  1940. echo
  1941. else
  1942. message "Installing $tmpdir_rpm"
  1943. rpm $rpm_options "$tmpdir_rpm"
  1944. fi
  1945. }
  1946.  
  1947. adjust_chrome_defaults()
  1948. # Create a modify_wrapper script to be included in chrome-deps that modifies
  1949. # /etc/default/google-chrome if necessary to doing the following:
  1950. # - Remove any existing setting of repo_add_once
  1951. # - Updates (or adds) a custom ### START .. ### END section, which will
  1952. # add an LD_PRELOAD definition to google-chrome if one isn't present.
  1953. # - Sets repo_add_once to true (picked up by /etc/cron.daily/google-chrome)
  1954. # modify_wrapper is run once at the end of the chrome-deps RPM installation.
  1955. {
  1956. if [ $dry_run -eq 1 ]
  1957. then
  1958. echo "Would create a modify_wrapper script to modify $chrome_defaults."
  1959. echo "The script would ensure the creation of $chrome_repo and"
  1960. echo "the addition of a LD_PRELOAD variable to $chrome_wrapper."
  1961. echo
  1962. return
  1963. fi
  1964.  
  1965. ( cat <<@EOF
  1966. #! /bin/bash
  1967. # @MODIFY_WRAPPER@ @WRAPPER_MOD_VERSION@ (C) Richard K. Lloyd 2014 <rklloyd@gmail.com>
  1968. # Created by @SCRIPTNAME@ and included in the @DEPS_NAME@ RPM
  1969. # to modify @CHROME_DEFAULTS@ in the following ways:
  1970. # - Remove any existing setting of repo_add_once
  1971. # - Updates (or adds) a custom ### START .. ### END section, which will
  1972. # add an LD_PRELOAD definition to google-chrome if one isn't present.
  1973. # - Sets repo_add_once to true (picked up by /etc/cron.daily/google-chrome)
  1974. # @MODIFY_WRAPPER@ is run once at the end of the @DEPS_NAME@ RPM installation.
  1975.  
  1976. chrome_defaults="@CHROME_DEFAULTS@"
  1977. progname="\`basename \$0\`"
  1978.  
  1979. error()
  1980. {
  1981. echo "\$progname: ERROR: \$1 - aborted" >&2
  1982. exit 1
  1983. }
  1984.  
  1985. # Create defaults file if it doesn't exist
  1986. touch "\$chrome_defaults"
  1987. if [ ! -f "\$chrome_defaults" ]
  1988. then
  1989. error "Can't create \$chrome_defaults"
  1990. fi
  1991.  
  1992. update_file()
  1993. # \$1 = File to update with contents of stdin
  1994. {
  1995. nfile="\$1.new" ; ofile="\$1.old"
  1996. cat >"\$nfile"
  1997. if [ ! -f "\$nfile" ]
  1998. then
  1999. rm -f "\$nfile"
  2000. error "Failed to create temporary update file \$nfile"
  2001. fi
  2002.  
  2003. # Don't do update if new file is the same as old one
  2004. if [ "\`diff \"\$1\" \"\$nfile\"\`" = "" ]
  2005. then
  2006. rm -f "\$nfile"
  2007. return
  2008. fi
  2009.  
  2010. mv -f "\$1" "\$ofile"
  2011. if [ ! -f "\$ofile" ]
  2012. then
  2013. error "Failed to create temporary backup of \$1"
  2014. fi
  2015.  
  2016. mv -f "\$nfile" "\$1"
  2017. rm -f "\$nfile"
  2018. if [ ! -f "\$1" ]
  2019. then
  2020. mv -f "\$ofile" "\$1"
  2021. chmod a+r "\$1"
  2022. error "Failed to update \$1"
  2023. fi
  2024.  
  2025. chmod a+r "\$1"
  2026. rm -f "\$ofile"
  2027. }
  2028.  
  2029. grep -v repo_add_once= "\$chrome_defaults" | awk '
  2030. BEGIN { wrapper_mod=0; exclude_mod=0; end_of_mod=0; }
  2031. {
  2032. if (\$4==scriptname)
  2033. {
  2034. if (\$2=="START")
  2035. {
  2036. if (\$3==wrapper_mod_version)
  2037. {
  2038. wrapper_mod=1; exclude_mod=0;
  2039. }
  2040. else exclude_mod=1;
  2041. }
  2042. else
  2043. if (\$2=="END") end_of_mod=1;
  2044. }
  2045.  
  2046. if (!exclude_mod) printf("%s\n",\$0);
  2047.  
  2048. if (end_of_mod) { exclude_mod=0; end_of_mod=0; }
  2049. }
  2050. END {
  2051. if (!wrapper_mod)
  2052. {
  2053. printf("### START %s %s modifications\n",
  2054. wrapper_mod_version,scriptname);
  2055. printf("old_line=\"export LD_LIBRARY_PATH\"\n");
  2056. printf("new_line=\"\$old_line LD_PRELOAD=\\\\\"%s\\\\\"\"\n",unsetlib);
  2057. printf("chrome_wrapper=\"%s\"\n",chrome_wrapper);
  2058. printf("if [ -s \"\$chrome_wrapper\" ]\n");
  2059. printf("then\n");
  2060. printf(" if [ \"\`grep \\\\\"\$new_line\\\\\" \\\\\"\$chrome_wrapper\\\\\"\`\" = \"\" ]\n");
  2061. printf(" then\n");
  2062. printf(" new_wrapper=\"\$chrome_wrapper.new\"\n");
  2063. printf(" sed -e \"s#\$old_line#\$new_line#g\" <\"\$chrome_wrapper\" >\"\$new_wrapper\"\n");
  2064. printf(" if [ -s \"\$new_wrapper\" ]\n");
  2065. printf(" then\n");
  2066. printf(" mv -f \"\$new_wrapper\" \"\$chrome_wrapper\"\n");
  2067. printf(" chmod a+rx \"\$chrome_wrapper\"\n");
  2068. printf(" fi\n");
  2069. printf(" fi\n");
  2070. printf("fi\n");
  2071. printf("### END %s %s modifications\n",
  2072. wrapper_mod_version,scriptname);
  2073. }
  2074. printf("repo_add_once=\"true\"\n");
  2075. }' \
  2076. wrapper_mod_version="@WRAPPER_MOD_VERSION@" scriptname="@SCRIPTNAME@" \
  2077. unsetlib="@UNSETLIB@" chrome_wrapper="@CHROME_WRAPPER@" |
  2078. update_file "\$chrome_defaults"
  2079.  
  2080. # Now actually run the defaults file (it will be run daily via cron or
  2081. # when the google-chrome-stable RPM is installed or updated),
  2082. # so that google-chrome is updated if it needs to be
  2083. if [ -s "\$chrome_defaults" ]
  2084. then
  2085. . "\$chrome_defaults"
  2086. fi
  2087.  
  2088. exit 0
  2089. @EOF
  2090. ) | sed \
  2091. -e "s#@MODIFY_WRAPPER@#`basename \"$modify_wrapper\"`#g" \
  2092. -e "s#@WRAPPER_MOD_VERSION@#$wrapper_mod_version#g" \
  2093. -e "s#@SCRIPTNAME@#$scriptname#g" \
  2094. -e "s#@DEPS_NAME@#$deps_name#g" \
  2095. -e "s#@CHROME_DEFAULTS@#$chrome_defaults#g" \
  2096. -e "s#@DEPS_NAME@#$deps_name#g" \
  2097. -e "s#@UNSETLIB@#$unsetlib#g" \
  2098. -e "s#@CHROME_WRAPPER@#$chrome_wrapper#g" \
  2099. >"$modify_wrapper"
  2100.  
  2101. if [ -s "$modify_wrapper" ]
  2102. then
  2103. chmod a+rx "$modify_wrapper"
  2104. change_se_context "$modify_wrapper"
  2105. message "Created $modify_wrapper sucessfully"
  2106. else
  2107. error "Failed to create $modify_wrapper"
  2108. fi
  2109. }
  2110.  
  2111. main_code()
  2112. # Initialisation complete, so run the code
  2113. {
  2114. if [ $do_install -eq 1 ]
  2115. then
  2116. # Only install RPM-building packages if latest chrome-deps isn't installed
  2117. if [ "$deps_latest" = "" ]
  2118. then
  2119. rpm_build_packages="gcc glibc-devel rpm-build rpmdevtools"
  2120. else
  2121. rpm_build_packages=""
  2122. fi
  2123.  
  2124. # Make sure google-chrome-stable and chrome-deps dependencies are present
  2125. # but prompt for their download/install if any aren't
  2126. yum_install prompt redhat-lsb wget xdg-utils GConf2 libXScrnSaver libX11 nss $rpm_build_packages
  2127.  
  2128. # Now update Google Chrome if necessary
  2129. update_google_chrome
  2130.  
  2131. if [ "$deps_latest" = "" ]
  2132. then
  2133. # Download/install/patch Fedora libraries
  2134. install_rpm_libraries
  2135. patch_libs
  2136.  
  2137. # Adjust /etc/default/google-chrome (sourced in daily by
  2138. # /etc/cron.daily/google-chrome) as required
  2139. adjust_chrome_defaults
  2140.  
  2141. # Build/install LD_PRELOAD library if latest chrome-deps not installed
  2142. install_ld_preload_lib
  2143.  
  2144. # Build and install the chrome-deps RPM if the latest isn't installed
  2145. build_deps_rpm
  2146.  
  2147. # That's the end of $libdir changes, so change its SELinux context type
  2148. change_se_context "$libdir"
  2149. fi
  2150. else
  2151. # If it's installed, uninstall Google Chrome and dependency packages
  2152. check_binary_not_running
  2153. uninstall_google_chrome
  2154. fi
  2155. }
  2156.  
  2157. check_selinux()
  2158. # See if SELinux is enabled and if it's enforcing
  2159. {
  2160. selinux_enforcing=0 ; selinux_enabled=0
  2161.  
  2162. # Yes, there's a value-returning util (0=enabled, ho hum, so we flip it)
  2163. # but it may not exist, so fallback on /selinux dir existence
  2164. if [ -x /usr/sbin/selinuxenabled ]
  2165. then
  2166. /usr/sbin/selinuxenabled
  2167. let selinux_enabled=1-$?
  2168. else
  2169. if [ -d /selinux ]
  2170. then
  2171. selinux_enabled=1
  2172. fi
  2173. fi
  2174.  
  2175. if [ $selinux_enabled -eq 1 ]
  2176. then
  2177. # Enforcing mode upsets nacl_helper, so try to see if we're using it
  2178. if [ -f /selinux/enforce ]
  2179. then
  2180. selinux_enforcing="`cat /selinux/enforce`"
  2181. fi
  2182. fi
  2183. }
  2184.  
  2185. # Initialisation functions
  2186. init_vars $0
  2187. check_derivative
  2188. check_selinux
  2189. parse_options $*
  2190. check_binary_not_running
  2191. init_setup
  2192. check_version $*
  2193.  
  2194. # Now do the install or uninstall
  2195. main_code
  2196.  
  2197. # Finalisation functions
  2198. clean_up
  2199. final_messages
  2200.  
  2201. if [ $do_install -eq 1 ]
  2202. then
  2203. # Need at least version 6.5 of OS to run Google Chrome successfully
  2204. check_if_os_obsolete
  2205. fi
  2206.  
  2207. # A good exit
  2208. exit 0

centos chrome的更多相关文章

  1. 解决centos chrome浏览器页面中文显示为方框

    1.系统:centos 7 下载宋体文件:点击下载 把文件放到 /usr/share/fonts/simsun.ttc 依次执行如下命令 mkfontdirmkfontscalefc-cache -f ...

  2. centos x86_64环境下 下载chrome

    由于Cent OS内核版本过低,无法安装Chrome浏览器2.替代方案:可以使用Chromium浏览器 1.切换到root: su - 或者 sudo -i 2.下载新的软件源定义: cd /etc/ ...

  3. Centos安装firefox/chrome

    centos安装chrome:去官网下载chrome安装包(xxx.rpm),带软件安装工具的系统双击该xxx.rpm就能自动安装,或者sudo rpm -i xxx.rpm安装. centos卸载自 ...

  4. CentOS 安装 chrome 浏览器

    安装 google-chrome 浏览器,由于众所周知的原因,一直安装不了,下面介绍一种新方法. cd 到 /etc/yum.repos.d 创建一个yum新源 vi chromium-el6.rep ...

  5. How to install 64-bit Google Chrome 28+ on 64-bit RHEL/CentOS 6 or 7

    How to install 64-bit Google Chrome 28+ on 64-bit RHEL/CentOS 6 or 7 The problem Google developers s ...

  6. CentOS安装Chrome

    问题 在CentOS安装Chrome会遇到 libstdc++.so.6(GLIBCXX_3.4.15)(64bit) 依赖失败的问题, 即使下载了最新的libstdc++.so.6(包含GLIBCX ...

  7. Google Chrome 55 Released – Install on RHEL/CentOS 7/6 and Fedora 25-20

    Google Chrome is a freeware web browser developed by Google Inc. Google Chrome team proudly announce ...

  8. Linux学习总结(九)—— CentOS常用软件安装:中文输入法、Chrome

    中文输入法 切换到root用户,运行以下命令: yum install "@Chinese Support" 按照提示,一路Yes等待安装完成.安装完成后点击左上角System - ...

  9. 芝麻HTTP:在无GUI的CentOS上使用Selenium+Chrome

    各位小伙伴儿的采集日常是不是被JavaScript的各种点击事件折腾的欲仙欲死啊?好不容易找到个Selenium+Chrome可以解决问题! 但是另一个▄█▀█●的事实摆在面前,服务器都特么没有GUI ...

随机推荐

  1. UVA - 11478 Halum 二分+差分约束

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34651 题意: 给定一个有向图,每一条边都有一个权值,每次你可以 ...

  2. shell编程之分隔符

    1 #!/bin/bash 2 line="root:x:0:0:root:/root:bin/bash" 3 oldIFS=$IFS 4 IFS=":" 5 ...

  3. 【BZOJ】【1001】 【BJOI2006】狼抓兔子

    平面图最小割->对偶图最短路 平面图最小割转对偶图最短路= = 想到了就比较好写了…… 可能是我对区域的标号方式比较奇特?反正我没有特判n==1||m==1也能过2333(机智吧-(滚开啦你个自 ...

  4. Windows+Apache+MySQL+PHP(WAMP)环境搭建

    运行操作系统:Windows Server 2008 R2 Apache版本:Apache 2.2 MySQL版本:MySQL 5.5 PHP版本:PHP 5.6.14(当前最新版) 更新日期:201 ...

  5. Gitlab 7.12 发布 SAML支持及其他更多功能

    官方文章:https://about.gitlab.com/2015/06/22/gitlab-7-12-released/ CSDN翻译文章:http://geek.csdn.net/news/de ...

  6. Unity3D判断鼠标向右或向左滑动,响应不同的事件

    private var first = Vector2.zero; private var second = Vector2.zero; function Update () { } function ...

  7. mysql date数据类型异常原因0000-00

    1.数据库字段: `dri_lic_first_time` date DEFAULT NULL COMMENT '驾驶证初次领证日期', 2.异常信息 org.springframework.dao. ...

  8. mysql同时修改2个表思路

    1.需求:修改评论表中的昵称为手机号码最后4位. ,) AND issuer_name LIKE '1%'; 2.由于误操作(MID(issuer_name,4,6)是中间的6位),需要数据回滚. 3 ...

  9. 屏蔽wordpress升级提示

    根据自己的需要,挑选适合的代码放在主题的functions.php文件中就可以了 /* 去除 WordPress 後台升級提示 */ // 2.8 ~ 2.9: add_filter('pre_tra ...

  10. Spring mvc json null

    http://blog.csdn.net/zdsdiablo/article/details/9429263