Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / installer / linux / common / rpm.include
blob7c8ef53c2e38e9df1518e4e5cd4fa903b1522a7b
1 @@include@@variables.include
3 # Install the repository signing key (see also:
4 # https://www.google.com/linuxrepositories/)
5 install_rpm_key() {
6   # Check to see if key already exists.
7   rpm -q gpg-pubkey-7fac5991-4615767f > /dev/null 2>&1
8   if [ "$?" -eq "0" ]; then
9     # Key already exists
10     return 0
11   fi
12   # This is to work around a bug in RPM 4.7.0. (see http://crbug.com/22312)
13   rpm -q gpg-pubkey-7fac5991-45f06f46 > /dev/null 2>&1
14   if [ "$?" -eq "0" ]; then
15     # Key already exists
16     return 0
17   fi
19   # RPM on Mandriva 2009 is dumb and does not understand "rpm --import -"
20   TMPKEY=$(mktemp /tmp/google.sig.XXXXXX)
21   if [ -n "$TMPKEY" ]; then
22     cat > "$TMPKEY" <<KEYDATA
23 -----BEGIN PGP PUBLIC KEY BLOCK-----
24 Version: GnuPG v1.4.2.2 (GNU/Linux)
26 mQGiBEXwb0YRBADQva2NLpYXxgjNkbuP0LnPoEXruGmvi3XMIxjEUFuGNCP4Rj/a
27 kv2E5VixBP1vcQFDRJ+p1puh8NU0XERlhpyZrVMzzS/RdWdyXf7E5S8oqNXsoD1z
28 fvmI+i9b2EhHAA19Kgw7ifV8vMa4tkwslEmcTiwiw8lyUl28Wh4Et8SxzwCggDcA
29 feGqtn3PP5YAdD0km4S4XeMEAJjlrqPoPv2Gf//tfznY2UyS9PUqFCPLHgFLe80u
30 QhI2U5jt6jUKN4fHauvR6z3seSAsh1YyzyZCKxJFEKXCCqnrFSoh4WSJsbFNc4PN
31 b0V0SqiTCkWADZyLT5wll8sWuQ5ylTf3z1ENoHf+G3um3/wk/+xmEHvj9HCTBEXP
32 78X0A/0Tqlhc2RBnEf+AqxWvM8sk8LzJI/XGjwBvKfXe+l3rnSR2kEAvGzj5Sg0X
33 4XmfTg4Jl8BNjWyvm2Wmjfet41LPm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TdMuwNFiEkEGBECAAkFAkXwb0sCGwwACgkQoECD
50 D3+sWZF/WACfeNAu1/1hwZtUo1bR+MWiCjpvHtwAnA1R3IHqFLQ2X3xJ40XPuAyY
51 /FJG
52 =Quqp
53 -----END PGP PUBLIC KEY BLOCK-----
54 KEYDATA
55     rpm --import "$TMPKEY"
56     rc=$?
57     rm -f "$TMPKEY"
58     if [ "$rc" -eq "0" ]; then
59       return 0
60     fi
61   fi
62   return 1
65 determine_rpm_package_manager() {
66   local RELEASE
67   LSB_RELEASE="$(which lsb_release 2> /dev/null)"
68   if [ -x "$LSB_RELEASE" ]; then
69     RELEASE=$(lsb_release -i 2> /dev/null | sed 's/:\t/:/' | cut -d ':' -f 2-)
70     case $RELEASE in
71     "Fedora")
72       PACKAGEMANAGER=yum
73       ;;
74     "Mageia"|"MandrivaLinux")
75       PACKAGEMANAGER=urpmi
76       ;;
77     "SUSE LINUX")
78       PACKAGEMANAGER=yast
79       ;;
80     esac
81   fi
83   if [ "$PACKAGEMANAGER" ]; then
84     return
85   fi
87   # Fallback methods that are probably unnecessary on modern systems.
88   if [ -f "/etc/lsb-release" ]; then
89     # file missing on Fedora, does not contain DISTRIB_ID on OpenSUSE.
90     eval $(sed -e '/DISTRIB_ID/!d' /etc/lsb-release)
91     case $DISTRIB_ID in
92     MandrivaLinux)
93       PACKAGEMANAGER=urpmi
94       ;;
95     esac
96   fi
98   if [ "$PACKAGEMANAGER" ]; then
99     return
100   fi
102   if [ -f "/etc/fedora-release" ] || [ -f "/etc/redhat-release" ]; then
103     PACKAGEMANAGER=yum
104   elif [ -f "/etc/SuSE-release" ]; then
105     PACKAGEMANAGER=yast
106   elif [ -f "/etc/mandriva-release" ]; then
107     PACKAGEMANAGER=urpmi
108   fi
111 DEFAULT_ARCH="@@ARCHITECTURE@@"
112 YUM_REPO_FILE="/etc/yum.repos.d/@@PACKAGE@@.repo"
113 ZYPPER_REPO_FILE="/etc/zypp/repos.d/@@PACKAGE@@.repo"
114 URPMI_REPO_FILE="/etc/urpmi/urpmi.cfg"
116 install_yum() {
117   install_rpm_key
119   if [ ! "$REPOCONFIG" ]; then
120     return 0
121   fi
123   if [ -d "/etc/yum.repos.d" ]; then
124 cat > "$YUM_REPO_FILE" << REPOCONTENT
125 [@@PACKAGE@@]
126 name=@@PACKAGE@@
127 baseurl=$REPOCONFIG/$DEFAULT_ARCH
128 enabled=1
129 gpgcheck=1
130 gpgkey=https://dl.google.com/linux/linux_signing_key.pub
131 REPOCONTENT
132   fi
135 # This is called by the cron job, rather than in the RPM postinstall.
136 # We cannot do this during the install when urpmi is running due to
137 # database locking. We also need to enable the repository, and we can
138 # only do that while we are online.
139 # see: https://qa.mandriva.com/show_bug.cgi?id=31893
140 configure_urpmi() {
141   if [ ! "$REPOCONFIG" ]; then
142     return 0
143   fi
145   urpmq --list-media | grep -q -s "^@@PACKAGE@@$"
146   if [ "$?" -eq "0" ]; then
147     # Repository already configured
148     return 0
149   fi
150   urpmi.addmedia --update \
151     "@@PACKAGE@@" "$REPOCONFIG/$DEFAULT_ARCH"
154 install_urpmi() {
155   # urpmi not smart enough to pull media_info/pubkey from the repository?
156   install_rpm_key
158   # Defer urpmi.addmedia to configure_urpmi() in the cron job.
159   # See comment there.
160   #
161   # urpmi.addmedia --update \
162   #   "@@PACKAGE@@" "$REPOCONFIG/$DEFAULT_ARCH"
165 install_yast() {
166   if [ ! "$REPOCONFIG" ]; then
167     return 0
168   fi
170   # We defer adding the key to later. See comment in the cron job.
172   # Ideally, we would run: zypper addrepo -t YUM -f \
173   # "$REPOCONFIG/$DEFAULT_ARCH" "@@PACKAGE@@"
174   # but that does not work when zypper is running.
175   if [ -d "/etc/zypp/repos.d" ]; then
176 cat > "$ZYPPER_REPO_FILE" << REPOCONTENT
177 [@@PACKAGE@@]
178 name=@@PACKAGE@@
179 enabled=1
180 autorefresh=1
181 baseurl=$REPOCONFIG/$DEFAULT_ARCH
182 type=rpm-md
183 keeppackages=0
184 REPOCONTENT
185   fi
188 # Check if the automatic repository configuration is done, so we know when to
189 # stop trying.
190 verify_install() {
191   # It's probably enough to see that the repo configs have been created. If they
192   # aren't configured properly, update_bad_repo should catch that when it's run.
193   case $1 in
194   "yum")
195     [ -f "$YUM_REPO_FILE" ]
196     ;;
197   "yast")
198     [ -f "$ZYPPER_REPO_FILE" ]
199     ;;
200   "urpmi")
201     urpmq --list-url | grep -q -s "\b@@PACKAGE@@\b"
202     ;;
203   esac
206 # Update the Google repository if it's not set correctly.
207 update_bad_repo() {
208   if [ ! "$REPOCONFIG" ]; then
209     return 0
210   fi
212   determine_rpm_package_manager
214   case $PACKAGEMANAGER in
215   "yum")
216     update_repo_file "$YUM_REPO_FILE"
217     ;;
218   "yast")
219     update_repo_file "$ZYPPER_REPO_FILE"
220     ;;
221   "urpmi")
222     update_urpmi_cfg
223     ;;
224   esac
227 update_repo_file() {
228   REPO_FILE="$1"
230   # Don't do anything if the file isn't there, since that probably means the
231   # user disabled it.
232   if [ ! -r "$REPO_FILE" ]; then
233     return 0
234   fi
236   # Check if the correct repository configuration is in there.
237   REPOMATCH=$(grep "^baseurl=$REPOCONFIG/$DEFAULT_ARCH" "$REPO_FILE" \
238     2>/dev/null)
239   # If it's there, nothing to do
240   if [ "$REPOMATCH" ]; then
241     return 0
242   fi
244   # Check if it's there but disabled by commenting out (as opposed to using the
245   # 'enabled' setting).
246   MATCH_DISABLED=$(grep "^[[:space:]]*#.*baseurl=$REPOCONFIG/$DEFAULT_ARCH" \
247     "$REPO_FILE" 2>/dev/null)
248   if [ "$MATCH_DISABLED" ]; then
249     # It's OK for it to be disabled, as long as nothing bogus is enabled in its
250     # place.
251     ACTIVECONFIGS=$(grep "^baseurl=.*" "$REPO_FILE" 2>/dev/null)
252     if [ ! "$ACTIVECONFIGS" ]; then
253       return 0
254     fi
255   fi
257   # If we get here, the correct repository wasn't found, or something else is
258   # active, so fix it. This assumes there is a 'baseurl' setting, but if not,
259   # then that's just another way of disabling, so we won't try to add it.
260   sed -i -e "s,^baseurl=.*,baseurl=$REPOCONFIG/$DEFAULT_ARCH," "$REPO_FILE"
263 update_urpmi_cfg() {
264   REPOCFG=$(urpmq --list-url | grep "\b@@PACKAGE@@\b")
265   if [ ! "$REPOCFG" ]; then
266     # Don't do anything if the repo isn't there, since that probably means the
267     # user deleted it.
268     return 0
269   fi
271   # See if it's the right repo URL
272   REPOMATCH=$(echo "$REPOCFG" | grep "\b$REPOCONFIG/$DEFAULT_ARCH\b")
273   # If so, nothing to do
274   if [ "$REPOMATCH" ]; then
275     return 0
276   fi
278   # Looks like it's the wrong URL, so recreate it.
279   urpmi.removemedia "@@PACKAGE@@" && \
280     urpmi.addmedia --update "@@PACKAGE@@" "$REPOCONFIG/$DEFAULT_ARCH"
283 # We only remove the repository configuration during a purge. Since RPM has
284 # no equivalent to dpkg --purge, the code below is actually never used. We
285 # keep it only for reference purposes, should we ever need it.
287 #remove_yum() {
288 #  rm -f "$YUM_REPO_FILE"
291 #remove_urpmi() {
292 #  # Ideally, we would run: urpmi.removemedia "@@PACKAGE@@"
293 #  # but that does not work when urpmi is running.
294 #  # Sentinel comment text does not work either because urpmi.update removes
295 #  # all comments. So we just delete the entry that matches what we originally
296 #  # inserted. If such an entry was added manually, that's tough luck.
297 #  if [ -f "$URPMI_REPO_FILE" ]; then
298 #    sed -i '\_^@@PACKAGE@@ $REPOCONFIG/$DEFAULT_ARCH {$_,/^}$/d' "$URPMI_REPO_FILE"
299 #  fi
302 #remove_yast() {
303 #  # Ideally, we would run: zypper removerepo "@@PACKAGE@@"
304 #  # but that does not work when zypper is running.
305 #  rm -f /etc/zypp/repos.d/@@PACKAGE@@.repo
308 DEFAULT_ARCH="@@ARCHITECTURE@@"
310 get_lib_dir() {
311   if [ "$DEFAULT_ARCH" = "i386" ]; then
312     LIBDIR=lib
313   elif [ "$DEFAULT_ARCH" = "x86_64" ]; then
314     LIBDIR=lib64
315   else
316     echo Unknown CPU Architecture: "$DEFAULT_ARCH"
317     exit 1
318   fi