1cdf0e10cSrcweir#!/bin/sh
2*9f22d7c2SAndrew Rist# *************************************************************
3*9f22d7c2SAndrew Rist#
4*9f22d7c2SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
5*9f22d7c2SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
6*9f22d7c2SAndrew Rist#  distributed with this work for additional information
7*9f22d7c2SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
8*9f22d7c2SAndrew Rist#  to you under the Apache License, Version 2.0 (the
9*9f22d7c2SAndrew Rist#  "License"); you may not use this file except in compliance
10*9f22d7c2SAndrew Rist#  with the License.  You may obtain a copy of the License at
11*9f22d7c2SAndrew Rist#
12*9f22d7c2SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
13*9f22d7c2SAndrew Rist#
14*9f22d7c2SAndrew Rist#  Unless required by applicable law or agreed to in writing,
15*9f22d7c2SAndrew Rist#  software distributed under the License is distributed on an
16*9f22d7c2SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17*9f22d7c2SAndrew Rist#  KIND, either express or implied.  See the License for the
18*9f22d7c2SAndrew Rist#  specific language governing permissions and limitations
19*9f22d7c2SAndrew Rist#  under the License.
20*9f22d7c2SAndrew Rist#
21*9f22d7c2SAndrew Rist# *************************************************************
22cdf0e10cSrcweir
23cdf0e10cSrcweirMYUID=`id | sed "s/(.*//g" | sed "s/.*=//"`
24cdf0e10cSrcweir
25cdf0e10cSrcweirif [ $MYUID -ne 0 ]
26cdf0e10cSrcweirthen
27cdf0e10cSrcweir	echo You need to have super-user permissions to run this patch script
28cdf0e10cSrcweir	exit 1
29cdf0e10cSrcweirfi
30cdf0e10cSrcweir
31cdf0e10cSrcweirecho
32cdf0e10cSrcweirecho "Searching for the PRODUCTNAMEPLACEHOLDER installation ..."
33cdf0e10cSrcweir
34cdf0e10cSrcweirRPMNAME=`rpm -qa | grep SEARCHPACKAGENAMEPLACEHOLDER`
35cdf0e10cSrcweir
36cdf0e10cSrcweirif [ "x$RPMNAME" != "x" ]
37cdf0e10cSrcweirthen
38cdf0e10cSrcweir  PRODUCTINSTALLLOCATION="`rpm --query --queryformat "%{INSTALLPREFIX}" $RPMNAME`"
39cdf0e10cSrcweir  FULLPRODUCTINSTALLLOCATION="${PRODUCTINSTALLLOCATION}/PRODUCTDIRECTORYNAME"
40cdf0e10cSrcweirelse
41cdf0e10cSrcweir  echo "PRODUCTNAMEPLACEHOLDER is not installed"
42cdf0e10cSrcweir  exit 1
43cdf0e10cSrcweirfi
44cdf0e10cSrcweir
45cdf0e10cSrcweir# Last chance to exit ..
46cdf0e10cSrcweirecho
47cdf0e10cSrcweirread -p "Patching the installation in ${FULLPRODUCTINSTALLLOCATION}. Continue (y/n) ? " -n 1 reply leftover
48cdf0e10cSrcweirecho
49cdf0e10cSrcweir[ "$reply" == "y" ] || exit 1
50cdf0e10cSrcweir
51cdf0e10cSrcweirecho
52cdf0e10cSrcweirecho "About to update the following packages ..."
53cdf0e10cSrcweir
54cdf0e10cSrcweirBASEDIR=`dirname $0`
55cdf0e10cSrcweir
56cdf0e10cSrcweirRPMLIST=""
57cdf0e10cSrcweirfor i in `ls $BASEDIR/RPMS/*.rpm`
58cdf0e10cSrcweirdo
59cdf0e10cSrcweir  rpm --query `rpm --query --queryformat "%{NAME}\n" --package $i` && RPMLIST="$RPMLIST $i"
60cdf0e10cSrcweirdone
61cdf0e10cSrcweir
62cdf0e10cSrcweir# Save UserInstallation value
63cdf0e10cSrcweirBOOTSTRAPRC="${FULLPRODUCTINSTALLLOCATION}/program/bootstraprc"
64cdf0e10cSrcweirUSERINST=`grep UserInstallation ${BOOTSTRAPRC}`
65cdf0e10cSrcweir
66cdf0e10cSrcweir# Check, if kde-integration rpm is available
67cdf0e10cSrcweirKDERPM=`ls $BASEDIR/RPMS/*.rpm | grep kde-integration`
68cdf0e10cSrcweir
69cdf0e10cSrcweirif [ "x$KDERPM" != "x" ]; then
70cdf0e10cSrcweir  # Check, that $RPMLIST does not contain kde integration rpm (then it is already installed)
71cdf0e10cSrcweir  KDERPMINSTALLED=`grep kde-integration ${RPMLIST}`
72cdf0e10cSrcweir
73cdf0e10cSrcweir  if [ "x$KDERPMINSTALLED" == "x" ]; then
74cdf0e10cSrcweir    # Install the kde integration rpm
75cdf0e10cSrcweir    RPMLIST="$RPMLIST $KDERPM"
76cdf0e10cSrcweir  fi
77cdf0e10cSrcweirfi
78cdf0e10cSrcweir
79cdf0e10cSrcweirecho
80cdf0e10cSrcweirrpm --upgrade -v --hash --prefix $PRODUCTINSTALLLOCATION --notriggers $RPMLIST
81cdf0e10cSrcweirecho
82cdf0e10cSrcweir
83cdf0e10cSrcweir# Some RPM versions have problems with -U and --prefix
84cdf0e10cSrcweirif [ ! -f ${BOOTSTRAPRC} ]; then
85cdf0e10cSrcweir  echo Update failed due to a bug in RPM, uninstalling ..
86cdf0e10cSrcweir  rpm --erase -v --nodeps --notriggers `rpm --query --queryformat "%{NAME} " --package $RPMLIST`
87cdf0e10cSrcweir  echo
88cdf0e10cSrcweir  echo Now re-installing new packages ..
89cdf0e10cSrcweir  echo
90cdf0e10cSrcweir  rpm --install -v --hash --prefix $PRODUCTINSTALLLOCATION --notriggers $RPMLIST
91cdf0e10cSrcweir  echo
92cdf0e10cSrcweirfi
93cdf0e10cSrcweir
94cdf0e10cSrcweir# Restore the UserInstallation key if necessary
95cdf0e10cSrcweirDEFUSERINST=`grep UserInstallation ${BOOTSTRAPRC}`
96cdf0e10cSrcweirif [ "${USERINST}" != "${DEFUSERINST}" ]; then
97cdf0e10cSrcweir  mv -f ${BOOTSTRAPRC} ${BOOTSTRAPRC}.$$
98cdf0e10cSrcweir  sed "s|UserInstallation.*|${USERINST}|" ${BOOTSTRAPRC}.$$ > ${BOOTSTRAPRC}
99cdf0e10cSrcweir  rm -f ${BOOTSTRAPRC}.$$
100cdf0e10cSrcweirfi
101cdf0e10cSrcweir
102cdf0e10cSrcweirecho "Done."
103cdf0e10cSrcweir
104cdf0e10cSrcweirexit 0
105