From fdc1294993386899d667f04a906801d3406b9064 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sat, 12 Feb 2022 14:02:43 -0800 Subject: [PATCH] setup-apt-repo: Support installing an APT preferences file. Signed-off-by: Anders Kaseorg --- scripts/lib/setup-apt-repo | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/scripts/lib/setup-apt-repo b/scripts/lib/setup-apt-repo index d3bfb0d28a..b35d8e9e0e 100755 --- a/scripts/lib/setup-apt-repo +++ b/scripts/lib/setup-apt-repo @@ -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