2018-12-18 02:08:53 +01:00
|
|
|
#!/usr/bin/env bash
|
2021-05-22 01:23:43 +02:00
|
|
|
#
|
|
|
|
# This script handles adding custom apt repositories into
|
|
|
|
# /etc/apt/sources.list.d/ files. It bundles the GPG keys which are
|
|
|
|
# used to verify the repositories (via `apt-key`), to explicitly pin
|
|
|
|
# the trusted signing keys, as opposed to blindly trusting HTTPS.
|
|
|
|
#
|
|
|
|
# Each /etc/apt/soruces.list.d/foo.list file is created via `--list
|
|
|
|
# foo`, where `foo` defaults to `zulip`. The default `zulip.list` is
|
|
|
|
# installed in `scripts/lib/install` / `tools/lib/provision.py`, and
|
|
|
|
# other `.list` files may be installed by Puppet.
|
2016-08-05 22:27:03 +02:00
|
|
|
set -x
|
2018-12-06 23:05:36 +01:00
|
|
|
set -e
|
2020-11-30 01:27:45 +01:00
|
|
|
set -u
|
|
|
|
set -o pipefail
|
2016-08-05 22:27:03 +02:00
|
|
|
|
2020-10-14 01:58:58 +02:00
|
|
|
verify=false
|
2021-05-22 01:23:43 +02:00
|
|
|
args="$(getopt -o '' --long verify,list: -- "$@")"
|
2020-10-14 01:58:58 +02:00
|
|
|
eval "set -- $args"
|
2021-05-22 01:23:43 +02:00
|
|
|
LIST=zulip
|
2020-10-14 01:58:58 +02:00
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
--verify)
|
|
|
|
verify=true
|
|
|
|
shift
|
|
|
|
;;
|
2021-05-22 01:23:43 +02:00
|
|
|
--list)
|
|
|
|
LIST="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
2020-10-14 01:58:58 +02:00
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2018-12-11 02:35:41 +01:00
|
|
|
# Ensure the directory for LAST_DEPENDENCIES_HASH exists
|
|
|
|
mkdir -p /var/lib/zulip
|
|
|
|
|
2021-05-22 01:23:43 +02:00
|
|
|
SOURCES_FILE=/etc/apt/sources.list.d/$LIST.list
|
|
|
|
STAMP_FILE=/etc/apt/sources.list.d/$LIST.list.apt-update-in-progress
|
|
|
|
|
|
|
|
ZULIP_SCRIPTS="$(cd "$(dirname "$(dirname "$0")")" && pwd)"
|
|
|
|
LIST_PATH="$ZULIP_SCRIPTS/setup/apt-repos/$LIST"
|
|
|
|
if ! [ -d "$LIST_PATH" ]; then
|
|
|
|
echo "Not a valid value for --list: '$LIST'"
|
|
|
|
echo ""
|
|
|
|
echo "Valid values are:"
|
|
|
|
ls -1 "$ZULIP_SCRIPTS/setup/apt-repos/"
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-12-06 23:05:36 +01:00
|
|
|
|
2021-05-22 01:23:43 +02:00
|
|
|
DEPENDENCIES_HASH=$(sha1sum "$LIST_PATH/"*.asc "$0")
|
|
|
|
DEPENDENCIES_HASH_FILE="/var/lib/zulip/setup-repositories-state-$LIST"
|
2018-12-11 02:35:41 +01:00
|
|
|
# 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
|
2020-10-14 01:58:58 +02:00
|
|
|
elif [ "$verify" == true ]; then
|
|
|
|
exit 1
|
2018-12-11 02:35:41 +01:00
|
|
|
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
|
|
|
|
2021-06-25 01:28:27 +02:00
|
|
|
pre_setup_deps=(lsb-release apt-transport-https ca-certificates gnupg curl)
|
2019-05-27 23:58:48 +02:00
|
|
|
if ! apt-get -dy install "${pre_setup_deps[@]}"; then
|
2019-05-25 01:09:00 +02:00
|
|
|
apt-get update
|
|
|
|
fi
|
|
|
|
apt-get -y install "${pre_setup_deps[@]}"
|
2016-10-12 03:14:58 +02:00
|
|
|
|
2016-08-05 22:27:03 +02:00
|
|
|
release=$(lsb_release -sc)
|
2021-05-22 01:23:43 +02:00
|
|
|
if [ -f "$LIST_PATH/$release.list" ]; then
|
|
|
|
apt-key add "$LIST_PATH/"*.asc
|
|
|
|
cp "$LIST_PATH/$release.list" "$SOURCES_FILE"
|
|
|
|
else
|
|
|
|
cat <<EOF
|
|
|
|
Unsupported release $release for sources.list file $LIST. To add a
|
|
|
|
new release, make a $LIST_PATH/$release.list file based on existing
|
|
|
|
.list files in that directory.
|
2020-06-13 03:07:55 +02:00
|
|
|
|
2017-07-15 01:23:39 +02:00
|
|
|
EOF
|
2016-08-05 22:27:03 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2016-10-16 09:56:58 +02:00
|
|
|
|
2021-05-22 01:23:43 +02:00
|
|
|
if [ -e "$LIST_PATH/custom.sh" ]; then
|
|
|
|
export LIST_PATH
|
|
|
|
export STAMP_FILE
|
|
|
|
bash "$LIST_PATH/custom.sh"
|
2020-11-30 01:27:45 +01:00
|
|
|
fi
|
|
|
|
|
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
|
|
|
|
2020-10-15 04:55:57 +02:00
|
|
|
echo "$DEPENDENCIES_HASH" >"$DEPENDENCIES_HASH_FILE"
|