Fix: only add apt sources for users that want them (#22145) (#221285)

Signed-off-by: Matthias Breithaupt <m.breithaupt@vogl-electronic.com>
This commit is contained in:
Matthias B.
2024-08-06 23:54:05 +02:00
committed by GitHub
parent ab962cd422
commit cd340e6aa4
4 changed files with 61 additions and 6 deletions

View File

@@ -35,20 +35,46 @@ if [ "@@NAME@@" != "code-oss" ]; then
eval $(apt-config shell APT_TRUSTED_PARTS Dir::Etc::trustedparts/d)
CODE_TRUSTED_PART=${APT_TRUSTED_PARTS}microsoft.gpg
RET=true
if [ -e '/usr/share/debconf/confmodule' ]; then
. /usr/share/debconf/confmodule
db_get @@NAME@@/add-microsoft-repo || true
fi
# Install repository source list
WRITE_SOURCE=0
if [ ! -f $CODE_SOURCE_PART ] && [ ! -f /etc/rpi-issue ]; then
# Write source list if it does not exist and we're not running on Raspberry Pi OS
WRITE_SOURCE=1
elif grep -Eq "http:\/\/packages\.microsoft\.com\/repos\/vscode" $CODE_SOURCE_PART; then
if [ "$RET" = false ]; then
# The user does not want to add the microsoft repository
WRITE_SOURCE=0
elif grep -q "http://packages.microsoft.com/repos/vscode" $CODE_SOURCE_PART; then
# Migrate from old repository
WRITE_SOURCE=2
elif grep -q "http://packages.microsoft.com/repos/code" $CODE_SOURCE_PART; then
# Migrate from old repository
WRITE_SOURCE=2
elif apt-cache policy | grep -q "https://packages.microsoft.com/repos/code"; then
# Skip following checks if the repo is already known to apt
WRITE_SOURCE=0
elif [ ! -f $CODE_SOURCE_PART ] && [ ! -f /etc/rpi-issue ]; then
# Write source list if it does not exist and we're not running on Raspberry Pi OS
WRITE_SOURCE=1
elif grep -q "# disabled on upgrade to" $CODE_SOURCE_PART; then
# Write source list if it was disabled by OS upgrade
WRITE_SOURCE=1
fi
if [ "$WRITE_SOURCE" -eq "1" ]; then
if [ "$WRITE_SOURCE" -eq "1" ] && [ -e '/usr/share/debconf/confmodule' ]; then
# Ask the user whether to actually write the source list
db_input high @@NAME@@/add-microsoft-repo || true
db_go || true
db_get @@NAME@@/add-microsoft-repo
if [ "$RET" = false ]; then
WRITE_SOURCE=0
fi
fi
if [ "$WRITE_SOURCE" -ne "0" ]; then
echo "### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out this entry, but any other modifications may be lost.
deb [arch=amd64,arm64,armhf] https://packages.microsoft.com/repos/code stable main" > $CODE_SOURCE_PART