2018-12-18 02:08:53 +01:00
|
|
|
#!/usr/bin/env bash
|
2016-08-05 22:27:03 +02:00
|
|
|
set -x
|
2018-12-06 23:05:36 +01:00
|
|
|
set -e
|
2016-08-05 22:27:03 +02:00
|
|
|
|
2018-12-11 02:35:41 +01:00
|
|
|
# Ensure the directory for LAST_DEPENDENCIES_HASH exists
|
|
|
|
mkdir -p /var/lib/zulip
|
|
|
|
|
2016-10-19 10:10:54 +02:00
|
|
|
SOURCES_FILE=/etc/apt/sources.list.d/zulip.list
|
2017-09-12 16:02:27 +02:00
|
|
|
STAMP_FILE=/etc/apt/sources.list.d/zulip.list.apt-update-in-progress
|
2018-12-06 23:05:36 +01:00
|
|
|
|
2018-12-11 02:35:41 +01:00
|
|
|
ZULIP_SCRIPTS="$(dirname "$(dirname "$0")")"
|
|
|
|
DEPENDENCIES_HASH=$(sha1sum "$ZULIP_SCRIPTS/setup/"*.asc "$0")
|
|
|
|
DEPENDENCIES_HASH_FILE="/var/lib/zulip/setup-repositories-state"
|
|
|
|
# Ensure that DEPENDENCIES_HASH_FILE exists before hashing it.
|
|
|
|
touch "$DEPENDENCIES_HASH_FILE"
|
|
|
|
LAST_DEPENDENCIES_HASH="$(cat "$DEPENDENCIES_HASH_FILE")"
|
|
|
|
|
|
|
|
# First, we only do anything in setup-apt-repo if any of its inputs
|
|
|
|
# (apt keys, code, etc.) changed.
|
|
|
|
if [ "$DEPENDENCIES_HASH" = "$LAST_DEPENDENCIES_HASH" ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2018-12-06 23:05:36 +01:00
|
|
|
# Ensure that the sources file exists
|
|
|
|
touch "$SOURCES_FILE"
|
|
|
|
|
|
|
|
# Hash it to check if the sources file is changed by the script later.
|
2018-08-03 02:14:47 +02:00
|
|
|
zulip_source_hash=$(sha1sum "$SOURCES_FILE")
|
2016-10-19 10:10:54 +02:00
|
|
|
|
2018-11-30 19:43:46 +01:00
|
|
|
apt-get install -y lsb-release apt-transport-https gnupg
|
2016-10-12 03:14:58 +02:00
|
|
|
|
2018-08-03 02:14:47 +02:00
|
|
|
SCRIPTS_PATH="$(dirname "$(dirname "$0")")"
|
2016-08-05 22:27:03 +02:00
|
|
|
|
|
|
|
release=$(lsb_release -sc)
|
2018-05-05 20:41:57 +02:00
|
|
|
if [ "$release" = "trusty" ] || [ "$release" = "xenial" ] || [ "$release" = "bionic" ]; then
|
2018-05-05 18:53:14 +02:00
|
|
|
apt-key add "$SCRIPTS_PATH"/setup/pgroonga-ppa.asc
|
|
|
|
apt-key add "$SCRIPTS_PATH"/setup/zulip-ppa.asc
|
2018-12-06 23:05:36 +01:00
|
|
|
cat >$SOURCES_FILE <<EOF
|
2016-10-12 03:14:58 +02:00
|
|
|
deb http://ppa.launchpad.net/groonga/ppa/ubuntu $release main
|
2016-08-05 22:27:03 +02:00
|
|
|
deb http://ppa.launchpad.net/tabbott/zulip/ubuntu $release main
|
2016-10-12 03:14:58 +02:00
|
|
|
deb-src http://ppa.launchpad.net/groonga/ppa/ubuntu $release main
|
2016-08-05 22:27:03 +02:00
|
|
|
deb-src http://ppa.launchpad.net/tabbott/zulip/ubuntu $release main
|
|
|
|
EOF
|
2019-03-09 18:54:40 +01:00
|
|
|
elif [ "$release" = "cosmic" ]; then
|
|
|
|
# This case will eventually merge with the above, if/when we add
|
|
|
|
# tsearch_extras packages to the Zulip PPA.
|
|
|
|
apt-key add "$SCRIPTS_PATH"/setup/pgroonga-ppa.asc
|
|
|
|
cat >$SOURCES_FILE <<EOF
|
|
|
|
deb http://ppa.launchpad.net/groonga/ppa/ubuntu $release main
|
|
|
|
deb-src http://ppa.launchpad.net/groonga/ppa/ubuntu $release main
|
|
|
|
EOF
|
2017-07-15 01:23:39 +02:00
|
|
|
elif [ "$release" = "stretch" ]; then
|
2018-05-05 18:53:14 +02:00
|
|
|
apt-get install -y debian-archive-keyring
|
2018-05-05 18:48:16 +02:00
|
|
|
apt-key add "$SCRIPTS_PATH"/setup/packagecloud.asc
|
2017-07-15 01:23:39 +02:00
|
|
|
apt-key add "$SCRIPTS_PATH"/setup/pgroonga-debian.asc
|
2018-12-06 23:05:36 +01:00
|
|
|
cat >$SOURCES_FILE <<EOF
|
2018-05-05 18:48:16 +02:00
|
|
|
deb https://packagecloud.io/zulip/server/debian/ stretch main
|
2017-07-15 01:23:39 +02:00
|
|
|
deb https://packages.groonga.org/debian/ stretch main
|
|
|
|
deb-src https://packages.groonga.org/debian/ stretch main
|
|
|
|
EOF
|
2016-08-05 22:27:03 +02:00
|
|
|
else
|
|
|
|
echo "Unsupported release $release."
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-10-16 09:56:58 +02:00
|
|
|
|
2018-08-03 02:14:47 +02:00
|
|
|
if [ "$zulip_source_hash" = "$(sha1sum "$SOURCES_FILE")" ] && ! [ -e "$STAMP_FILE" ]; then
|
2016-10-19 10:10:54 +02:00
|
|
|
echo "zulip.list file did not change; skipping apt-get update"
|
|
|
|
else
|
2017-09-12 16:02:27 +02:00
|
|
|
# We create this stamp file to ensure `apt-get update` will be run
|
|
|
|
# the next time this script is invoked, and each time after, until
|
|
|
|
# `apt-get update` finishes successfully.
|
|
|
|
touch "$STAMP_FILE"
|
|
|
|
apt-get update && rm -f "$STAMP_FILE"
|
2016-10-19 10:10:54 +02:00
|
|
|
fi
|
2018-12-11 02:35:41 +01:00
|
|
|
|
|
|
|
echo "$DEPENDENCIES_HASH" > "$DEPENDENCIES_HASH_FILE"
|