rpm.include revision cedac228d2dd51db4b79ea1e72c7f249408ee061
1@@include@@variables.include 2 3# Install the repository signing key (see also: 4# http://www.google.com/linuxrepositories/aboutkey.html) 5install_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 18 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----- 24Version: GnuPG v1.4.2.2 (GNU/Linux) 25 26mQGiBEXwb0YRBADQva2NLpYXxgjNkbuP0LnPoEXruGmvi3XMIxjEUFuGNCP4Rj/a 27kv2E5VixBP1vcQFDRJ+p1puh8NU0XERlhpyZrVMzzS/RdWdyXf7E5S8oqNXsoD1z 28fvmI+i9b2EhHAA19Kgw7ifV8vMa4tkwslEmcTiwiw8lyUl28Wh4Et8SxzwCggDcA 29feGqtn3PP5YAdD0km4S4XeMEAJjlrqPoPv2Gf//tfznY2UyS9PUqFCPLHgFLe80u 30QhI2U5jt6jUKN4fHauvR6z3seSAsh1YyzyZCKxJFEKXCCqnrFSoh4WSJsbFNc4PN 31b0V0SqiTCkWADZyLT5wll8sWuQ5ylTf3z1ENoHf+G3um3/wk/+xmEHvj9HCTBEXP 3278X0A/0Tqlhc2RBnEf+AqxWvM8sk8LzJI/XGjwBvKfXe+l3rnSR2kEAvGzj5Sg0X 334XmfTg4Jl8BNjWyvm2Wmjfet41LPmYJKsux3g0b8yzQxeOA4pQKKAU3Z4+rgzGmf 34HdwCG5MNT2A5XxD/eDd+L4fRx0HbFk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FLQ2X3xJ40XPuAyY 51/FJG 52=Quqp 53-----END PGP PUBLIC KEY BLOCK----- 54KEYDATA 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 63} 64 65determine_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 82 83 if [ "$PACKAGEMANAGER" ]; then 84 return 85 fi 86 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 97 98 if [ "$PACKAGEMANAGER" ]; then 99 return 100 fi 101 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 109} 110 111DEFAULT_ARCH="@@ARCHITECTURE@@" 112YUM_REPO_FILE="/etc/yum.repos.d/@@PACKAGE@@.repo" 113ZYPPER_REPO_FILE="/etc/zypp/repos.d/@@PACKAGE@@.repo" 114URPMI_REPO_FILE="/etc/urpmi/urpmi.cfg" 115 116install_yum() { 117 install_rpm_key 118 119 if [ ! "$REPOCONFIG" ]; then 120 return 0 121 fi 122 123 if [ -d "/etc/yum.repos.d" ]; then 124cat > "$YUM_REPO_FILE" << REPOCONTENT 125[@@PACKAGE@@] 126name=@@PACKAGE@@ 127baseurl=$REPOCONFIG/$DEFAULT_ARCH 128enabled=1 129gpgcheck=1 130REPOCONTENT 131 fi 132} 133 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 139configure_urpmi() { 140 if [ ! "$REPOCONFIG" ]; then 141 return 0 142 fi 143 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" 151} 152 153install_urpmi() { 154 # urpmi not smart enough to pull media_info/pubkey from the repository? 155 install_rpm_key 156 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" 162} 163 164install_yast() { 165 if [ ! "$REPOCONFIG" ]; then 166 return 0 167 fi 168 169 # We defer adding the key to later. See comment in the cron job. 170 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 175cat > "$ZYPPER_REPO_FILE" << REPOCONTENT 176[@@PACKAGE@@] 177name=@@PACKAGE@@ 178enabled=1 179autorefresh=1 180baseurl=$REPOCONFIG/$DEFAULT_ARCH 181type=rpm-md 182keeppackages=0 183REPOCONTENT 184 fi 185} 186 187# Check if the automatic repository configuration is done, so we know when to 188# stop trying. 189verify_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 203} 204 205# Update the Google repository if it's not set correctly. 206update_bad_repo() { 207 if [ ! "$REPOCONFIG" ]; then 208 return 0 209 fi 210 211 determine_rpm_package_manager 212 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 224} 225 226update_repo_file() { 227 REPO_FILE="$1" 228 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 234 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 242 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 255 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" 260} 261 262update_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 269 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 276 277 # Looks like it's the wrong URL, so recreate it. 278 urpmi.removemedia "@@PACKAGE@@" && \ 279 urpmi.addmedia --update "@@PACKAGE@@" "$REPOCONFIG/$DEFAULT_ARCH" 280} 281 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. 285# 286#remove_yum() { 287# rm -f "$YUM_REPO_FILE" 288#} 289# 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 299#} 300# 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 305#} 306 307DEFAULT_ARCH="@@ARCHITECTURE@@" 308 309get_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 318} 319