You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.3 KiB
Kotlin
76 lines
2.3 KiB
Kotlin
package org.domaindrivenarchitecture.provs.framework.ubuntu.install.base
|
|
|
|
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
|
import org.domaindrivenarchitecture.provs.framework.core.ProvResult
|
|
|
|
|
|
private var aptInit = false
|
|
|
|
/**
|
|
* Installs package(s) by using package manager "apt".
|
|
*
|
|
* @param packages the packages to be installed, packages must be separated by space if there are more than one
|
|
*/
|
|
fun Prov.aptInstall(packages: String): ProvResult = def {
|
|
if (!aptInit) {
|
|
cmd("sudo apt-get update")
|
|
cmd("sudo apt-get install -qy apt-utils")
|
|
aptInit = true
|
|
}
|
|
|
|
val packageList = packages.split(" ")
|
|
for (packg in packageList) {
|
|
// see https://superuser.com/questions/164553/automatically-answer-yes-when-using-apt-get-install
|
|
cmd("sudo DEBIAN_FRONTEND=noninteractive apt-get install -qy $packg")
|
|
}
|
|
ProvResult(true) // dummy
|
|
}
|
|
|
|
|
|
/**
|
|
* Installs package(s) by using package manager "snap".
|
|
*
|
|
* @param packages the packages to be installed, packages must be separated by space if there are more than one
|
|
*/
|
|
// todo: add test
|
|
fun Prov.snapInstall(packages: String, classic: Boolean = false): ProvResult = def {
|
|
val packageList = packages.split(" ")
|
|
for (packg in packageList) {
|
|
cmd("sudo snap install $packg" + if (classic) " --classic" else "")
|
|
}
|
|
ProvResult(true) // dummy
|
|
}
|
|
|
|
|
|
/**
|
|
* Installs a package from a ppa (personal package archive) by using package manager "apt".
|
|
*
|
|
* @param packageName the package to install
|
|
*/
|
|
fun Prov.aptInstallFromPpa(launchPadUser: String, ppaName: String, packageName: String): ProvResult = def {
|
|
aptInstall("software-properties-common") // for being able to use add-apt-repository
|
|
cmd("sudo add-apt-repository -y ppa:$launchPadUser/$ppaName")
|
|
aptInstall(packageName)
|
|
}
|
|
|
|
|
|
/**
|
|
* Checks if a program is installed
|
|
*
|
|
* @param packageName to check
|
|
* @return true if program is installed
|
|
*/
|
|
@Suppress("unused") // used externally
|
|
fun Prov.isPackageInstalled(packageName: String): Boolean {
|
|
return chk("timeout 2 dpkg -l $packageName")
|
|
}
|
|
|
|
|
|
/**
|
|
* Removes a package including its configuration and data files
|
|
*/
|
|
@Suppress("unused") // used externally
|
|
fun Prov.aptPurge(packageName: String): Boolean {
|
|
return chk("sudo apt-get purge -qy $packageName")
|
|
}
|