Customising installs for sbt-native-packager

Further to my previous post, turns out we want to install files under /opt/<package>, and the associated config under /etc/<package>. And ideally we don’t want to make the sbt-assembly stage force it’s output to a non-standard directory.


Here’s my updated sbtproj/assembly.sbt file (I removed the outputPath entry)

1
2
3
4
5
import AssemblyKeys._
 
assemblySettings
 
mainClass in assembly := Some("uk.co.devsoup.sbt.rpm.Hi")

assemblySettings

mainClass in assembly := Some("uk.co.devsoup.sbt.rpm.Hi")

and here’s my updated sbtproj/build.sbt file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import NativePackagerKeys._
import sbtassembly.Plugin.AssemblyKeys
import com.typesafe.sbt.packager.linux.LinuxPackageMapping
import com.typesafe.sbt.packager.linux.LinuxFileMetaData
import com.typesafe.sbt.packager.linux.LinuxSymlink
import java.io.File
 
packagerSettings
 
name := "sbt-rpm"
 
version := "1.0"
 
maintainer := "Andrew &lt;[email protected]&gt;"
 
packageSummary := "Test rpm package"
 
packageDescription := """SBT built RPM."""
 
rpmRelease := "1"
 
rpmVendor := "devsoup"
 
rpmUrl := Some("http://www.devsoup.co.uk")
 
rpmLicense := Some("BSD")
 
rpmPre := Some("""echo "pre-install"""")
 
rpmPost := Some("""echo "post-install"""")
 
rpmPretrans := Some("""echo "pretrans"""")
 
rpmPosttrans := Some("""echo "posttrans"""")
 
rpmPreun := Some("""echo "pre-uninstall"""")
 
rpmPostun := Some("""echo "post-uninstall"""")
 
rpmRequirements := Seq("java-1.7.0-openjdk")
 
// Overwrite the file mappings
mappings in Universal := Seq (
  // Include the sbt-assembly output
  AssemblyKeys.assembly.value -&gt; String.format("lib/%s", AssemblyKeys.assembly.value.getName()),
  // Add a dummy config file
  new File("src/universal/conf/config.txt") -&gt; "conf/config.txt"
)
 
// Overwrite the RPM file mappings
linuxPackageMappings in Rpm := Seq (
    // Include the sbt-assembly output file
    LinuxPackageMapping(Array(
        AssemblyKeys.assembly.value -&gt;String.format("/opt/%s-%s/lib/%s", name.value, version.value, AssemblyKeys.assembly.value.getName())
        )),
    // Add a configuration file
    LinuxPackageMapping(Array(
        new File("src/universal/conf/config.txt") -&gt; String.format("/etc/%s-%s/config.txt", name.value, version.value)
        ), 
        new LinuxFileMetaData("root", "root", "0644", "true", false)
        )
)
 
// When producing an RPM, force a symlink under the /opt install location to the /etc config dir
linuxPackageSymlinks in Rpm := Seq (
    LinuxSymlink(String.format("/opt/%s-%s/conf", name.value, version.value), String.format("/etc/%s-%s", name.value, version.value))
    )

packagerSettings

name := "sbt-rpm"

version := "1.0"

maintainer := "Andrew &lt;[email protected]&gt;"

packageSummary := "Test rpm package"

packageDescription := """SBT built RPM."""

rpmRelease := "1"

rpmVendor := "devsoup"

rpmUrl := Some("http://www.devsoup.co.uk")

rpmLicense := Some("BSD")

rpmPre := Some("""echo "pre-install"""")

rpmPost := Some("""echo "post-install"""")

rpmPretrans := Some("""echo "pretrans"""")

rpmPosttrans := Some("""echo "posttrans"""")

rpmPreun := Some("""echo "pre-uninstall"""")

rpmPostun := Some("""echo "post-uninstall"""")

rpmRequirements := Seq("java-1.7.0-openjdk")

// Overwrite the file mappings
mappings in Universal := Seq (
// Include the sbt-assembly output
AssemblyKeys.assembly.value -&gt; String.format("lib/%s", AssemblyKeys.assembly.value.getName()),
// Add a dummy config file
new File("src/universal/conf/config.txt") -&gt; "conf/config.txt"
)

// Overwrite the RPM file mappings
linuxPackageMappings in Rpm := Seq (
// Include the sbt-assembly output file
LinuxPackageMapping(Array(
AssemblyKeys.assembly.value -&gt;String.format("/opt/%s-%s/lib/%s", name.value, version.value, AssemblyKeys.assembly.value.getName())
)),
// Add a configuration file
LinuxPackageMapping(Array(
new File("src/universal/conf/config.txt") -&gt; String.format("/etc/%s-%s/config.txt", name.value, version.value)
),
new LinuxFileMetaData("root", "root", "0644", "true", false)
)
)

// When producing an RPM, force a symlink under the /opt install location to the /etc config dir
linuxPackageSymlinks in Rpm := Seq (
LinuxSymlink(String.format("/opt/%s-%s/conf", name.value, version.value), String.format("/etc/%s-%s", name.value, version.value))
)

in which I basically overwrite all the generic mappings and force it to do my own thing.

This is my personal blog - all views are my own.

Tagged with: , , ,