Skip to content

Commit 7dfa716

Browse files
committed
original, unmodified .rpm postinst script and cron file from Chrome
Earlier we pulled out a lot of code from here, but we tried to avoid bringing in the cronjobs, because that felt complicated. Turns out the Chrome people know what they're doing (duh), and the cronjobs are required to handle dist upgrades properly. We need to stick closer to the Chrome approach. This is a verbatim copy of the Chrome cron file for RPM, so that it's easy to see what we're changing in the following commit. More code is duplicated in the postinstall script here, compared to Debian, so we need to pull that in too.
1 parent 797657c commit 7dfa716

2 files changed

Lines changed: 866 additions & 20 deletions

File tree

‎packaging/linux/rpm/cron.template‎

Lines changed: 388 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,388 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
4+
# Use of this source code is governed by a BSD-style license that can be
5+
# found in the LICENSE file.
6+
#
7+
# This script is part of the google-chrome package.
8+
#
9+
# It creates the repository configuration file for package updates, since
10+
# we cannot do this during the google-chrome installation since the repository
11+
# is locked.
12+
#
13+
# This functionality can be controlled by creating the $DEFAULTS_FILE and
14+
# setting "repo_add_once" to "true" or "false" as desired. An empty
15+
# $DEFAULTS_FILE is the same as setting the value to "false".
16+
17+
# System-wide package configuration.
18+
DEFAULTS_FILE="/etc/default/google-chrome"
19+
20+
# sources.list setting for google-chrome updates.
21+
REPOCONFIG="http://dl.google.com/linux/chrome/rpm/stable"
22+
SSLREPOCONFIG="https://dl.google.com/linux/chrome/rpm/stable"
23+
24+
# Install the repository signing key (see also:
25+
# https://www.google.com/linuxrepositories/)
26+
install_rpm_key() {
27+
# Check to see if key already exists.
28+
rpm -q gpg-pubkey-7fac5991-4615767f > /dev/null 2>&1
29+
if [ "$?" -eq "0" ]; then
30+
# Key already exists
31+
return 0
32+
fi
33+
# This is to work around a bug in RPM 4.7.0. (see http://crbug.com/22312)
34+
rpm -q gpg-pubkey-7fac5991-45f06f46 > /dev/null 2>&1
35+
if [ "$?" -eq "0" ]; then
36+
# Key already exists
37+
return 0
38+
fi
39+
40+
# RPM on Mandriva 2009 is dumb and does not understand "rpm --import -"
41+
TMPKEY=$(mktemp /tmp/google.sig.XXXXXX)
42+
if [ -n "$TMPKEY" ]; then
43+
cat > "$TMPKEY" <<KEYDATA
44+
-----BEGIN PGP PUBLIC KEY BLOCK-----
45+
Version: GnuPG v1.4.2.2 (GNU/Linux)
46+
47+
mQGiBEXwb0YRBADQva2NLpYXxgjNkbuP0LnPoEXruGmvi3XMIxjEUFuGNCP4Rj/a
48+
kv2E5VixBP1vcQFDRJ+p1puh8NU0XERlhpyZrVMzzS/RdWdyXf7E5S8oqNXsoD1z
49+
fvmI+i9b2EhHAA19Kgw7ifV8vMa4tkwslEmcTiwiw8lyUl28Wh4Et8SxzwCggDcA
50+
feGqtn3PP5YAdD0km4S4XeMEAJjlrqPoPv2Gf//tfznY2UyS9PUqFCPLHgFLe80u
51+
QhI2U5jt6jUKN4fHauvR6z3seSAsh1YyzyZCKxJFEKXCCqnrFSoh4WSJsbFNc4PN
52+
b0V0SqiTCkWADZyLT5wll8sWuQ5ylTf3z1ENoHf+G3um3/wk/+xmEHvj9HCTBEXP
53+
78X0A/0Tqlhc2RBnEf+AqxWvM8sk8LzJI/XGjwBvKfXe+l3rnSR2kEAvGzj5Sg0X
54+
4XmfTg4Jl8BNjWyvm2Wmjfet41LPmYJKsux3g0b8yzQxeOA4pQKKAU3Z4+rgzGmf
55+
HdwCG5MNT2A5XxD/eDd+L4fRx0HbFkIQoAi1J3YWQSiTk15fw7RMR29vZ2xlLCBJ
56+
bmMuIExpbnV4IFBhY2thZ2UgU2lnbmluZyBLZXkgPGxpbnV4LXBhY2thZ2VzLWtl
57+
eW1hc3RlckBnb29nbGUuY29tPohjBBMRAgAjAhsDBgsJCAcDAgQVAggDBBYCAwEC
58+
HgECF4AFAkYVdn8CGQEACgkQoECDD3+sWZHKSgCfdq3HtNYJLv+XZleb6HN4zOcF
59+
AJEAniSFbuv8V5FSHxeRimHx25671az+uQINBEXwb0sQCACuA8HT2nr+FM5y/kzI
60+
A51ZcC46KFtIDgjQJ31Q3OrkYP8LbxOpKMRIzvOZrsjOlFmDVqitiVc7qj3lYp6U
61+
rgNVaFv6Qu4bo2/ctjNHDDBdv6nufmusJUWq/9TwieepM/cwnXd+HMxu1XBKRVk9
62+
XyAZ9SvfcW4EtxVgysI+XlptKFa5JCqFM3qJllVohMmr7lMwO8+sxTWTXqxsptJo
63+
pZeKz+UBEEqPyw7CUIVYGC9ENEtIMFvAvPqnhj1GS96REMpry+5s9WKuLEaclWpd
64+
K3krttbDlY1NaeQUCRvBYZ8iAG9YSLHUHMTuI2oea07Rh4dtIAqPwAX8xn36JAYG
65+
2vgLAAMFB/wKqaycjWAZwIe98Yt0qHsdkpmIbarD9fGiA6kfkK/UxjL/k7tmS4Vm
66+
CljrrDZkPSQ/19mpdRcGXtb0NI9+nyM5trweTvtPw+HPkDiJlTaiCcx+izg79Fj9
67+
KcofuNb3lPdXZb9tzf5oDnmm/B+4vkeTuEZJ//IFty8cmvCpzvY+DAz1Vo9rA+Zn
68+
cpWY1n6z6oSS9AsyT/IFlWWBZZ17SpMHu+h4Bxy62+AbPHKGSujEGQhWq8ZRoJAT
69+
G0KSObnmZ7FwFWu1e9XFoUCt0bSjiJWTIyaObMrWu/LvJ3e9I87HseSJStfw6fki
70+
5og9qFEkMrIrBCp3QGuQWBq/rTdMuwNFiEkEGBECAAkFAkXwb0sCGwwACgkQoECD
71+
D3+sWZF/WACfeNAu1/1hwZtUo1bR+MWiCjpvHtwAnA1R3IHqFLQ2X3xJ40XPuAyY
72+
/FJG
73+
=Quqp
74+
-----END PGP PUBLIC KEY BLOCK-----
75+
KEYDATA
76+
rpm --import "$TMPKEY"
77+
rc=$?
78+
rm -f "$TMPKEY"
79+
if [ "$rc" -eq "0" ]; then
80+
return 0
81+
fi
82+
fi
83+
return 1
84+
}
85+
86+
determine_rpm_package_manager() {
87+
local RELEASE
88+
LSB_RELEASE="$(which lsb_release 2> /dev/null)"
89+
if [ -x "$LSB_RELEASE" ]; then
90+
RELEASE=$(lsb_release -i 2> /dev/null | sed 's/:\t/:/' | cut -d ':' -f 2-)
91+
case $RELEASE in
92+
"Fedora")
93+
PACKAGEMANAGER=yum
94+
;;
95+
"Mageia"|"MandrivaLinux")
96+
PACKAGEMANAGER=urpmi
97+
;;
98+
"SUSE LINUX")
99+
PACKAGEMANAGER=yast
100+
;;
101+
esac
102+
fi
103+
104+
if [ "$PACKAGEMANAGER" ]; then
105+
return
106+
fi
107+
108+
# Fallback methods that are probably unnecessary on modern systems.
109+
if [ -f "/etc/lsb-release" ]; then
110+
# file missing on Fedora, does not contain DISTRIB_ID on OpenSUSE.
111+
eval $(sed -e '/DISTRIB_ID/!d' /etc/lsb-release)
112+
case $DISTRIB_ID in
113+
MandrivaLinux)
114+
PACKAGEMANAGER=urpmi
115+
;;
116+
esac
117+
fi
118+
119+
if [ "$PACKAGEMANAGER" ]; then
120+
return
121+
fi
122+
123+
if [ -f "/etc/fedora-release" ] || [ -f "/etc/redhat-release" ]; then
124+
PACKAGEMANAGER=yum
125+
elif [ -f "/etc/SuSE-release" ]; then
126+
PACKAGEMANAGER=yast
127+
elif [ -f "/etc/mandriva-release" ]; then
128+
PACKAGEMANAGER=urpmi
129+
fi
130+
}
131+
132+
DEFAULT_ARCH="x86_64"
133+
YUM_REPO_FILE="/etc/yum.repos.d/google-chrome.repo"
134+
ZYPPER_REPO_FILE="/etc/zypp/repos.d/google-chrome.repo"
135+
URPMI_REPO_FILE="/etc/urpmi/urpmi.cfg"
136+
137+
install_yum() {
138+
install_rpm_key
139+
140+
if [ ! "$REPOCONFIG" ]; then
141+
return 0
142+
fi
143+
144+
if [ -d "/etc/yum.repos.d" ]; then
145+
cat > "$YUM_REPO_FILE" << REPOCONTENT
146+
[google-chrome]
147+
name=google-chrome
148+
baseurl=$REPOCONFIG/$DEFAULT_ARCH
149+
enabled=1
150+
gpgcheck=1
151+
gpgkey=https://dl.google.com/linux/linux_signing_key.pub
152+
REPOCONTENT
153+
fi
154+
}
155+
156+
# This is called by the cron job, rather than in the RPM postinstall.
157+
# We cannot do this during the install when urpmi is running due to
158+
# database locking. We also need to enable the repository, and we can
159+
# only do that while we are online.
160+
# see: https://qa.mandriva.com/show_bug.cgi?id=31893
161+
configure_urpmi() {
162+
if [ ! "$REPOCONFIG" ]; then
163+
return 0
164+
fi
165+
166+
urpmq --list-media | grep -q -s "^google-chrome$"
167+
if [ "$?" -eq "0" ]; then
168+
# Repository already configured
169+
return 0
170+
fi
171+
urpmi.addmedia --update \
172+
"google-chrome" "$REPOCONFIG/$DEFAULT_ARCH"
173+
}
174+
175+
install_urpmi() {
176+
# urpmi not smart enough to pull media_info/pubkey from the repository?
177+
install_rpm_key
178+
179+
# Defer urpmi.addmedia to configure_urpmi() in the cron job.
180+
# See comment there.
181+
#
182+
# urpmi.addmedia --update \
183+
# "google-chrome" "$REPOCONFIG/$DEFAULT_ARCH"
184+
}
185+
186+
install_yast() {
187+
if [ ! "$REPOCONFIG" ]; then
188+
return 0
189+
fi
190+
191+
# We defer adding the key to later. See comment in the cron job.
192+
193+
# Ideally, we would run: zypper addrepo -t YUM -f \
194+
# "$REPOCONFIG/$DEFAULT_ARCH" "google-chrome"
195+
# but that does not work when zypper is running.
196+
if [ -d "/etc/zypp/repos.d" ]; then
197+
cat > "$ZYPPER_REPO_FILE" << REPOCONTENT
198+
[google-chrome]
199+
name=google-chrome
200+
enabled=1
201+
autorefresh=1
202+
baseurl=$REPOCONFIG/$DEFAULT_ARCH
203+
type=rpm-md
204+
keeppackages=0
205+
REPOCONTENT
206+
fi
207+
}
208+
209+
# Check if the automatic repository configuration is done, so we know when to
210+
# stop trying.
211+
verify_install() {
212+
# It's probably enough to see that the repo configs have been created. If they
213+
# aren't configured properly, update_bad_repo should catch that when it's run.
214+
case $1 in
215+
"yum")
216+
[ -f "$YUM_REPO_FILE" ]
217+
;;
218+
"yast")
219+
[ -f "$ZYPPER_REPO_FILE" ]
220+
;;
221+
"urpmi")
222+
urpmq --list-url | grep -q -s "\bgoogle-chrome\b"
223+
;;
224+
esac
225+
}
226+
227+
# Update the Google repository if it's not set correctly.
228+
update_bad_repo() {
229+
if [ ! "$REPOCONFIG" ]; then
230+
return 0
231+
fi
232+
233+
determine_rpm_package_manager
234+
235+
case $PACKAGEMANAGER in
236+
"yum")
237+
update_repo_file "$YUM_REPO_FILE"
238+
;;
239+
"yast")
240+
update_repo_file "$ZYPPER_REPO_FILE"
241+
;;
242+
"urpmi")
243+
update_urpmi_cfg
244+
;;
245+
esac
246+
}
247+
248+
update_repo_file() {
249+
REPO_FILE="$1"
250+
251+
# Don't do anything if the file isn't there, since that probably means the
252+
# user disabled it.
253+
if [ ! -r "$REPO_FILE" ]; then
254+
return 0
255+
fi
256+
257+
# Check if the correct repository configuration is in there.
258+
REPOMATCH=$(grep "^baseurl=$REPOCONFIG/$DEFAULT_ARCH" "$REPO_FILE" \
259+
2>/dev/null)
260+
# If it's there, nothing to do
261+
if [ "$REPOMATCH" ]; then
262+
return 0
263+
fi
264+
265+
# Check if it's there but disabled by commenting out (as opposed to using the
266+
# 'enabled' setting).
267+
MATCH_DISABLED=$(grep "^[[:space:]]*#.*baseurl=$REPOCONFIG/$DEFAULT_ARCH" \
268+
"$REPO_FILE" 2>/dev/null)
269+
if [ "$MATCH_DISABLED" ]; then
270+
# It's OK for it to be disabled, as long as nothing bogus is enabled in its
271+
# place.
272+
ACTIVECONFIGS=$(grep "^baseurl=.*" "$REPO_FILE" 2>/dev/null)
273+
if [ ! "$ACTIVECONFIGS" ]; then
274+
return 0
275+
fi
276+
fi
277+
278+
# If we get here, the correct repository wasn't found, or something else is
279+
# active, so fix it. This assumes there is a 'baseurl' setting, but if not,
280+
# then that's just another way of disabling, so we won't try to add it.
281+
sed -i -e "s,^baseurl=.*,baseurl=$REPOCONFIG/$DEFAULT_ARCH," "$REPO_FILE"
282+
}
283+
284+
update_urpmi_cfg() {
285+
REPOCFG=$(urpmq --list-url | grep "\bgoogle-chrome\b")
286+
if [ ! "$REPOCFG" ]; then
287+
# Don't do anything if the repo isn't there, since that probably means the
288+
# user deleted it.
289+
return 0
290+
fi
291+
292+
# See if it's the right repo URL
293+
REPOMATCH=$(echo "$REPOCFG" | grep "\b$REPOCONFIG/$DEFAULT_ARCH\b")
294+
# If so, nothing to do
295+
if [ "$REPOMATCH" ]; then
296+
return 0
297+
fi
298+
299+
# Looks like it's the wrong URL, so recreate it.
300+
urpmi.removemedia "google-chrome" && \
301+
urpmi.addmedia --update "google-chrome" "$REPOCONFIG/$DEFAULT_ARCH"
302+
}
303+
304+
# We only remove the repository configuration during a purge. Since RPM has
305+
# no equivalent to dpkg --purge, the code below is actually never used. We
306+
# keep it only for reference purposes, should we ever need it.
307+
#
308+
#remove_yum() {
309+
# rm -f "$YUM_REPO_FILE"
310+
#}
311+
#
312+
#remove_urpmi() {
313+
# # Ideally, we would run: urpmi.removemedia "google-chrome"
314+
# # but that does not work when urpmi is running.
315+
# # Sentinel comment text does not work either because urpmi.update removes
316+
# # all comments. So we just delete the entry that matches what we originally
317+
# # inserted. If such an entry was added manually, that's tough luck.
318+
# if [ -f "$URPMI_REPO_FILE" ]; then
319+
# sed -i '\_^google-chrome $REPOCONFIG/$DEFAULT_ARCH {$_,/^}$/d' "$URPMI_REPO_FILE"
320+
# fi
321+
#}
322+
#
323+
#remove_yast() {
324+
# # Ideally, we would run: zypper removerepo "google-chrome"
325+
# # but that does not work when zypper is running.
326+
# rm -f /etc/zypp/repos.d/google-chrome.repo
327+
#}
328+
329+
DEFAULT_ARCH="x86_64"
330+
331+
get_lib_dir() {
332+
if [ "$DEFAULT_ARCH" = "i386" ]; then
333+
LIBDIR=lib
334+
elif [ "$DEFAULT_ARCH" = "x86_64" ]; then
335+
LIBDIR=lib64
336+
else
337+
echo Unknown CPU Architecture: "$DEFAULT_ARCH"
338+
exit 1
339+
fi
340+
}
341+
342+
## MAIN ##
343+
DEFAULTS_FILE="/etc/default/google-chrome"
344+
if [ -r "$DEFAULTS_FILE" ]; then
345+
. "$DEFAULTS_FILE"
346+
fi
347+
348+
if [ "$repo_add_once" = "true" ]; then
349+
determine_rpm_package_manager
350+
351+
# The initial install happens in the post-install scripts, but there have been
352+
# reports of configuration problems, so just verify that everything looks
353+
# good, and if not, try to install again.
354+
verify_install $PACKAGEMANAGER
355+
if [ $? -ne 0 ]; then
356+
install_${PACKAGEMANAGER}
357+
fi
358+
359+
# Now do any extra configuration that couldn't be done by post-install.
360+
case $PACKAGEMANAGER in
361+
"urpmi")
362+
# We need to configure urpmi after the install has finished.
363+
# See configure_urpmi() for details.
364+
configure_urpmi
365+
;;
366+
"yast")
367+
# It looks as though yast/zypper has a lock on the RPM DB during
368+
# postinstall, so we cannot add the signing key with install_rpm_key().
369+
# Instead, we attempt to do this here. If the user attempt to update before
370+
# the cron job imports the key, Yast will grab the key from our server and
371+
# prompt the user to accept the key.
372+
install_rpm_key
373+
;;
374+
esac
375+
376+
if [ $? -eq 0 ]; then
377+
# Before we quit auto-configuration, check that everything looks sane, since
378+
# part of this happened during package install and we don't have the return
379+
# value of that process.
380+
verify_install $PACKAGEMANAGER
381+
if [ $? -eq 0 ]; then
382+
sed -i -e 's/[[:space:]]*repo_add_once=.*/repo_add_once="false"/' \
383+
"$DEFAULTS_FILE"
384+
fi
385+
fi
386+
else
387+
update_bad_repo
388+
fi

0 commit comments

Comments
 (0)