setup-apt-repo: Support installing an APT preferences file.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2022-02-12 14:02:43 -08:00 committed by Tim Abbott
parent 7077a289ae
commit fdc1294993
1 changed files with 13 additions and 8 deletions

View File

@ -13,6 +13,7 @@ set -x
set -e
set -u
set -o pipefail
shopt -s extglob
verify=false
args="$(getopt -o '' --long verify,list: -- "$@")"
@ -40,6 +41,7 @@ done
mkdir -p /var/lib/zulip
SOURCES_FILE=/etc/apt/sources.list.d/$LIST.list
PREF_FILE=/etc/apt/preferences.d/$LIST.pref
STAMP_FILE=/etc/apt/sources.list.d/$LIST.list.apt-update-in-progress
ZULIP_SCRIPTS="$(cd "$(dirname "$(dirname "$0")")" && pwd)"
@ -64,7 +66,7 @@ EOF
exit 1
fi
DEPENDENCIES_HASH=$(sha1sum "$LIST_PATH/"*.asc "$0")
DEPENDENCIES_HASH="$(sha256sum "$LIST_PATH"/?(*.asc|"$release.list"|"$LIST.pref"|custom.sh) "$ZULIP_SCRIPTS/lib/setup-apt-repo")"
DEPENDENCIES_HASH_FILE="/var/lib/zulip/setup-repositories-state-$LIST"
# Ensure that DEPENDENCIES_HASH_FILE exists before hashing it.
touch "$DEPENDENCIES_HASH_FILE"
@ -78,11 +80,8 @@ elif [ "$verify" == true ]; then
exit 1
fi
# Ensure that the sources file exists
touch "$SOURCES_FILE"
# Hash it to check if the sources file is changed by the script later.
zulip_source_hash=$(sha1sum "$SOURCES_FILE")
# Hash to check if the configuration is changed by the script later.
hashes=$(sha256sum "$SOURCES_FILE" "$PREF_FILE" 2>/dev/null || true)
pre_setup_deps=(lsb-release apt-transport-https ca-certificates gnupg curl)
if ! apt-get -dy install "${pre_setup_deps[@]}"; then
@ -93,14 +92,20 @@ apt-get -y install "${pre_setup_deps[@]}"
apt-key add "$LIST_PATH/"*.asc
cp "$LIST_PATH/$release.list" "$SOURCES_FILE"
if [ -e "$LIST_PATH/$LIST.pref" ]; then
cp "$LIST_PATH/$LIST.pref" "$PREF_FILE"
else
rm -f "$PREF_FILE"
fi
if [ -e "$LIST_PATH/custom.sh" ]; then
export LIST_PATH
export STAMP_FILE
bash "$LIST_PATH/custom.sh"
fi
if [ "$zulip_source_hash" = "$(sha1sum "$SOURCES_FILE")" ] && ! [ -e "$STAMP_FILE" ]; then
echo "zulip.list file did not change; skipping apt-get update"
if [ "$hashes" = "$(sha256sum "$SOURCES_FILE" "$PREF_FILE" 2>/dev/null || true)" ] && ! [ -e "$STAMP_FILE" ]; then
echo "APT configuration did not change; skipping apt-get update"
else
# 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