Guest User

Google Chrome scripts

a guest
Mar 28th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 39.85 KB | None | 0 0
  1. [nenderus@nenderus-pc Google Chrome]$ rpm -qp --scripts google-chrome-stable_current_x86_64.rpm
  2. preinstall scriptlet (through /bin/sh):
  3.  
  4. exit 0
  5.  
  6.  
  7.  
  8.  
  9. #------------------------------------------------------------------------------
  10. #   Post install script
  11. #------------------------------------------------------------------------------
  12. postinstall scriptlet (through /bin/sh):
  13.  
  14. # Add icons to the system icons
  15. XDG_ICON_RESOURCE="`which xdg-icon-resource 2> /dev/null || true`"
  16. if [ ! -x "$XDG_ICON_RESOURCE" ]; then
  17.   echo "Error: Could not find xdg-icon-resource" >&2
  18.   exit 1
  19. fi
  20. for icon in "/opt/google/chrome/product_logo_"*.png; do
  21.   size="${icon##*/product_logo_}"
  22.   "$XDG_ICON_RESOURCE" install --size "${size%.png}" "$icon" "google-chrome"
  23. done
  24.  
  25. UPDATE_MENUS="`which update-menus 2> /dev/null || true`"
  26. if [ -x "$UPDATE_MENUS" ]; then
  27.   update-menus                                                                                                                                                                                                                                                                              
  28. fi                                                                                                                                                                                                                                                                                          
  29.                                                                                                                                                                                                                                                                                            
  30. # Update cache of .desktop file MIME types. Non-fatal since it's just a cache.                                                                                                                                                                                                              
  31. update-desktop-database || true                                                                                                                                                                                                                                                            
  32.                                                                                                                                                                                                                                                                                            
  33. # Updates defaults.list file if present.                                                                                                                                                                                                                                                    
  34. update_defaults_list() {                                                                                                                                                                                                                                                                    
  35.   # $1: name of the .desktop file                                                                                                                                                                                                                                                          
  36.                                                                                                                                                                                                                                                                                            
  37.   local DEFAULTS_FILE="/usr/share/applications/defaults.list"                                                                                                                                                                                                                              
  38.                                                                                                                                                                                                                                                                                            
  39.   if [ ! -f "${DEFAULTS_FILE}" ]; then                                                                                                                                                                                                                                                      
  40.     return                                                                                                                                                                                                                                                                                  
  41.   fi                                                                                                                                                                                                                                                                                        
  42.                                                                                                                                                                                                                                                                                            
  43.   # Split key-value pair out of MimeType= line from the .desktop file,                                                                                                                                                                                                                      
  44.   # then split semicolon-separated list of mime types (they should not contain                                                                                                                                                                                                              
  45.   # spaces).                                                                                                                                                                                                                                                                                
  46.   mime_types="$(grep MimeType= /usr/share/applications/${1} |                                                                                                                                                                                                                              
  47.                cut -d '=' -f 2- |                                                                                                                                                                                                                                                          
  48.                tr ';' ' ')"                                                                                                                                                                                                                                                                
  49.   for mime_type in ${mime_types}; do                                                                                                                                                                                                                                                        
  50.     if egrep -q "^${mime_type}=" "${DEFAULTS_FILE}"; then                                                                                                                                                                                                                                  
  51.       if ! egrep -q "^${mime_type}=.*${1}" "${DEFAULTS_FILE}"; then                                                                                                                                                                                                                        
  52.         default_apps="$(grep ${mime_type}= "${DEFAULTS_FILE}" |                                                                                                                                                                                                                            
  53.                        cut -d '=' -f 2-)"                                                                                                                                                                                                                                                  
  54.         egrep -v "^${mime_type}=" "${DEFAULTS_FILE}" > "${DEFAULTS_FILE}.new"                                                                                                                                                                                                              
  55.         echo "${mime_type}=${default_apps};${1}" >> "${DEFAULTS_FILE}.new"                                                                                                                                                                                                                  
  56.         mv "${DEFAULTS_FILE}.new" "${DEFAULTS_FILE}"                                                                                                                                                                                                                                        
  57.       fi                                                                                                                                                                                                                                                                                    
  58.     else                                                                                                                                                                                                                                                                                    
  59.       # If there's no mention of the mime type in the file, add it.                                                                                                                                                                                                                        
  60.       echo "${mime_type}=${1};" >> "${DEFAULTS_FILE}"                                                                                                                                                                                                                                      
  61.     fi                                                                                                                                                                                                                                                                                      
  62.   done                                                                                                                                                                                                                                                                                      
  63. }                                                                                                                                                                                                                                                                                          
  64.                                                                                                                                                                                                                                                                                            
  65. update_defaults_list "google-chrome.desktop"                                                                                                                                                                                                                                                
  66.                                                                                                                                                                                                                                                                                            
  67. # This function uses sed to insert the contents of one file into another file,                                                                                                                                                                                                              
  68. # after the first line matching a given regular expression. If there is no                                                                                                                                                                                                                  
  69. # matching line, then the file is unchanged.                                                                                                                                                                                                                                                
  70. insert_after_first_match() {                                                                                                                                                                                                                                                                
  71.   # $1: file to update                                                                                                                                                                                                                                                                      
  72.   # $2: regular expression                                                                                                                                                                                                                                                                  
  73.   # $3: file to insert                                                                                                                                                                                                                                                                      
  74.   sed -i -e "1,/$2/ {                                                                                                                                                                                                                                                                      
  75.    /$2/ r $3
  76.    }" "$1"
  77. }
  78.  
  79. # If /usr/share/gnome-control-center/gnome-default-applications.xml exists, it
  80. # may need to be updated to add ourselves to the default applications list. If
  81. # we find the file and it does not seem to contain our patch already (the patch
  82. # is safe to leave even after uninstall), update it.
  83. GNOME_DFL_APPS=/usr/share/gnome-control-center/gnome-default-applications.xml
  84. if [ -f "$GNOME_DFL_APPS" ]; then
  85. # Conditionally insert the contents of the file "default-app-block" after the
  86. # first "<web-browsers>" line we find in gnome-default-applications.xml
  87.   fgrep -q "Google Chrome" "$GNOME_DFL_APPS" || insert_after_first_match \
  88.     "$GNOME_DFL_APPS" \
  89.     "^[         ]*<web-browsers>[       ]*$" \
  90.     "/opt/google/chrome/default-app-block"
  91. fi
  92.  
  93. # System-wide package configuration.
  94. DEFAULTS_FILE="/etc/default/google-chrome"
  95.  
  96. # sources.list setting for google-chrome updates.
  97. REPOCONFIG="http://dl.google.com/linux/chrome/rpm/stable"
  98.  
  99. # Install the repository signing key (see also:
  100. # http://www.google.com/linuxrepositories/aboutkey.html)
  101. install_rpm_key() {
  102.   # Check to see if key already exists.
  103.   rpm -q gpg-pubkey-7fac5991-4615767f > /dev/null 2>&1
  104.   if [ "$?" -eq "0" ]; then
  105.     # Key already exists
  106.     return 0
  107.   fi
  108.   # This is to work around a bug in RPM 4.7.0. (see http://crbug.com/22312)
  109.   rpm -q gpg-pubkey-7fac5991-45f06f46 > /dev/null 2>&1
  110.   if [ "$?" -eq "0" ]; then
  111.     # Key already exists
  112.     return 0
  113.   fi
  114.  
  115.   # RPM on Mandriva 2009 is dumb and does not understand "rpm --import -"
  116.   TMPKEY=$(mktemp /tmp/google.sig.XXXXXX)
  117.   if [ -n "$TMPKEY" ]; then
  118.     cat > "$TMPKEY" <<KEYDATA
  119. -----BEGIN PGP PUBLIC KEY BLOCK-----
  120. Version: GnuPG v1.4.2.2 (GNU/Linux)
  121.  
  122. mQGiBEXwb0YRBADQva2NLpYXxgjNkbuP0LnPoEXruGmvi3XMIxjEUFuGNCP4Rj/a
  123. kv2E5VixBP1vcQFDRJ+p1puh8NU0XERlhpyZrVMzzS/RdWdyXf7E5S8oqNXsoD1z
  124. fvmI+i9b2EhHAA19Kgw7ifV8vMa4tkwslEmcTiwiw8lyUl28Wh4Et8SxzwCggDcA
  125. feGqtn3PP5YAdD0km4S4XeMEAJjlrqPoPv2Gf//tfznY2UyS9PUqFCPLHgFLe80u
  126. QhI2U5jt6jUKN4fHauvR6z3seSAsh1YyzyZCKxJFEKXCCqnrFSoh4WSJsbFNc4PN
  127. b0V0SqiTCkWADZyLT5wll8sWuQ5ylTf3z1ENoHf+G3um3/wk/+xmEHvj9HCTBEXP
  128. 78X0A/0Tqlhc2RBnEf+AqxWvM8sk8LzJI/XGjwBvKfXe+l3rnSR2kEAvGzj5Sg0X
  129. 4XmfTg4Jl8BNjWyvm2Wmjfet41LPmYJKsux3g0b8yzQxeOA4pQKKAU3Z4+rgzGmf
  130. HdwCG5MNT2A5XxD/eDd+L4fRx0HbFkIQoAi1J3YWQSiTk15fw7RMR29vZ2xlLCBJ
  131. bmMuIExpbnV4IFBhY2thZ2UgU2lnbmluZyBLZXkgPGxpbnV4LXBhY2thZ2VzLWtl
  132. eW1hc3RlckBnb29nbGUuY29tPohjBBMRAgAjAhsDBgsJCAcDAgQVAggDBBYCAwEC
  133. HgECF4AFAkYVdn8CGQEACgkQoECDD3+sWZHKSgCfdq3HtNYJLv+XZleb6HN4zOcF
  134. AJEAniSFbuv8V5FSHxeRimHx25671az+uQINBEXwb0sQCACuA8HT2nr+FM5y/kzI
  135. A51ZcC46KFtIDgjQJ31Q3OrkYP8LbxOpKMRIzvOZrsjOlFmDVqitiVc7qj3lYp6U
  136. rgNVaFv6Qu4bo2/ctjNHDDBdv6nufmusJUWq/9TwieepM/cwnXd+HMxu1XBKRVk9
  137. XyAZ9SvfcW4EtxVgysI+XlptKFa5JCqFM3qJllVohMmr7lMwO8+sxTWTXqxsptJo
  138. pZeKz+UBEEqPyw7CUIVYGC9ENEtIMFvAvPqnhj1GS96REMpry+5s9WKuLEaclWpd
  139. K3krttbDlY1NaeQUCRvBYZ8iAG9YSLHUHMTuI2oea07Rh4dtIAqPwAX8xn36JAYG
  140. 2vgLAAMFB/wKqaycjWAZwIe98Yt0qHsdkpmIbarD9fGiA6kfkK/UxjL/k7tmS4Vm
  141. CljrrDZkPSQ/19mpdRcGXtb0NI9+nyM5trweTvtPw+HPkDiJlTaiCcx+izg79Fj9
  142. KcofuNb3lPdXZb9tzf5oDnmm/B+4vkeTuEZJ//IFty8cmvCpzvY+DAz1Vo9rA+Zn
  143. cpWY1n6z6oSS9AsyT/IFlWWBZZ17SpMHu+h4Bxy62+AbPHKGSujEGQhWq8ZRoJAT
  144. G0KSObnmZ7FwFWu1e9XFoUCt0bSjiJWTIyaObMrWu/LvJ3e9I87HseSJStfw6fki
  145. 5og9qFEkMrIrBCp3QGuQWBq/rTdMuwNFiEkEGBECAAkFAkXwb0sCGwwACgkQoECD
  146. D3+sWZF/WACfeNAu1/1hwZtUo1bR+MWiCjpvHtwAnA1R3IHqFLQ2X3xJ40XPuAyY
  147. /FJG
  148. =Quqp
  149. -----END PGP PUBLIC KEY BLOCK-----
  150. KEYDATA
  151.     rpm --import "$TMPKEY"
  152.     rc=$?
  153.     rm -f "$TMPKEY"
  154.     if [ "$rc" -eq "0" ]; then
  155.       return 0
  156.     fi
  157.   fi
  158.   return 1
  159. }
  160.  
  161. determine_rpm_package_manager() {
  162.   local RELEASE
  163.   LSB_RELEASE="$(which lsb_release 2> /dev/null)"
  164.   if [ -x "$LSB_RELEASE" ]; then
  165.     RELEASE=$(lsb_release -i 2> /dev/null | sed 's/:\t/:/' | cut -d ':' -f 2-)
  166.     case $RELEASE in
  167.     "Fedora")
  168.       PACKAGEMANAGER=yum
  169.       ;;
  170.     "MandrivaLinux")
  171.       PACKAGEMANAGER=urpmi
  172.       ;;
  173.     "SUSE LINUX")
  174.       PACKAGEMANAGER=yast
  175.       ;;
  176.     esac
  177.   fi
  178.  
  179.   if [ "$PACKAGEMANAGER" ]; then
  180.     return
  181.   fi
  182.  
  183.   # Fallback methods that are probably unnecessary on modern systems.
  184.   if [ -f "/etc/lsb-release" ]; then
  185.     # file missing on Fedora, does not contain DISTRIB_ID on OpenSUSE.
  186.     eval $(sed -e '/DISTRIB_ID/!d' /etc/lsb-release)
  187.     case $DISTRIB_ID in
  188.     MandrivaLinux)
  189.       PACKAGEMANAGER=urpmi
  190.       ;;
  191.     esac
  192.   fi
  193.  
  194.   if [ "$PACKAGEMANAGER" ]; then
  195.     return
  196.   fi
  197.  
  198.   if [ -f "/etc/fedora-release" ] || [ -f "/etc/redhat-release" ]; then
  199.     PACKAGEMANAGER=yum
  200.   elif [ -f "/etc/SuSE-release" ]; then
  201.     PACKAGEMANAGER=yast
  202.   elif [ -f "/etc/mandriva-release" ]; then
  203.     PACKAGEMANAGER=urpmi
  204.   fi
  205. }
  206.  
  207. DEFAULT_ARCH="x86_64"
  208. YUM_REPO_FILE="/etc/yum.repos.d/google-chrome.repo"
  209. ZYPPER_REPO_FILE="/etc/zypp/repos.d/google-chrome.repo"
  210. URPMI_REPO_FILE="/etc/urpmi/urpmi.cfg"
  211.  
  212. install_yum() {
  213.   install_rpm_key
  214.  
  215.   if [ ! "$REPOCONFIG" ]; then
  216.     return 0
  217.   fi
  218.  
  219.   if [ -d "/etc/yum.repos.d" ]; then
  220. cat > "$YUM_REPO_FILE" << REPOCONTENT
  221. [google-chrome]
  222. name=google-chrome
  223. baseurl=$REPOCONFIG/$DEFAULT_ARCH
  224. enabled=1
  225. gpgcheck=1
  226. REPOCONTENT
  227.   fi
  228. }
  229.  
  230. # This is called by the cron job, rather than in the RPM postinstall.
  231. # We cannot do this during the install when urpmi is running due to
  232. # database locking. We also need to enable the repository, and we can
  233. # only do that while we are online.
  234. # see: https://qa.mandriva.com/show_bug.cgi?id=31893
  235. configure_urpmi() {
  236.   if [ ! "$REPOCONFIG" ]; then
  237.     return 0
  238.   fi
  239.  
  240.   urpmq --list-media | grep -q -s "^google-chrome$"
  241.   if [ "$?" -eq "0" ]; then
  242.     # Repository already configured
  243.     return 0
  244.   fi
  245.   urpmi.addmedia --update \
  246.     "google-chrome" "$REPOCONFIG/$DEFAULT_ARCH"
  247. }
  248.  
  249. install_urpmi() {
  250.   # urpmi not smart enough to pull media_info/pubkey from the repository?
  251.   install_rpm_key
  252.  
  253.   # Defer urpmi.addmedia to configure_urpmi() in the cron job.
  254.   # See comment there.
  255.   #
  256.   # urpmi.addmedia --update \
  257.   #   "google-chrome" "$REPOCONFIG/$DEFAULT_ARCH"
  258. }
  259.  
  260. install_yast() {
  261.   if [ ! "$REPOCONFIG" ]; then
  262.     return 0
  263.   fi
  264.  
  265.   # We defer adding the key to later. See comment in the cron job.
  266.  
  267.   # Ideally, we would run: zypper addrepo -t YUM -f \
  268.   # "$REPOCONFIG/$DEFAULT_ARCH" "google-chrome"
  269.   # but that does not work when zypper is running.
  270.   if [ -d "/etc/zypp/repos.d" ]; then
  271. cat > "$ZYPPER_REPO_FILE" << REPOCONTENT
  272. [google-chrome]
  273. name=google-chrome
  274. enabled=1
  275. autorefresh=1
  276. baseurl=$REPOCONFIG/$DEFAULT_ARCH
  277. type=rpm-md
  278. keeppackages=0
  279. REPOCONTENT
  280.   fi
  281. }
  282.  
  283. # Check if the automatic repository configuration is done, so we know when to
  284. # stop trying.
  285. verify_install() {
  286.   # It's probably enough to see that the repo configs have been created. If they
  287.   # aren't configured properly, update_bad_repo should catch that when it's run.
  288.   case $1 in
  289.   "yum")
  290.     [ -f "$YUM_REPO_FILE" ]
  291.     ;;
  292.   "yast")
  293.     [ -f "$ZYPPER_REPO_FILE" ]
  294.     ;;
  295.   "urpmi")
  296.     urpmq --list-url | grep -q -s "\bgoogle-chrome\b"
  297.     ;;
  298.   esac
  299. }
  300.  
  301. # Update the Google repository if it's not set correctly.
  302. update_bad_repo() {
  303.   if [ ! "$REPOCONFIG" ]; then
  304.     return 0
  305.   fi
  306.  
  307.   determine_rpm_package_manager
  308.  
  309.   case $PACKAGEMANAGER in
  310.   "yum")
  311.     update_repo_file "$YUM_REPO_FILE"
  312.     ;;
  313.   "yast")
  314.     update_repo_file "$ZYPPER_REPO_FILE"
  315.     ;;
  316.   "urpmi")
  317.     update_urpmi_cfg
  318.     ;;
  319.   esac
  320. }
  321.  
  322. update_repo_file() {
  323.   REPO_FILE="$1"
  324.  
  325.   # Don't do anything if the file isn't there, since that probably means the
  326.   # user disabled it.
  327.   if [ ! -r "$REPO_FILE" ]; then
  328.     return 0
  329.   fi
  330.  
  331.   # Check if the correct repository configuration is in there.
  332.   REPOMATCH=$(grep "^baseurl=$REPOCONFIG/$DEFAULT_ARCH" "$REPO_FILE" \
  333.     2>/dev/null)
  334.   # If it's there, nothing to do
  335.   if [ "$REPOMATCH" ]; then
  336.     return 0
  337.   fi
  338.  
  339.   # Check if it's there but disabled by commenting out (as opposed to using the
  340.   # 'enabled' setting).
  341.   MATCH_DISABLED=$(grep "^[[:space:]]*#.*baseurl=$REPOCONFIG/$DEFAULT_ARCH" \
  342.     "$REPO_FILE" 2>/dev/null)
  343.   if [ "$MATCH_DISABLED" ]; then
  344.     # It's OK for it to be disabled, as long as nothing bogus is enabled in its
  345.     # place.
  346.     ACTIVECONFIGS=$(grep "^baseurl=.*" "$REPO_FILE" 2>/dev/null)
  347.     if [ ! "$ACTIVECONFIGS" ]; then
  348.       return 0
  349.     fi
  350.   fi
  351.  
  352.   # If we get here, the correct repository wasn't found, or something else is
  353.   # active, so fix it. This assumes there is a 'baseurl' setting, but if not,
  354.   # then that's just another way of disabling, so we won't try to add it.
  355.   sed -i -e "s,^baseurl=.*,baseurl=$REPOCONFIG/$DEFAULT_ARCH," "$REPO_FILE"
  356. }
  357.  
  358. update_urpmi_cfg() {
  359.   REPOCFG=$(urpmq --list-url | grep "\bgoogle-chrome\b")
  360.   if [ ! "$REPOCFG" ]; then
  361.     # Don't do anything if the repo isn't there, since that probably means the
  362.     # user deleted it.
  363.     return 0
  364.   fi
  365.  
  366.   # See if it's the right repo URL
  367.   REPOMATCH=$(echo "$REPOCFG" | grep "\b$REPOCONFIG/$DEFAULT_ARCH\b")
  368.   # If so, nothing to do
  369.   if [ "$REPOMATCH" ]; then
  370.     return 0
  371.   fi
  372.  
  373.   # Looks like it's the wrong URL, so recreate it.
  374.   urpmi.removemedia "google-chrome" && \
  375.     urpmi.addmedia --update "google-chrome" "$REPOCONFIG/$DEFAULT_ARCH"
  376. }
  377.  
  378. # We only remove the repository configuration during a purge. Since RPM has
  379. # no equivalent to dpkg --purge, the code below is actually never used. We
  380. # keep it only for reference purposes, should we ever need it.
  381. #
  382. #remove_yum() {
  383. #  rm -f "$YUM_REPO_FILE"
  384. #}
  385. #
  386. #remove_urpmi() {
  387. #  # Ideally, we would run: urpmi.removemedia "google-chrome"
  388. #  # but that does not work when urpmi is running.
  389. #  # Sentinel comment text does not work either because urpmi.update removes
  390. #  # all comments. So we just delete the entry that matches what we originally
  391. #  # inserted. If such an entry was added manually, that's tough luck.
  392. #  if [ -f "$URPMI_REPO_FILE" ]; then
  393. #    sed -i '\_^google-chrome $REPOCONFIG/$DEFAULT_ARCH {$_,/^}$/d' "$URPMI_REPO_FILE"
  394. #  fi
  395. #}
  396. #
  397. #remove_yast() {
  398. #  # Ideally, we would run: zypper removerepo "google-chrome"
  399. #  # but that does not work when zypper is running.
  400. #  rm -f /etc/zypp/repos.d/google-chrome.repo
  401. #}
  402.  
  403. DEFAULT_ARCH="x86_64"
  404.  
  405. get_lib_dir() {
  406.   if [ "$DEFAULT_ARCH" = "i386" ]; then
  407.     LIBDIR=lib
  408.   elif [ "$DEFAULT_ARCH" = "x86_64" ]; then
  409.     LIBDIR=lib64
  410.   else
  411.     echo Unknown CPU Architecture: "$DEFAULT_ARCH"
  412.     exit 1
  413.   fi
  414. }
  415.  
  416. NSS_FILES="libnspr4.so.0d libplds4.so.0d libplc4.so.0d libssl3.so.1d \
  417.    libnss3.so.1d libsmime3.so.1d libnssutil3.so.1d"
  418.  
  419. add_nss_symlinks() {
  420.   get_lib_dir
  421.   for f in $NSS_FILES
  422.   do
  423.     target=$(echo $f | sed 's/\.[01]d$//')
  424.     if [ -f "/$LIBDIR/$target" ]; then
  425.       ln -snf "/$LIBDIR/$target" "/opt/google/chrome/$f"
  426.     elif [ -f "/usr/$LIBDIR/$target" ]; then
  427.       ln -snf "/usr/$LIBDIR/$target" "/opt/google/chrome/$f"
  428.     else
  429.       echo $f not found in "/$LIBDIR/$target" or "/usr/$LIBDIR/$target".
  430.       exit 1
  431.     fi
  432.   done
  433. }
  434.  
  435. remove_nss_symlinks() {
  436.   for f in $NSS_FILES
  437.   do
  438.     rm -rf "/opt/google/chrome/$f"
  439.   done
  440. }
  441.  
  442. # Fedora 18 now has libudev.so.1. http://crbug.com/145160
  443. # Same for Ubuntu 13.04. http://crbug.com/226002
  444. LIBUDEV_0=libudev.so.0
  445. LIBUDEV_1=libudev.so.1
  446.  
  447. add_udev_symlinks() {
  448.   get_lib_dir
  449.   if [ -f "/$LIBDIR/$LIBUDEV_0" -o -f "/usr/$LIBDIR/$LIBUDEV_0" -o -f "/lib/$LIBUDEV_0" ]; then
  450.     return 0
  451.   fi
  452.  
  453.   if [ -f "/$LIBDIR/$LIBUDEV_1" ]; then
  454.     ln -snf "/$LIBDIR/$LIBUDEV_1" "/opt/google/chrome/$LIBUDEV_0"
  455.   elif [ -f "/usr/$LIBDIR/$LIBUDEV_1" ];
  456.   then
  457.     ln -snf "/usr/$LIBDIR/$LIBUDEV_1" "/opt/google/chrome/$LIBUDEV_0"
  458.   else
  459.     echo "$LIBUDEV_1" not found in "$LIBDIR" or "/usr/$LIBDIR".
  460.     exit 1
  461.   fi
  462. }
  463.  
  464. remove_udev_symlinks() {
  465.   rm -rf "/opt/google/chrome/$LIBUDEV_0"
  466. }
  467.  
  468. remove_nss_symlinks
  469. add_nss_symlinks
  470.  
  471. remove_udev_symlinks
  472. add_udev_symlinks
  473.  
  474. DEFAULTS_FILE="/etc/default/google-chrome"
  475. if [ ! -e "$DEFAULTS_FILE" ]; then
  476.   echo 'repo_add_once="true"' > "$DEFAULTS_FILE"
  477. fi
  478.  
  479. . "$DEFAULTS_FILE"
  480.  
  481. if [ "$repo_add_once" = "true" ]; then
  482.   determine_rpm_package_manager
  483.  
  484.   case $PACKAGEMANAGER in
  485.   "yum")
  486.     install_yum
  487.     ;;
  488.   "urpmi")
  489.     install_urpmi
  490.     ;;
  491.   "yast")
  492.     install_yast
  493.     ;;
  494.   esac
  495. fi
  496.  
  497. # Some package managers have locks that prevent everything from being
  498. # configured at install time, so wait a bit then kick the cron job to do
  499. # whatever is left. Probably the db will be unlocked by then, but if not, the
  500. # cron job will keep retrying.
  501. # Do this with 'at' instead of a backgrounded shell because zypper waits on all
  502. # sub-shells to finish before it finishes, which is exactly the opposite of
  503. # what we want here. Also preemptively start atd because for some reason it's
  504. # not always running, which kind of defeats the purpose of having 'at' as a
  505. # required LSB command.
  506. service atd start
  507. echo "sh /etc/cron.daily/google-chrome" | at now + 2 minute > /dev/null 2>&1
  508.  
  509. CHANNEL=stable
  510. case $CHANNEL in
  511.   stable )
  512.     PRIORITY=200
  513.     ;;
  514.   beta )
  515.     PRIORITY=150
  516.     ;;
  517.   unstable )
  518.     PRIORITY=120
  519.     ;;
  520.   * )
  521.     PRIORITY=0
  522.     ;;
  523. esac
  524.  
  525. /usr/sbin/update-alternatives --install /usr/bin/google-chrome google-chrome \
  526.   /usr/bin/google-chrome-stable $PRIORITY
  527.  
  528. exit 0
  529.  
  530.  
  531. #------------------------------------------------------------------------------
  532. #   Pre uninstallation script
  533. #------------------------------------------------------------------------------
  534. preuninstall scriptlet (through /bin/sh):
  535.  
  536. if [ "$1" -eq "0" ]; then
  537.   mode="uninstall"
  538. elif [ "$1" -eq "1" ]; then
  539.   mode="upgrade"
  540. fi
  541.  
  542. # System-wide package configuration.
  543. DEFAULTS_FILE="/etc/default/google-chrome"
  544.  
  545. # sources.list setting for google-chrome updates.
  546. REPOCONFIG="http://dl.google.com/linux/chrome/rpm/stable"
  547.  
  548. # Install the repository signing key (see also:
  549. # http://www.google.com/linuxrepositories/aboutkey.html)
  550. install_rpm_key() {
  551.   # Check to see if key already exists.
  552.   rpm -q gpg-pubkey-7fac5991-4615767f > /dev/null 2>&1
  553.   if [ "$?" -eq "0" ]; then
  554.     # Key already exists
  555.     return 0
  556.   fi
  557.   # This is to work around a bug in RPM 4.7.0. (see http://crbug.com/22312)
  558.   rpm -q gpg-pubkey-7fac5991-45f06f46 > /dev/null 2>&1
  559.   if [ "$?" -eq "0" ]; then
  560.     # Key already exists
  561.     return 0
  562.   fi
  563.  
  564.   # RPM on Mandriva 2009 is dumb and does not understand "rpm --import -"
  565.   TMPKEY=$(mktemp /tmp/google.sig.XXXXXX)
  566.   if [ -n "$TMPKEY" ]; then
  567.     cat > "$TMPKEY" <<KEYDATA
  568. -----BEGIN PGP PUBLIC KEY BLOCK-----
  569. Version: GnuPG v1.4.2.2 (GNU/Linux)
  570.  
  571. mQGiBEXwb0YRBADQva2NLpYXxgjNkbuP0LnPoEXruGmvi3XMIxjEUFuGNCP4Rj/a
  572. kv2E5VixBP1vcQFDRJ+p1puh8NU0XERlhpyZrVMzzS/RdWdyXf7E5S8oqNXsoD1z
  573. fvmI+i9b2EhHAA19Kgw7ifV8vMa4tkwslEmcTiwiw8lyUl28Wh4Et8SxzwCggDcA
  574. feGqtn3PP5YAdD0km4S4XeMEAJjlrqPoPv2Gf//tfznY2UyS9PUqFCPLHgFLe80u
  575. QhI2U5jt6jUKN4fHauvR6z3seSAsh1YyzyZCKxJFEKXCCqnrFSoh4WSJsbFNc4PN
  576. b0V0SqiTCkWADZyLT5wll8sWuQ5ylTf3z1ENoHf+G3um3/wk/+xmEHvj9HCTBEXP
  577. 78X0A/0Tqlhc2RBnEf+AqxWvM8sk8LzJI/XGjwBvKfXe+l3rnSR2kEAvGzj5Sg0X
  578. 4XmfTg4Jl8BNjWyvm2Wmjfet41LPmYJKsux3g0b8yzQxeOA4pQKKAU3Z4+rgzGmf
  579. HdwCG5MNT2A5XxD/eDd+L4fRx0HbFkIQoAi1J3YWQSiTk15fw7RMR29vZ2xlLCBJ
  580. bmMuIExpbnV4IFBhY2thZ2UgU2lnbmluZyBLZXkgPGxpbnV4LXBhY2thZ2VzLWtl
  581. eW1hc3RlckBnb29nbGUuY29tPohjBBMRAgAjAhsDBgsJCAcDAgQVAggDBBYCAwEC
  582. HgECF4AFAkYVdn8CGQEACgkQoECDD3+sWZHKSgCfdq3HtNYJLv+XZleb6HN4zOcF
  583. AJEAniSFbuv8V5FSHxeRimHx25671az+uQINBEXwb0sQCACuA8HT2nr+FM5y/kzI
  584. A51ZcC46KFtIDgjQJ31Q3OrkYP8LbxOpKMRIzvOZrsjOlFmDVqitiVc7qj3lYp6U
  585. rgNVaFv6Qu4bo2/ctjNHDDBdv6nufmusJUWq/9TwieepM/cwnXd+HMxu1XBKRVk9
  586. XyAZ9SvfcW4EtxVgysI+XlptKFa5JCqFM3qJllVohMmr7lMwO8+sxTWTXqxsptJo
  587. pZeKz+UBEEqPyw7CUIVYGC9ENEtIMFvAvPqnhj1GS96REMpry+5s9WKuLEaclWpd
  588. K3krttbDlY1NaeQUCRvBYZ8iAG9YSLHUHMTuI2oea07Rh4dtIAqPwAX8xn36JAYG
  589. 2vgLAAMFB/wKqaycjWAZwIe98Yt0qHsdkpmIbarD9fGiA6kfkK/UxjL/k7tmS4Vm
  590. CljrrDZkPSQ/19mpdRcGXtb0NI9+nyM5trweTvtPw+HPkDiJlTaiCcx+izg79Fj9
  591. KcofuNb3lPdXZb9tzf5oDnmm/B+4vkeTuEZJ//IFty8cmvCpzvY+DAz1Vo9rA+Zn
  592. cpWY1n6z6oSS9AsyT/IFlWWBZZ17SpMHu+h4Bxy62+AbPHKGSujEGQhWq8ZRoJAT
  593. G0KSObnmZ7FwFWu1e9XFoUCt0bSjiJWTIyaObMrWu/LvJ3e9I87HseSJStfw6fki
  594. 5og9qFEkMrIrBCp3QGuQWBq/rTdMuwNFiEkEGBECAAkFAkXwb0sCGwwACgkQoECD
  595. D3+sWZF/WACfeNAu1/1hwZtUo1bR+MWiCjpvHtwAnA1R3IHqFLQ2X3xJ40XPuAyY
  596. /FJG
  597. =Quqp
  598. -----END PGP PUBLIC KEY BLOCK-----
  599. KEYDATA
  600.     rpm --import "$TMPKEY"
  601.     rc=$?
  602.     rm -f "$TMPKEY"
  603.     if [ "$rc" -eq "0" ]; then
  604.       return 0
  605.     fi
  606.   fi
  607.   return 1
  608. }
  609.  
  610. determine_rpm_package_manager() {
  611.   local RELEASE
  612.   LSB_RELEASE="$(which lsb_release 2> /dev/null)"
  613.   if [ -x "$LSB_RELEASE" ]; then
  614.     RELEASE=$(lsb_release -i 2> /dev/null | sed 's/:\t/:/' | cut -d ':' -f 2-)
  615.     case $RELEASE in
  616.     "Fedora")
  617.       PACKAGEMANAGER=yum
  618.       ;;
  619.     "MandrivaLinux")
  620.       PACKAGEMANAGER=urpmi
  621.       ;;
  622.     "SUSE LINUX")
  623.       PACKAGEMANAGER=yast
  624.       ;;
  625.     esac
  626.   fi
  627.  
  628.   if [ "$PACKAGEMANAGER" ]; then
  629.     return
  630.   fi
  631.  
  632.   # Fallback methods that are probably unnecessary on modern systems.
  633.   if [ -f "/etc/lsb-release" ]; then
  634.     # file missing on Fedora, does not contain DISTRIB_ID on OpenSUSE.
  635.     eval $(sed -e '/DISTRIB_ID/!d' /etc/lsb-release)
  636.     case $DISTRIB_ID in
  637.     MandrivaLinux)
  638.       PACKAGEMANAGER=urpmi
  639.       ;;
  640.     esac
  641.   fi
  642.  
  643.   if [ "$PACKAGEMANAGER" ]; then
  644.     return
  645.   fi
  646.  
  647.   if [ -f "/etc/fedora-release" ] || [ -f "/etc/redhat-release" ]; then
  648.     PACKAGEMANAGER=yum
  649.   elif [ -f "/etc/SuSE-release" ]; then
  650.     PACKAGEMANAGER=yast
  651.   elif [ -f "/etc/mandriva-release" ]; then
  652.     PACKAGEMANAGER=urpmi
  653.   fi
  654. }
  655.  
  656. DEFAULT_ARCH="x86_64"
  657. YUM_REPO_FILE="/etc/yum.repos.d/google-chrome.repo"
  658. ZYPPER_REPO_FILE="/etc/zypp/repos.d/google-chrome.repo"
  659. URPMI_REPO_FILE="/etc/urpmi/urpmi.cfg"
  660.  
  661. install_yum() {
  662.   install_rpm_key
  663.  
  664.   if [ ! "$REPOCONFIG" ]; then
  665.     return 0
  666.   fi
  667.  
  668.   if [ -d "/etc/yum.repos.d" ]; then
  669. cat > "$YUM_REPO_FILE" << REPOCONTENT
  670. [google-chrome]
  671. name=google-chrome
  672. baseurl=$REPOCONFIG/$DEFAULT_ARCH
  673. enabled=1
  674. gpgcheck=1
  675. REPOCONTENT
  676.   fi
  677. }
  678.  
  679. # This is called by the cron job, rather than in the RPM postinstall.
  680. # We cannot do this during the install when urpmi is running due to
  681. # database locking. We also need to enable the repository, and we can
  682. # only do that while we are online.
  683. # see: https://qa.mandriva.com/show_bug.cgi?id=31893
  684. configure_urpmi() {
  685.   if [ ! "$REPOCONFIG" ]; then
  686.     return 0
  687.   fi
  688.  
  689.   urpmq --list-media | grep -q -s "^google-chrome$"
  690.   if [ "$?" -eq "0" ]; then
  691.     # Repository already configured
  692.     return 0
  693.   fi
  694.   urpmi.addmedia --update \
  695.     "google-chrome" "$REPOCONFIG/$DEFAULT_ARCH"
  696. }
  697.  
  698. install_urpmi() {
  699.   # urpmi not smart enough to pull media_info/pubkey from the repository?
  700.   install_rpm_key
  701.  
  702.   # Defer urpmi.addmedia to configure_urpmi() in the cron job.
  703.   # See comment there.
  704.   #
  705.   # urpmi.addmedia --update \
  706.   #   "google-chrome" "$REPOCONFIG/$DEFAULT_ARCH"
  707. }
  708.  
  709. install_yast() {
  710.   if [ ! "$REPOCONFIG" ]; then
  711.     return 0
  712.   fi
  713.  
  714.   # We defer adding the key to later. See comment in the cron job.
  715.  
  716.   # Ideally, we would run: zypper addrepo -t YUM -f \
  717.   # "$REPOCONFIG/$DEFAULT_ARCH" "google-chrome"
  718.   # but that does not work when zypper is running.
  719.   if [ -d "/etc/zypp/repos.d" ]; then
  720. cat > "$ZYPPER_REPO_FILE" << REPOCONTENT
  721. [google-chrome]
  722. name=google-chrome
  723. enabled=1
  724. autorefresh=1
  725. baseurl=$REPOCONFIG/$DEFAULT_ARCH
  726. type=rpm-md
  727. keeppackages=0
  728. REPOCONTENT
  729.   fi
  730. }
  731.  
  732. # Check if the automatic repository configuration is done, so we know when to
  733. # stop trying.
  734. verify_install() {
  735.   # It's probably enough to see that the repo configs have been created. If they
  736.   # aren't configured properly, update_bad_repo should catch that when it's run.
  737.   case $1 in
  738.   "yum")
  739.     [ -f "$YUM_REPO_FILE" ]
  740.     ;;
  741.   "yast")
  742.     [ -f "$ZYPPER_REPO_FILE" ]
  743.     ;;
  744.   "urpmi")
  745.     urpmq --list-url | grep -q -s "\bgoogle-chrome\b"
  746.     ;;
  747.   esac
  748. }
  749.  
  750. # Update the Google repository if it's not set correctly.
  751. update_bad_repo() {
  752.   if [ ! "$REPOCONFIG" ]; then
  753.     return 0
  754.   fi
  755.  
  756.   determine_rpm_package_manager
  757.  
  758.   case $PACKAGEMANAGER in
  759.   "yum")
  760.     update_repo_file "$YUM_REPO_FILE"
  761.     ;;
  762.   "yast")
  763.     update_repo_file "$ZYPPER_REPO_FILE"
  764.     ;;
  765.   "urpmi")
  766.     update_urpmi_cfg
  767.     ;;
  768.   esac
  769. }
  770.  
  771. update_repo_file() {
  772.   REPO_FILE="$1"
  773.  
  774.   # Don't do anything if the file isn't there, since that probably means the
  775.   # user disabled it.
  776.   if [ ! -r "$REPO_FILE" ]; then
  777.     return 0
  778.   fi
  779.  
  780.   # Check if the correct repository configuration is in there.
  781.   REPOMATCH=$(grep "^baseurl=$REPOCONFIG/$DEFAULT_ARCH" "$REPO_FILE" \
  782.     2>/dev/null)
  783.   # If it's there, nothing to do
  784.   if [ "$REPOMATCH" ]; then
  785.     return 0
  786.   fi
  787.  
  788.   # Check if it's there but disabled by commenting out (as opposed to using the
  789.   # 'enabled' setting).
  790.   MATCH_DISABLED=$(grep "^[[:space:]]*#.*baseurl=$REPOCONFIG/$DEFAULT_ARCH" \
  791.     "$REPO_FILE" 2>/dev/null)
  792.   if [ "$MATCH_DISABLED" ]; then
  793.     # It's OK for it to be disabled, as long as nothing bogus is enabled in its
  794.     # place.
  795.     ACTIVECONFIGS=$(grep "^baseurl=.*" "$REPO_FILE" 2>/dev/null)
  796.     if [ ! "$ACTIVECONFIGS" ]; then
  797.       return 0
  798.     fi
  799.   fi
  800.  
  801.   # If we get here, the correct repository wasn't found, or something else is
  802.   # active, so fix it. This assumes there is a 'baseurl' setting, but if not,
  803.   # then that's just another way of disabling, so we won't try to add it.
  804.   sed -i -e "s,^baseurl=.*,baseurl=$REPOCONFIG/$DEFAULT_ARCH," "$REPO_FILE"
  805. }
  806.  
  807. update_urpmi_cfg() {
  808.   REPOCFG=$(urpmq --list-url | grep "\bgoogle-chrome\b")
  809.   if [ ! "$REPOCFG" ]; then
  810.     # Don't do anything if the repo isn't there, since that probably means the
  811.     # user deleted it.
  812.     return 0
  813.   fi
  814.  
  815.   # See if it's the right repo URL
  816.   REPOMATCH=$(echo "$REPOCFG" | grep "\b$REPOCONFIG/$DEFAULT_ARCH\b")
  817.   # If so, nothing to do
  818.   if [ "$REPOMATCH" ]; then
  819.     return 0
  820.   fi
  821.  
  822.   # Looks like it's the wrong URL, so recreate it.
  823.   urpmi.removemedia "google-chrome" && \
  824.     urpmi.addmedia --update "google-chrome" "$REPOCONFIG/$DEFAULT_ARCH"
  825. }
  826.  
  827. # We only remove the repository configuration during a purge. Since RPM has
  828. # no equivalent to dpkg --purge, the code below is actually never used. We
  829. # keep it only for reference purposes, should we ever need it.
  830. #
  831. #remove_yum() {
  832. #  rm -f "$YUM_REPO_FILE"
  833. #}
  834. #
  835. #remove_urpmi() {
  836. #  # Ideally, we would run: urpmi.removemedia "google-chrome"
  837. #  # but that does not work when urpmi is running.
  838. #  # Sentinel comment text does not work either because urpmi.update removes
  839. #  # all comments. So we just delete the entry that matches what we originally
  840. #  # inserted. If such an entry was added manually, that's tough luck.
  841. #  if [ -f "$URPMI_REPO_FILE" ]; then
  842. #    sed -i '\_^google-chrome $REPOCONFIG/$DEFAULT_ARCH {$_,/^}$/d' "$URPMI_REPO_FILE"
  843. #  fi
  844. #}
  845. #
  846. #remove_yast() {
  847. #  # Ideally, we would run: zypper removerepo "google-chrome"
  848. #  # but that does not work when zypper is running.
  849. #  rm -f /etc/zypp/repos.d/google-chrome.repo
  850. #}
  851.  
  852. DEFAULT_ARCH="x86_64"
  853.  
  854. get_lib_dir() {
  855.   if [ "$DEFAULT_ARCH" = "i386" ]; then
  856.     LIBDIR=lib
  857.   elif [ "$DEFAULT_ARCH" = "x86_64" ]; then
  858.     LIBDIR=lib64
  859.   else
  860.     echo Unknown CPU Architecture: "$DEFAULT_ARCH"
  861.     exit 1
  862.   fi
  863. }
  864.  
  865. NSS_FILES="libnspr4.so.0d libplds4.so.0d libplc4.so.0d libssl3.so.1d \
  866.    libnss3.so.1d libsmime3.so.1d libnssutil3.so.1d"
  867.  
  868. add_nss_symlinks() {
  869.   get_lib_dir
  870.   for f in $NSS_FILES
  871.   do
  872.     target=$(echo $f | sed 's/\.[01]d$//')
  873.     if [ -f "/$LIBDIR/$target" ]; then
  874.       ln -snf "/$LIBDIR/$target" "/opt/google/chrome/$f"
  875.     elif [ -f "/usr/$LIBDIR/$target" ]; then
  876.       ln -snf "/usr/$LIBDIR/$target" "/opt/google/chrome/$f"
  877.     else
  878.       echo $f not found in "/$LIBDIR/$target" or "/usr/$LIBDIR/$target".
  879.       exit 1
  880.     fi
  881.   done
  882. }
  883.  
  884. remove_nss_symlinks() {
  885.   for f in $NSS_FILES
  886.   do
  887.     rm -rf "/opt/google/chrome/$f"
  888.   done
  889. }
  890.  
  891. # Fedora 18 now has libudev.so.1. http://crbug.com/145160
  892. # Same for Ubuntu 13.04. http://crbug.com/226002
  893. LIBUDEV_0=libudev.so.0
  894. LIBUDEV_1=libudev.so.1
  895.  
  896. add_udev_symlinks() {
  897.   get_lib_dir
  898.   if [ -f "/$LIBDIR/$LIBUDEV_0" -o -f "/usr/$LIBDIR/$LIBUDEV_0" -o -f "/lib/$LIBUDEV_0" ]; then
  899.     return 0
  900.   fi
  901.  
  902.   if [ -f "/$LIBDIR/$LIBUDEV_1" ]; then
  903.     ln -snf "/$LIBDIR/$LIBUDEV_1" "/opt/google/chrome/$LIBUDEV_0"
  904.   elif [ -f "/usr/$LIBDIR/$LIBUDEV_1" ];
  905.   then
  906.     ln -snf "/usr/$LIBDIR/$LIBUDEV_1" "/opt/google/chrome/$LIBUDEV_0"
  907.   else
  908.     echo "$LIBUDEV_1" not found in "$LIBDIR" or "/usr/$LIBDIR".
  909.     exit 1
  910.   fi
  911. }
  912.  
  913. remove_udev_symlinks() {
  914.   rm -rf "/opt/google/chrome/$LIBUDEV_0"
  915. }
  916.  
  917. # Only remove menu items and symlinks on uninstall. When upgrading,
  918. # old_pkg's %preun runs after new_pkg's %post.
  919. if [ "$mode" = "uninstall" ]; then
  920. # Remove icons from the system icons
  921. XDG_ICON_RESOURCE="`which xdg-icon-resource 2> /dev/null || true`"
  922. if [ ! -x "$XDG_ICON_RESOURCE" ]; then
  923.   echo "Error: Could not find xdg-icon-resource" >&2
  924.   exit 1
  925. fi
  926. for icon in "/opt/google/chrome/product_logo_"*.png; do
  927.   size="${icon##*/product_logo_}"
  928.   "$XDG_ICON_RESOURCE" uninstall --size "${size%.png}" "google-chrome"
  929. done
  930.  
  931. UPDATE_MENUS="`which update-menus 2> /dev/null || true`"
  932. if [ -x "$UPDATE_MENUS" ]; then
  933.   update-menus
  934. fi
  935.  
  936. # Update cache of .desktop file MIME types. Non-fatal since it's just a cache.
  937. update-desktop-database || true
  938.   remove_nss_symlinks
  939.   remove_udev_symlinks
  940.  
  941.   /usr/sbin/update-alternatives --remove google-chrome \
  942.     /usr/bin/google-chrome-stable
  943. fi
  944.  
  945. # On Debian we only remove when we purge. However, RPM has no equivalent to
  946. # dpkg --purge, so this is all disabled.
  947. #
  948. #determine_rpm_package_manager
  949. #
  950. #case $PACKAGEMANAGER in
  951. #"yum")
  952. #  remove_yum
  953. #  ;;
  954. #"urpmi")
  955. #  remove_urpmi
  956. #  ;;
  957. #"yast")
  958. #  remove_yast
  959. #  ;;
  960. #esac
  961.  
  962. exit 0
  963.  
  964. #------------------------------------------------------------------------------
  965. #   Post uninstallation script
  966. #------------------------------------------------------------------------------
  967. postuninstall scriptlet (through /bin/sh):
  968.  
  969. exit 0
Add Comment
Please, Sign In to add comment