diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt index 0da3e0b..b99081e 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt @@ -4,6 +4,7 @@ import org.domaindrivenarchitecture.provs.framework.core.Prov import org.domaindrivenarchitecture.provs.framework.core.ProvResult import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.* import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall +import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.checkPackage import org.domaindrivenarchitecture.provs.framework.ubuntu.web.base.downloadFromURL @@ -160,3 +161,17 @@ fun Prov.installTerraform() = task { cmd("tfenv install latest:^1.4.6", sudo = true) cmd("tfenv use latest:^1.4.6", sudo = true) } + +fun Prov.installDirenv() = taskWithResult { + val bashConfigFile = "~/.bashrc.d/direnv.sh" + if (!checkFile(bashConfigFile) && !checkPackage("direnv")) { + aptInstall("direnv") + val content = """ + eval "$(direnv hook bash)" + """ + "\n".trimIndent() + createFile(bashConfigFile, content) + addResult(checkPackage("direnv"), info = "direnv has been installed.") + } else { + return@taskWithResult ProvResult(true, out = "direnv or ~/.bashrc.d/direnv.sh already installed") + } +} \ No newline at end of file diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOpsKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOpsKtTest.kt index a539962..f3a9f91 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOpsKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOpsKtTest.kt @@ -58,4 +58,20 @@ internal class DevOpsKtTest { assertTrue(res.success) assertTrue(prov.checkFile("/usr/local/bin/kubeconform")) } + + @ExtensiveContainerTest + fun installDirenv() { + // given + val prov = defaultTestContainer() + + // when + val res = prov.task { + installDirenv() + installDirenv() // check repeatability + } + + // then + assertTrue(res.success) + //assertTrue(prov.checkFile("/usr/local/bin/kubeconform")) + } }