Roll src/third_party/skia 99c7c07:4af6580
[chromium-blink-merge.git] / chrome / installer / linux / common / rpm.include
blob16414aa464119e65faa4bcff2ac129e4182b98e4
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 4XmfTg4Jl8BNjWyvm2Wmjfet41LPmYJKsux3g0b8yzQxeO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kFAkXwb0sCGwwACgkQoECD
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 REPOCONTENT
131   fi
134 # This is called by the cron job, rather than in the RPM postinstall.
135 # We cannot do this during the install when urpmi is running due to
136 # database locking. We also need to enable the repository, and we can
137 # only do that while we are online.
138 # see: https://qa.mandriva.com/show_bug.cgi?id=31893
139 configure_urpmi() {
140   if [ ! "$REPOCONFIG" ]; then
141     return 0
142   fi
144   urpmq --list-media | grep -q -s "^@@PACKAGE@@$"
145   if [ "$?" -eq "0" ]; then
146     # Repository already configured
147     return 0
148   fi
149   urpmi.addmedia --update \
150     "@@PACKAGE@@" "$REPOCONFIG/$DEFAULT_ARCH"
153 install_urpmi() {
154   # urpmi not smart enough to pull media_info/pubkey from the repository?
155   install_rpm_key
157   # Defer urpmi.addmedia to configure_urpmi() in the cron job.
158   # See comment there.
159   #
160   # urpmi.addmedia --update \
161   #   "@@PACKAGE@@" "$REPOCONFIG/$DEFAULT_ARCH"
164 install_yast() {
165   if [ ! "$REPOCONFIG" ]; then
166     return 0
167   fi
169   # We defer adding the key to later. See comment in the cron job.
171   # Ideally, we would run: zypper addrepo -t YUM -f \
172   # "$REPOCONFIG/$DEFAULT_ARCH" "@@PACKAGE@@"
173   # but that does not work when zypper is running.
174   if [ -d "/etc/zypp/repos.d" ]; then
175 cat > "$ZYPPER_REPO_FILE" << REPOCONTENT
176 [@@PACKAGE@@]
177 name=@@PACKAGE@@
178 enabled=1
179 autorefresh=1
180 baseurl=$REPOCONFIG/$DEFAULT_ARCH
181 type=rpm-md
182 keeppackages=0
183 REPOCONTENT
184   fi
187 # Check if the automatic repository configuration is done, so we know when to
188 # stop trying.
189 verify_install() {
190   # It's probably enough to see that the repo configs have been created. If they
191   # aren't configured properly, update_bad_repo should catch that when it's run.
192   case $1 in
193   "yum")
194     [ -f "$YUM_REPO_FILE" ]
195     ;;
196   "yast")
197     [ -f "$ZYPPER_REPO_FILE" ]
198     ;;
199   "urpmi")
200     urpmq --list-url | grep -q -s "\b@@PACKAGE@@\b"
201     ;;
202   esac
205 # Update the Google repository if it's not set correctly.
206 update_bad_repo() {
207   if [ ! "$REPOCONFIG" ]; then
208     return 0
209   fi
211   determine_rpm_package_manager
213   case $PACKAGEMANAGER in
214   "yum")
215     update_repo_file "$YUM_REPO_FILE"
216     ;;
217   "yast")
218     update_repo_file "$ZYPPER_REPO_FILE"
219     ;;
220   "urpmi")
221     update_urpmi_cfg
222     ;;
223   esac
226 update_repo_file() {
227   REPO_FILE="$1"
229   # Don't do anything if the file isn't there, since that probably means the
230   # user disabled it.
231   if [ ! -r "$REPO_FILE" ]; then
232     return 0
233   fi
235   # Check if the correct repository configuration is in there.
236   REPOMATCH=$(grep "^baseurl=$REPOCONFIG/$DEFAULT_ARCH" "$REPO_FILE" \
237     2>/dev/null)
238   # If it's there, nothing to do
239   if [ "$REPOMATCH" ]; then
240     return 0
241   fi
243   # Check if it's there but disabled by commenting out (as opposed to using the
244   # 'enabled' setting).
245   MATCH_DISABLED=$(grep "^[[:space:]]*#.*baseurl=$REPOCONFIG/$DEFAULT_ARCH" \
246     "$REPO_FILE" 2>/dev/null)
247   if [ "$MATCH_DISABLED" ]; then
248     # It's OK for it to be disabled, as long as nothing bogus is enabled in its
249     # place.
250     ACTIVECONFIGS=$(grep "^baseurl=.*" "$REPO_FILE" 2>/dev/null)
251     if [ ! "$ACTIVECONFIGS" ]; then
252       return 0
253     fi
254   fi
256   # If we get here, the correct repository wasn't found, or something else is
257   # active, so fix it. This assumes there is a 'baseurl' setting, but if not,
258   # then that's just another way of disabling, so we won't try to add it.
259   sed -i -e "s,^baseurl=.*,baseurl=$REPOCONFIG/$DEFAULT_ARCH," "$REPO_FILE"
262 update_urpmi_cfg() {
263   REPOCFG=$(urpmq --list-url | grep "\b@@PACKAGE@@\b")
264   if [ ! "$REPOCFG" ]; then
265     # Don't do anything if the repo isn't there, since that probably means the
266     # user deleted it.
267     return 0
268   fi
270   # See if it's the right repo URL
271   REPOMATCH=$(echo "$REPOCFG" | grep "\b$REPOCONFIG/$DEFAULT_ARCH\b")
272   # If so, nothing to do
273   if [ "$REPOMATCH" ]; then
274     return 0
275   fi
277   # Looks like it's the wrong URL, so recreate it.
278   urpmi.removemedia "@@PACKAGE@@" && \
279     urpmi.addmedia --update "@@PACKAGE@@" "$REPOCONFIG/$DEFAULT_ARCH"
282 # We only remove the repository configuration during a purge. Since RPM has
283 # no equivalent to dpkg --purge, the code below is actually never used. We
284 # keep it only for reference purposes, should we ever need it.
286 #remove_yum() {
287 #  rm -f "$YUM_REPO_FILE"
290 #remove_urpmi() {
291 #  # Ideally, we would run: urpmi.removemedia "@@PACKAGE@@"
292 #  # but that does not work when urpmi is running.
293 #  # Sentinel comment text does not work either because urpmi.update removes
294 #  # all comments. So we just delete the entry that matches what we originally
295 #  # inserted. If such an entry was added manually, that's tough luck.
296 #  if [ -f "$URPMI_REPO_FILE" ]; then
297 #    sed -i '\_^@@PACKAGE@@ $REPOCONFIG/$DEFAULT_ARCH {$_,/^}$/d' "$URPMI_REPO_FILE"
298 #  fi
301 #remove_yast() {
302 #  # Ideally, we would run: zypper removerepo "@@PACKAGE@@"
303 #  # but that does not work when zypper is running.
304 #  rm -f /etc/zypp/repos.d/@@PACKAGE@@.repo
307 DEFAULT_ARCH="@@ARCHITECTURE@@"
309 get_lib_dir() {
310   if [ "$DEFAULT_ARCH" = "i386" ]; then
311     LIBDIR=lib
312   elif [ "$DEFAULT_ARCH" = "x86_64" ]; then
313     LIBDIR=lib64
314   else
315     echo Unknown CPU Architecture: "$DEFAULT_ARCH"
316     exit 1
317   fi