[skip ci] Idempotence code installation check for install via apt

This commit is contained in:
az 2021-11-30 19:31:52 +01:00
parent 2a02a0afb2
commit 6c906118cf

View file

@ -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(
"""
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")
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()
}