ring-all.postinst 7.35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/bin/sh
set -e

###############################################################################
# RING PACKAGE POSTINST                                                       #
#                                                                             #
# Install Ring's package repository to the trusted sources and add Ring's     #
# release key to trusted keyring.                                             #
#                                                                             #
# NOTE: We follow https://wiki.debian.org/DebianRepository/UseThirdParty      #
###############################################################################


###############################################################################
# [1] Configuration                                                           #
###############################################################################

18
# All package repo urls are expected to start with this string, regardless
19 20 21 22
# of the distribution or version. The end tag is automatically appended,
# depending on the system the postinst script is run on. Examples:
#
# Ubuntu 18.04:
23
# $RING_REPO = $RING_REPO_BASE/ubuntu_18.04/
24 25
#
# Debian 9:
26
# $RING_REPO = $RING_REPO_BASE/debian_9
27 28
#
# To update the appended end tags, modify the switch in [2].
29
RING_REPO_BASE="https://dl.ring.cx/ring-nightly"
30 31 32 33 34

# Ring release key.
RING_KEY_FINGERPRINT="A295D773307D25A33AE72F2F64CD5FA175348F84"
RING_KEY="\
-----BEGIN PGP PUBLIC KEY BLOCK-----
35
Version: GnuPG v2
36 37 38 39 40 41 42 43

mQENBFVSdlcBCAC9zC1rp12O2K08PGozI14Y+t4qC931eHicvkuEMF1B9gAhjdRF
aIJS+UXwgQzoamDIHenxz1Q3fXUjKCMXytjGymB/0LUKccSbtH0Rcsl8kZ2z57KN
E+GLS7SvlP93ZOxco7eAEBWF/fvMrCsm10sNI6bW7UK0bgql9iIetd6Wrp9xXFVs
gmoV8Av714OlswsthSNtN+xQls3ozQ/dVGsOkZEyDbBzi88/rQEtuIDztTSWyD0V
x7WaY5+mVRwsJKzyPlgvsXpbP7A41IFykeOzPKh+vYz3k7dcLIRdOwse79oT2RXt
2VYEyTyTZIQlCJjGNTJYsU7GVffU4LnI7p/bABEBAAG0QFJpbmcgLSBTYXZvaXIt
RmFpcmUgTGludXgsIEluYyA8cmluZ0BsaXN0cy5zYXZvaXJmYWlyZWxpbnV4Lm5l
44 45 46 47 48 49 50 51 52 53 54 55 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kuMzZdTS4qyFb8EE/Ypi/WgewO9ib53kt7FBrxmm0l+d9GR4jH
CKGqaYjm8xzTsNa3m2C0Cf/C13bOaQVicgntfQ32IjjZdaDMlRLQluYNQ0ETA1FE
9+EVvrQYZ+kAEQEAAYkBHwQYAQgACQUCVVJ2VwIbDAAKCRBkzV+hdTSPhMIaB/9D
CrIZBDy7YOK3gdnNm57jemJRz6Cum7RTUiqCQ8ivSmEgv1KmMIqMpjmnKKP43iHO
mR4i7XDml6RBGynPys6cQcAlBWSuhOv9PGpRCaGyjJ4vmQUsYhyD/+tCDZVdBuGg
CxteSMbawxtMHESqX7dDlctc+njDjBcbcGj73sj36qoFIjorjymZlT5IdK39oXVM
Hi1TssiWPOU0hQgn4BIreYnEZUA6xuFX10C7k2DVRFZrXF7lpNgPQ8eNZTnQBIuw
HUFCGSHO3/kzxSlkE1PBUX3IZ8PSFijyopBnWUhlSXuyRjte8OR7Fl/Rlf0IaOD1
4sRdAfS333T4Uifq4uOu
=s2aQ
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
-----END PGP PUBLIC KEY BLOCK-----"

# System paths and generated variables
# In general: you will not need to modify these variables.
# WARNING: When modifying the paths, keep in mind that the corresponding
# postrm paths should be modified as well
APT_FILE="/etc/apt/sources.list.d/ring-main.sources"
APT_PREFS_FILE="/etc/apt/preferences.d/ring-main.pref"
UPDATE_MANAGER_PATH="/etc/update-manager/release-upgrades.d/"
RING_UPDATE_MANAGER_ID="ring-main"

RING_UPDATE_MANAGER_CFG="${RING_UPDATE_MANAGER_ID}.cfg"
UPDATE_MANAGER_CFG_PATH="${UPDATE_MANAGER_PATH}/${RING_UPDATE_MANAGER_CFG}"


###############################################################################
# [2] Set package repo url depending on distribution and version              #
###############################################################################

CAN_ADD_DEB_SOURCE=true

# Detect currently running system using /etc/os-release
# Debian-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
    . /etc/os-release
96

97
    # Set-up Ring repository end tag
98
    if [ "$ID" = "debian" ] && [ "$VER" = "9" ]; then
99
        ENDTAG="${ID}_${VERSION_ID}"
100
    elif [ "$ID" = "ubuntu" ] && [ "$VER" = "16.04" ]; then
101
        ENDTAG="${ID}_${VERSION_ID}"
102
    elif [ "$ID" = "ubuntu" ] && [ "$VER" = "17.04" ]; then
103
        ENDTAG="${ID}_${VERSION_ID}"
104
    elif [ "$ID" = "ubuntu" ] && [ "$VER" = "17.10" ]; then
105
        ENDTAG="${ID}_${VERSION_ID}"
106
    elif [ "$ID" = "ubuntu" ] && [ "$VER" = "18.04" ]; then
107
        ENDTAG="${ID}_${VERSION_ID}"
108
    elif [ "$ID" = "linuxmint" ] && [ "$UBUNTU_CODENAME" = "xenial" ]; then
109
        ENDTAG="ubuntu_16.04"
110
    elif [ "$ID" = "linuxmint" ] && [ "$UBUNTU_CODENAME" = "bionic" ]; then
111 112 113 114 115
        ENDTAG="ubuntu_18.04"
    else
        # Distribution is not supported. Don't provide automatic updates.
        CAN_ADD_DEB_SOURCE=false
    fi
116 117 118 119 120 121 122 123 124 125 126
else
    CAN_ADD_DEB_SOURCE=false
fi


###############################################################################
# [3] Maintainer script main switch                                           #
###############################################################################

case "$1" in
    configure)
127 128 129 130 131
        if [ "`command -v apt-key`" = "" ]; then
            # we can only add key if apt-key is present
            CAN_ADD_DEB_SOURCE=false
        fi

132
        if [ "$CAN_ADD_DEB_SOURCE" = "true" ]; then
133
            RING_REPO="${RING_REPO_BASE}/${ENDTAG}"
134 135

            # We first add the key to the trusted keyring.
136
            apt-key add - > /dev/null 2>&1 << EOF
137 138 139 140 141 142 143 144 145 146
$RING_KEY
EOF

            # Add an entry for the package repository to the trusted package
            # sources (DEB822 format)
            cat > $APT_FILE <<EOF
# This file makes sure that Ring is kept up-to-date
# as part of regular system upgrades

Types: deb
147
URIs: $RING_REPO
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
Suites: ring
Architectures: i386 amd64
Components: main
Signed-By: $RING_KEY_FINGERPRINT
EOF

            # It is recommended to also restrict the range of the newly added
            # source.
            cat > $APT_PREFS_FILE <<EOF
# forbid upgrading already installed packages from official repositories but
# allow upgrades to be performed for the ring repository
Package: *
Pin: origin dl.ring.cx
Pin-Priority: 100
EOF

            # Additionally, if update manager is installed we inform it about
            # the repository so it doesn't get scrapped after system updates
            if [ -d /etc/update-manager -a ! -f $UPDATE_MANAGER_CFG_PATH ]
            then
                mkdir -p $UPDATE_MANAGER_PATH
                cat > $UPDATE_MANAGER_CFG_PATH <<EOF
# Added by Ring to prevent disabling of Ring repository sources on
# distribution release upgrade.
[ThirdPartyMirrors]
173
ring/${RING_UPDATE_MANAGER_ID}=${RING_REPO}
174 175 176 177 178 179 180 181
EOF
            fi
        fi
        ;;
esac

# exit with a zero status as everything went well, important for maintscripts
exit 0