improve installPpaFirefox to set priority for ppa above default (snap) installation and allow unattended upgrades
This commit is contained in:
parent
32840cdd46
commit
e8fcdae778
2 changed files with 71 additions and 32 deletions
|
@ -1,42 +1,53 @@
|
||||||
package org.domaindrivenarchitecture.provs.desktop.infrastructure
|
package org.domaindrivenarchitecture.provs.desktop.infrastructure
|
||||||
|
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.addTextToFile
|
import org.domaindrivenarchitecture.provs.framework.core.ProvResult
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.checkFile
|
||||||
import java.io.File
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createFile
|
||||||
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstallFromPpa
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Installs non-snap firefox, removing a firefox snap-installation if existing
|
* Installs ppa firefox (i.e. non-snap), removing snap-firefox if existing.
|
||||||
*/
|
*/
|
||||||
fun Prov.installPpaFirefox() = task {
|
fun Prov.installPpaFirefox() = taskWithResult {
|
||||||
|
|
||||||
// inspired by: https://www.omgubuntu.co.uk/2022/04/how-to-install-firefox-deb-apt-ubuntu-22-04
|
// inspired by: https://wiki.ubuntuusers.de/Firefox/Installation/PPA/
|
||||||
|
|
||||||
task("remove snap firefox") {
|
val unattendeUpgradesForPpaFirefox = "/etc/apt/apt.conf.d/51unattended-upgrades-firefox"
|
||||||
if (chk("snap list | grep firefox")) {
|
|
||||||
|
val preCondition = checkFile(unattendeUpgradesForPpaFirefox)
|
||||||
|
if (preCondition) {
|
||||||
|
return@taskWithResult ProvResult(true, out = "Firefox already installed with ppa")
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd("sudo apt-get -qy remove firefox", sudo = true)
|
||||||
|
optional {
|
||||||
cmd("snap remove firefox", sudo = true)
|
cmd("snap remove firefox", sudo = true)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
aptInstall("software-properties-common")
|
createFile("/etc/apt/preferences.d/mozillateam", mozillaTeamFileContent, sudo = true)
|
||||||
cmd("add-apt-repository -y ppa:mozillateam/ppa", sudo = true)
|
|
||||||
|
|
||||||
// set prio in order to use ppa-firefox above snap
|
aptInstallFromPpa("mozillateam", "ppa", "firefox")
|
||||||
addTextToFile(
|
|
||||||
"\nPackage: *\n" +
|
createFile(
|
||||||
"Pin: release o=LP-PPA-mozillateam\n" +
|
unattendeUpgradesForPpaFirefox,
|
||||||
"Pin-Priority: 1001\n",
|
"Unattended-Upgrade::Allowed-Origins:: \"LP-PPA-mozillateam:\${distro_codename}\";\n",
|
||||||
File("/etc/apt/preferences.d/mozilla-firefox"),
|
|
||||||
sudo = true
|
sudo = true
|
||||||
)
|
)
|
||||||
|
|
||||||
addTextToFile(
|
|
||||||
"""Unattended-Upgrade::Allowed-Origins:: "LP-PPA-mozillateam:${'$'}{distro_codename}";""",
|
|
||||||
File("/etc/apt/preferences.d/mozilla-firefox"),
|
|
||||||
sudo = true
|
|
||||||
)
|
|
||||||
|
|
||||||
aptInstall("firefox")
|
|
||||||
cmd("apt-get upgrade -y --allow-downgrades firefox", sudo = true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private val mozillaTeamFileContent = """
|
||||||
|
Package: *
|
||||||
|
Pin: release o=LP-PPA-mozillateam
|
||||||
|
Pin-Priority: 100
|
||||||
|
|
||||||
|
Package: firefox*
|
||||||
|
Pin: release o=LP-PPA-mozillateam
|
||||||
|
Pin-Priority: 1001
|
||||||
|
|
||||||
|
Package: firefox*
|
||||||
|
Pin: release o=Ubuntu
|
||||||
|
Pin-Priority: -1
|
||||||
|
""".trimIndent()
|
|
@ -1,32 +1,60 @@
|
||||||
package org.domaindrivenarchitecture.provs.desktop.infrastructure
|
package org.domaindrivenarchitecture.provs.desktop.infrastructure
|
||||||
|
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.remote
|
import org.domaindrivenarchitecture.provs.framework.core.remote
|
||||||
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.deleteFile
|
||||||
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.fileContainsText
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.checkPackageInstalled
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.checkPackageInstalled
|
||||||
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.isPackageInstalled
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.secret.secretSources.PromptSecretSource
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.secret.secretSources.PromptSecretSource
|
||||||
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
|
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
|
||||||
import org.domaindrivenarchitecture.provs.test.tags.ExtensiveContainerTest
|
import org.domaindrivenarchitecture.provs.test.tags.ExtensiveContainerTest
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.Assertions.assertTrue
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
import org.junit.jupiter.api.Disabled
|
import org.junit.jupiter.api.Disabled
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
internal class FirefoxKtTest {
|
internal class FirefoxKtTest {
|
||||||
|
|
||||||
// Attention: this test does not test full functionality of installFirefox, e.g. does not test
|
// Attention: this test does not test full functionality of installPpaFirefox, e.g. does not test
|
||||||
// remove snap, as this test runs against a container which does not have snap-firefox installed
|
// remove snap-firefox, as this test runs against a container, which does have neither snap nor snap-firefox installed
|
||||||
@ExtensiveContainerTest
|
@ExtensiveContainerTest
|
||||||
fun installFirefox() {
|
fun installFirefox() {
|
||||||
|
// given
|
||||||
|
val prov = defaultTestContainer()
|
||||||
|
|
||||||
// when
|
// when
|
||||||
val result = defaultTestContainer().session {
|
val result = prov.session {
|
||||||
|
deleteFile("/etc/apt/apt.conf.d/51unattended-upgrades-firefox", sudo = true)
|
||||||
|
deleteFile("/etc/apt/preferences.d/mozillateam", sudo = true)
|
||||||
installPpaFirefox()
|
installPpaFirefox()
|
||||||
checkPackageInstalled("firefox")
|
|
||||||
}
|
}
|
||||||
|
val result2 = prov.installPpaFirefox()
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertTrue(result.success)
|
assertTrue(result.success)
|
||||||
|
assertEquals("Firefox already installed with ppa", result2.out)
|
||||||
|
|
||||||
|
assertTrue(prov.isPackageInstalled("firefox"))
|
||||||
|
assertTrue(
|
||||||
|
prov.fileContainsText(
|
||||||
|
"/etc/apt/apt.conf.d/51unattended-upgrades-firefox",
|
||||||
|
"Unattended-Upgrade::Allowed-Origins:: \"LP-PPA-mozillateam:\${distro_codename}\";\n",
|
||||||
|
sudo = true
|
||||||
|
)
|
||||||
|
)
|
||||||
|
val expectedPolicyLine = Regex("1001? https?://ppa.launchpad(?:content)?.net/mozillateam/ppa/ubuntu")
|
||||||
|
val policy = prov.cmd("apt policy firefox").out
|
||||||
|
assertTrue(
|
||||||
|
policy?.contains(expectedPolicyLine) ?: false,
|
||||||
|
"$expectedPolicyLine was not found in $policy"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests installing firefox on a remote machine, e.g. a virtual machine
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Disabled("Update connection details,then enable and run manually")
|
@Disabled("Update connection details, then enable the test and run manually")
|
||||||
fun installFirefox_remotely() {
|
fun installFirefox_remotely() {
|
||||||
val host = "192.168.56.123"
|
val host = "192.168.56.123"
|
||||||
val user = "user"
|
val user = "user"
|
||||||
|
|
Loading…
Reference in a new issue