diff --git a/packaging/rules/fedora/jami-all.postinst b/packaging/rules/fedora/jami-all.postinst index 4e59d7890162653f39b065369232cb93af53923c..af1d4c3af125a7024347b1f578d99495b034069c 100755 --- a/packaging/rules/fedora/jami-all.postinst +++ b/packaging/rules/fedora/jami-all.postinst @@ -14,11 +14,6 @@ # [1] Configuration # ############################################################################### -# All package repo urls are expected to start with this string, regardless -# of the distribution or version. The end tag is automatically appended, -# depending on the system the postinst script is run on. -# -# To update the appended end tags, modify the switch in [2]. JAMI_REPO_BASE="https://dl.jami.net/nightly" # Jami release key. @@ -68,66 +63,60 @@ HUFCGSHO3/kzxSlkE1PBUX3IZ8PSFijyopBnWUhlSXuyRjte8OR7Fl/Rlf0IaOD1 # postrm paths should be modified as well YUM_FILE="/etc/yum.repos.d/jami-main.repo" GPG_FILE="/etc/pki/rpm-gpg/RPM-GPG-KEY-JAMI" -JAMI_UPDATE_MANAGER_ID="jami" -JAMI_UPDATE_MANAGER_CFG="${JAMI_UPDATE_MANAGER_ID}.cfg" -############################################################################### -# [2] Set package repo url depending on distribution and version # -############################################################################### +is_distribution_supported() { -CAN_ADD_YUM_SOURCE=true + # Detect currently running system using /etc/os-release + # Redhat-based systems are supposed to provide /etc/os-release so + # if it's not the case then we simply don't want to provide + # automatic updates. + if ! [ -f /etc/os-release ]; then + return 1 + fi -# Detect currently running system using /etc/os-release -# Redhat-based systems are supposed to provide /etc/os-release so if it's not -# the case then we simply don't want to provide automatic updates -if [ -f /etc/os-release ]; then + # This defines variables such as NAME, ID, VERSION_ID, etc. . /etc/os-release -JAMI_REPO=' -[jami] -name='"${NAME}"' $releasever - $basearch - Jami -baseurl='"${JAMI_REPO_BASE}"/"${ID}"'_$releasever -gpgcheck=1 -gpgkey=https://dl.jami.net/jami.pub.key -enabled=1' - - # Set-up Jami repository end tag - if [ "${PLATFORM_ID}" = "platform:el8" ] || [ "${ID}_${VERSION_ID%.*}" = "rhel_8" ]; then - ENDTAG="rhel_8" - elif [ "${PLATFORM_ID}" = "platform:f32" ] || [ "${ID}_${VERSION_ID}" = "fedora_32" ]; then - ENDTAG="fedora_32" - elif [ "${PLATFORM_ID}" = "platform:f33" ] || [ "${ID}_${VERSION_ID}" = "fedora_33" ]; then - ENDTAG="fedora_33" - else - # Distribution is not supported. Don't provide automatic updates. - CAN_ADD_YUM_SOURCE=false - fi -else - CAN_ADD_YUM_SOURCE=false -fi + case ${ID}_${VERSION_ID%.*} in + rhel_8|fedora_32|fedora_33) + return 0;; + esac + return 1 +} ############################################################################### # [3] Maintainer script main switch # ############################################################################### - if [ "`command -v rpm`" = "" ]; then - # we can only add key if rpm is present - CAN_ADD_YUM_SOURCE=false - fi +if is_distribution_supported; then + CAN_ADD_YUM_SOURCE=true +else + CAN_ADD_YUM_SOURCE=false +fi + +if command -v rpm > /dev/null; then + # RPM is required to add the key. + CAN_ADD_YUM_SOURCE=false +fi - if [ "${CAN_ADD_YUM_SOURCE}" = "true" ]; then -# # We first add the key to the trusted keyring. - cat > $GPG_FILE <<EOF - -$JAMI_KEY -EOF - /usr/bin/rm -f /var/lib/rpm/.rpm.lock > /dev/null 2>&1 - /usr/bin/rpm --import $GPG_FILE > /dev/null 2>&1 +if [ "${CAN_ADD_YUM_SOURCE}" = "true" ]; then + # Add the key to the trusted keyring. + echo "$JAMI_KEY" > "$GPG_FILE" - # Add an entry for the package repository to the trusted package - cat > $YUM_FILE <<EOF -$JAMI_REPO + rm -f /var/lib/rpm/.rpm.lock > /dev/null 2>&1 + rpm --import "$GPG_FILE" > /dev/null 2>&1 + + # Add an entry for the package repository to the trusted package. + # XXX: The NAME and ID variables are set as a side-effect of + # sourcing the /etc/os-release file in the above + # is_distribution_supported call. + cat > "$YUM_FILE" <<EOF +[jami] +name=$NAME \$releasever - \$basearch - Jami +baseurl=${JAMI_REPO_BASE}/${ID}_\$releasever +gpgcheck=1 +gpgkey=https://dl.jami.net/jami.pub.key +enabled=1 EOF - fi -exit 0 +fi