Skip to content

Commit

Permalink
Fix: only add apt sources for users that want it (microsoft#22145)
Browse files Browse the repository at this point in the history
Currently, vscode.list is added to /etc/apt/sources.d/ whenever it
doesn't exist. With this patch, the new behaviour is as follows:

1. If the user already has the Microsoft source file installed for apt,
   sources won't be added
2. If the user sets debconf-set-selections to set code/add-microsoft-repo
   to false, the sources won't be added
3. If sources might be added, the script checks whether it makes sense to
   (over)write them (i.e. the file doesn't exist, is old or has been disabled
   during some OS upgrade)
4. If is makes sense and the code/add-microsoft-repo is not set, the user is
   asked to cofirm, whether they actually want Microsoft sources to be
   installed (setting code/add-microsoft-repo to the selected value)
5. Only if it makes sense and the user agrees, the sources are installed

This change will mostly affect new users or those reinstalling vscode.
Personally, I feel like the whole approach of automatically adding the
repo is very invasive, and would prefer that it not be done at all.
However, with this change, it is up to the user whether they want it
to be installed or not. Since the default is set to true, users that
install vscode in noninteractive environments get the current behavior.
Existing users will either be asked once or never (depending on whther
step 4 above gets triggered). New users will be asked unless they make
a decision ahead of time using debconf-set-selections.

With this, microsoft#22145 and duplicates should be sufficiently addressed.

Signed-off-by: Matthias Breithaupt <m.breithaupt@vogl-electronic.com>
  • Loading branch information
m-byte committed Jul 9, 2024
1 parent b23e791 commit 9fa06c0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
4 changes: 4 additions & 0 deletions build/gulpfile.vscode.linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ function prepareDebPackage(arch) {
.pipe(replace('@@NAME@@', product.applicationName))
.pipe(rename('DEBIAN/postinst'));

const templates = gulp.src('resources/linux/debian/templates.template', { base: '.' })
.pipe(replace('@@NAME@@', product.applicationName))
.pipe(rename('DEBIAN/templates'));

const all = es.merge(control, postinst, postrm, prerm, desktops, appdata, workspaceMime, icon, bash_completion, zsh_completion, code);

return all.pipe(vfs.dest(destination));
Expand Down
22 changes: 21 additions & 1 deletion resources/linux/debian/postinst.template
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,18 @@ if [ "@@NAME@@" != "code-oss" ]; then
eval $(apt-config shell APT_TRUSTED_PARTS Dir::Etc::trustedparts/d)
CODE_TRUSTED_PART=${APT_TRUSTED_PARTS}microsoft.gpg

. /usr/share/debconf/confmodule
db_get @@NAME@@/add-microsoft-repo || true

# Install repository source list
WRITE_SOURCE=0
if [ ! -f $CODE_SOURCE_PART ] && [ ! -f /etc/rpi-issue ]; then
if [ apt-cache policy | grep -Eq "https:\/\/packages\.microsoft\.com\/repos\/code"]; then
# Skip following checks if the repo is already known to apt
WRITE_SOURCE=0
elif [ "$RET" = false ]; then
# The user does not want to add the microsoft repository
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 -Eq "http:\/\/packages\.microsoft\.com\/repos\/vscode" $CODE_SOURCE_PART; then
Expand All @@ -48,6 +57,17 @@ if [ "@@NAME@@" != "code-oss" ]; then
WRITE_SOURCE=1
fi

if [ "$WRITE_SOURCE" -eq "1" ]; then
# Ask the user what to do
db_input medium @@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" -eq "1" ]; then
echo "### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out this entry, but any other modifications may be lost.
Expand Down
16 changes: 16 additions & 0 deletions resources/linux/debian/postrm.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,19 @@ fi
if hash update-mime-database 2>/dev/null; then
update-mime-database /usr/share/mime
fi

. /usr/share/debconf/confmodule
db_get @@NAME@@/add-microsoft-repo || true
if [ "$RET" = true ]; then
eval $(apt-config shell APT_SOURCE_PARTS Dir::Etc::sourceparts/d)
CODE_SOURCE_PART=${APT_SOURCE_PARTS}vscode.list
rm -f $CODE_SOURCE_PART

eval $(apt-config shell APT_TRUSTED_PARTS Dir::Etc::trustedparts/d)
CODE_TRUSTED_PART=${APT_TRUSTED_PARTS}microsoft.gpg
rm -f $CODE_TRUSTED_PART
fi

if [ "$1" -eq "purge"]; then
db_purge
fi
7 changes: 7 additions & 0 deletions resources/linux/debian/templates.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Template: @@NAME@@/add-microsoft-repo
Type: boolean
Default: true
Description: Add Microsoft repository for Visual Studio Code?
The installer determined that you should most likely install add the
Microsoft apt repository for Visual Studio Code. Do you want this to
be done?

0 comments on commit 9fa06c0

Please sign in to comment.