diff --git a/build/gulpfile.vscode.linux.js b/build/gulpfile.vscode.linux.js index 28ddfb04c3d908..f374ea967eac45 100644 --- a/build/gulpfile.vscode.linux.js +++ b/build/gulpfile.vscode.linux.js @@ -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)); diff --git a/resources/linux/debian/postinst.template b/resources/linux/debian/postinst.template index 16acb1481bffde..6744a9478e8ee5 100755 --- a/resources/linux/debian/postinst.template +++ b/resources/linux/debian/postinst.template @@ -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 @@ -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. diff --git a/resources/linux/debian/postrm.template b/resources/linux/debian/postrm.template index fb36d522f388d4..f33d20f79a19d3 100755 --- a/resources/linux/debian/postrm.template +++ b/resources/linux/debian/postrm.template @@ -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 diff --git a/resources/linux/debian/templates.template b/resources/linux/debian/templates.template new file mode 100644 index 00000000000000..c68cab9e2a557d --- /dev/null +++ b/resources/linux/debian/templates.template @@ -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?