pamduffy
pamduffy

Reputation: 21

Modifying install directory for rpm with sbt native-packager

I am trying to build an rpm package with the sbt-native-packager that installs in a custom directory eg /opt/myapp instead of /usr - due to in-house policy requirements.

I have a build.sbt that will build a standard rpm but I'm stumped when it comes to modifying the directory. My apologies-I'm quite new to scala, sbt and the native pacakger.

I am using mapGenericFilesToLinux and would like to keep its structure - just modifying the first part of the destination directory.

I found this code fragment in a git hub issue https://github.com/sbt/sbt-native-packager/issues/4#issuecomment-6731183

linuxPackageMappings <+= target map { target =>
  val src = target / "webapp"
  val dest = "/opt/app"
  LinuxPackageMapping(
  for {
    path <- (src ***).get
    if !path.isDirectory
  } yield path -> path.toString.replaceFirst(src.toString, dest)
 )
}

I believe I want to do something similar except to

linuxPackageMappings in Rpm <++= <SOMETHING HERE> { 
   // for loop that steps through the source and destination and modifies the directory
}

thanks in advance for any help

bye Pam

Upvotes: 2

Views: 1028

Answers (1)

jsuereth
jsuereth

Reputation: 5624

So, in sbt 0.12 you need to make sure you specify all the dependent keys you want to use before declaring the value you want. SO, let's pretend two things:

  1. linuxPackageMappings has all your mappings for the packaging.
  2. linuxPackageMappings in Rpm has nothing added to it directly.

We're going to take the value in linuxPackageMappings and alter the directory for linuxPackageMappings in Rpm:

linuxPackageMappings in Rpm <<= (linuxPackageMappings) map { mappings => 
  // Let's loop through the mappings and alter their on-disc location....
  for(LinuxPackageMapping(filesAndNames, meta, zipped) <- mappings) yield {
     val newFilesAndNames = for {
        (file, installPath) <- filesAndNames
     } yield file -> installPath.replaceFirst("/usr/share/app", "/opt/app")
     LinuxPackageMapping(newFilesAndNames, meta, zipped) 
  }
}

What this does is rip out the linux package mappings (which include whether or not to gzip files, and the user/group owners/permissions) and modify the install path of each file.

Hope that helps! IN sbt-native-packager.NEXT (not released) you can configure the default install location.

Upvotes: 2

Related Questions