@@include@@variables.include # Install the repository signing key (see also: # http://www.google.com/linuxrepositories/aboutkey.html) install_rpm_key() { # Check to see if key already exists. rpm -q gpg-pubkey-7fac5991-4615767f > /dev/null 2>&1 if [ "$?" -eq "0" ]; then # Key already exists return 0 fi # This is to work around a bug in RPM 4.7.0. (see http://crbug.com/22312) rpm -q gpg-pubkey-7fac5991-45f06f46 > /dev/null 2>&1 if [ "$?" -eq "0" ]; then # Key already exists return 0 fi # RPM on Mandriva 2009 is dumb and does not understand "rpm --import -" TMPKEY=$(mktemp /tmp/google.sig.XXXXXX) if [ -n "$TMPKEY" ]; then cat > "$TMPKEY" < /dev/null | sed 's/:\t/:/' | cut -d ':' -f 2-) case $RELEASE in "Fedora") PACKAGEMANAGER=yum ;; "Mageia"|"MandrivaLinux") PACKAGEMANAGER=urpmi ;; "SUSE LINUX") PACKAGEMANAGER=yast ;; esac fi if [ "$PACKAGEMANAGER" ]; then return fi # Fallback methods that are probably unnecessary on modern systems. if [ -f "/etc/lsb-release" ]; then # file missing on Fedora, does not contain DISTRIB_ID on OpenSUSE. eval $(sed -e '/DISTRIB_ID/!d' /etc/lsb-release) case $DISTRIB_ID in MandrivaLinux) PACKAGEMANAGER=urpmi ;; esac fi if [ "$PACKAGEMANAGER" ]; then return fi if [ -f "/etc/fedora-release" ] || [ -f "/etc/redhat-release" ]; then PACKAGEMANAGER=yum elif [ -f "/etc/SuSE-release" ]; then PACKAGEMANAGER=yast elif [ -f "/etc/mandriva-release" ]; then PACKAGEMANAGER=urpmi fi } DEFAULT_ARCH="@@ARCHITECTURE@@" YUM_REPO_FILE="/etc/yum.repos.d/@@PACKAGE@@.repo" ZYPPER_REPO_FILE="/etc/zypp/repos.d/@@PACKAGE@@.repo" URPMI_REPO_FILE="/etc/urpmi/urpmi.cfg" install_yum() { install_rpm_key if [ ! "$REPOCONFIG" ]; then return 0 fi if [ -d "/etc/yum.repos.d" ]; then cat > "$YUM_REPO_FILE" << REPOCONTENT [@@PACKAGE@@] name=@@PACKAGE@@ baseurl=$REPOCONFIG/$DEFAULT_ARCH enabled=1 gpgcheck=1 REPOCONTENT fi } # This is called by the cron job, rather than in the RPM postinstall. # We cannot do this during the install when urpmi is running due to # database locking. We also need to enable the repository, and we can # only do that while we are online. # see: https://qa.mandriva.com/show_bug.cgi?id=31893 configure_urpmi() { if [ ! "$REPOCONFIG" ]; then return 0 fi urpmq --list-media | grep -q -s "^@@PACKAGE@@$" if [ "$?" -eq "0" ]; then # Repository already configured return 0 fi urpmi.addmedia --update \ "@@PACKAGE@@" "$REPOCONFIG/$DEFAULT_ARCH" } install_urpmi() { # urpmi not smart enough to pull media_info/pubkey from the repository? install_rpm_key # Defer urpmi.addmedia to configure_urpmi() in the cron job. # See comment there. # # urpmi.addmedia --update \ # "@@PACKAGE@@" "$REPOCONFIG/$DEFAULT_ARCH" } install_yast() { if [ ! "$REPOCONFIG" ]; then return 0 fi # We defer adding the key to later. See comment in the cron job. # Ideally, we would run: zypper addrepo -t YUM -f \ # "$REPOCONFIG/$DEFAULT_ARCH" "@@PACKAGE@@" # but that does not work when zypper is running. if [ -d "/etc/zypp/repos.d" ]; then cat > "$ZYPPER_REPO_FILE" << REPOCONTENT [@@PACKAGE@@] name=@@PACKAGE@@ enabled=1 autorefresh=1 baseurl=$REPOCONFIG/$DEFAULT_ARCH type=rpm-md keeppackages=0 REPOCONTENT fi } # Check if the automatic repository configuration is done, so we know when to # stop trying. verify_install() { # It's probably enough to see that the repo configs have been created. If they # aren't configured properly, update_bad_repo should catch that when it's run. case $1 in "yum") [ -f "$YUM_REPO_FILE" ] ;; "yast") [ -f "$ZYPPER_REPO_FILE" ] ;; "urpmi") urpmq --list-url | grep -q -s "\b@@PACKAGE@@\b" ;; esac } # Update the Google repository if it's not set correctly. update_bad_repo() { if [ ! "$REPOCONFIG" ]; then return 0 fi determine_rpm_package_manager case $PACKAGEMANAGER in "yum") update_repo_file "$YUM_REPO_FILE" ;; "yast") update_repo_file "$ZYPPER_REPO_FILE" ;; "urpmi") update_urpmi_cfg ;; esac } update_repo_file() { REPO_FILE="$1" # Don't do anything if the file isn't there, since that probably means the # user disabled it. if [ ! -r "$REPO_FILE" ]; then return 0 fi # Check if the correct repository configuration is in there. REPOMATCH=$(grep "^baseurl=$REPOCONFIG/$DEFAULT_ARCH" "$REPO_FILE" \ 2>/dev/null) # If it's there, nothing to do if [ "$REPOMATCH" ]; then return 0 fi # Check if it's there but disabled by commenting out (as opposed to using the # 'enabled' setting). MATCH_DISABLED=$(grep "^[[:space:]]*#.*baseurl=$REPOCONFIG/$DEFAULT_ARCH" \ "$REPO_FILE" 2>/dev/null) if [ "$MATCH_DISABLED" ]; then # It's OK for it to be disabled, as long as nothing bogus is enabled in its # place. ACTIVECONFIGS=$(grep "^baseurl=.*" "$REPO_FILE" 2>/dev/null) if [ ! "$ACTIVECONFIGS" ]; then return 0 fi fi # If we get here, the correct repository wasn't found, or something else is # active, so fix it. This assumes there is a 'baseurl' setting, but if not, # then that's just another way of disabling, so we won't try to add it. sed -i -e "s,^baseurl=.*,baseurl=$REPOCONFIG/$DEFAULT_ARCH," "$REPO_FILE" } update_urpmi_cfg() { REPOCFG=$(urpmq --list-url | grep "\b@@PACKAGE@@\b") if [ ! "$REPOCFG" ]; then # Don't do anything if the repo isn't there, since that probably means the # user deleted it. return 0 fi # See if it's the right repo URL REPOMATCH=$(echo "$REPOCFG" | grep "\b$REPOCONFIG/$DEFAULT_ARCH\b") # If so, nothing to do if [ "$REPOMATCH" ]; then return 0 fi # Looks like it's the wrong URL, so recreate it. urpmi.removemedia "@@PACKAGE@@" && \ urpmi.addmedia --update "@@PACKAGE@@" "$REPOCONFIG/$DEFAULT_ARCH" } # We only remove the repository configuration during a purge. Since RPM has # no equivalent to dpkg --purge, the code below is actually never used. We # keep it only for reference purposes, should we ever need it. # #remove_yum() { # rm -f "$YUM_REPO_FILE" #} # #remove_urpmi() { # # Ideally, we would run: urpmi.removemedia "@@PACKAGE@@" # # but that does not work when urpmi is running. # # Sentinel comment text does not work either because urpmi.update removes # # all comments. So we just delete the entry that matches what we originally # # inserted. If such an entry was added manually, that's tough luck. # if [ -f "$URPMI_REPO_FILE" ]; then # sed -i '\_^@@PACKAGE@@ $REPOCONFIG/$DEFAULT_ARCH {$_,/^}$/d' "$URPMI_REPO_FILE" # fi #} # #remove_yast() { # # Ideally, we would run: zypper removerepo "@@PACKAGE@@" # # but that does not work when zypper is running. # rm -f /etc/zypp/repos.d/@@PACKAGE@@.repo #} DEFAULT_ARCH="@@ARCHITECTURE@@" get_lib_dir() { if [ "$DEFAULT_ARCH" = "i386" ]; then LIBDIR=lib elif [ "$DEFAULT_ARCH" = "x86_64" ]; then LIBDIR=lib64 else echo Unknown CPU Architecture: "$DEFAULT_ARCH" exit 1 fi }