diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/extensions/workplace/base/VSCode.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/extensions/workplace/base/VSCode.kt index fc70a3d..752b4c6 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/extensions/workplace/base/VSCode.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/extensions/workplace/base/VSCode.kt @@ -3,6 +3,7 @@ package org.domaindrivenarchitecture.provs.extensions.workplace.base import org.domaindrivenarchitecture.provs.core.Prov import org.domaindrivenarchitecture.provs.core.ProvResult import org.domaindrivenarchitecture.provs.ubuntu.install.base.aptInstall +import org.domaindrivenarchitecture.provs.ubuntu.install.base.isPackageInstalled fun Prov.installVSC(vararg options: String) = requireAll { @@ -31,19 +32,21 @@ private fun Prov.prerequisitesVSCinstall() = def { @Suppress("unused") // only required for installation of vscode via apt -private fun Prov.configurePackageManagerForVsc() = requireAll { +private fun Prov.installVscWithApt() = requireAll { + val packageName = "code" + if (!isPackageInstalled(packageName)) { // see https://code.visualstudio.com/docs/setup/linux - // alternatively install with snapd (but this cannot be tested within docker as snapd within docker is not working/supported) - - sh( - """ - curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg - sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/ - sudo sh -c 'echo \"deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/vscode stable main\" > /etc/apt/sources.list.d/vscode.list' - """ - ) - aptInstall("apt-transport-https") - aptInstall("code") + // alternatively install with snapd (but this cannot be tested within docker as snapd within docker is not working/supported) + sh(""" + curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg + sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/ + sudo sh -c 'echo \"deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/vscode stable main\" > /etc/apt/sources.list.d/vscode.list' + """) + aptInstall("apt-transport-https") + aptInstall(packageName) + } else { + ProvResult(true, out = "Package $packageName already installed.") + } } @@ -51,9 +54,7 @@ private fun Prov.installVSCPackage() = def { cmd("sudo snap install code --classic") // to install via apt use: - // configurePackageManagerForVsc() - // aptInstall("code") - + // installVscWithApt() }