-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #625 from sbt/wip/unify-maintainerscripts
Unify maintainerScripts
- Loading branch information
Showing
36 changed files
with
567 additions
and
279 deletions.
There are no files selected for viewing
17 changes: 9 additions & 8 deletions
17
src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/debian/postinst-template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
${{header}} | ||
${{loader-functions}} | ||
${{control-functions}} | ||
|
||
addGroup ${{daemon_group}} "${{daemon_group_gid}}" | ||
addUser ${{daemon_user}} "${{daemon_user_uid}}" ${{daemon_group}} "${{app_name}} user-daemon" "${{daemon_shell}}" | ||
|
||
${{chown-paths}} | ||
# ------------------------------------------------------------------------------------ | ||
# ____ _ _ _ | ||
# / ___| ___ _ ____ _____ _ __ / \ _ __ ___| |__ ___| |_ _ _ _ __ ___ | ||
# \___ \ / _ \ '__\ \ / / _ \ '__| / _ \ | '__/ __| '_ \ / _ \ __| | | | '_ \ / _ \ | ||
# ___) | __/ | \ V / __/ | / ___ \| | | (__| | | | __/ |_| |_| | |_) | __/ | ||
# |____/ \___|_| \_/ \___|_| /_/ \_\_| \___|_| |_|\___|\__|\__, | .__/ \___| | ||
# |___/|_| | ||
# ------------------------------------------------------------------------------------ | ||
|
||
${{loader-functions}} | ||
startService ${{app_name}} || echo "${{app_name}} could not be registered or started" |
25 changes: 9 additions & 16 deletions
25
src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/debian/postrm-template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,10 @@ | ||
${{header}} | ||
${{control-functions}} | ||
# ------------------------------------------------------------------------------------ | ||
# ____ _ _ _ | ||
# / ___| ___ _ ____ _____ _ __ / \ _ __ ___| |__ ___| |_ _ _ _ __ ___ | ||
# \___ \ / _ \ '__\ \ / / _ \ '__| / _ \ | '__/ __| '_ \ / _ \ __| | | | '_ \ / _ \ | ||
# ___) | __/ | \ V / __/ | / ___ \| | | (__| | | | __/ |_| |_| | |_) | __/ | ||
# |____/ \___|_| \_/ \___|_| /_/ \_\_| \___|_| |_|\___|\__|\__, | .__/ \___| | ||
# |___/|_| | ||
# ------------------------------------------------------------------------------------ | ||
|
||
# Deleting user: ${{daemon_user}} and group: ${{daemon_group}} | ||
case "$1" in | ||
remove|failed-upgrade|abort-upgrade|abort-install|disappear) | ||
;; | ||
purge) | ||
deleteUser ${{daemon_user}} | ||
deleteGroup ${{daemon_group}} | ||
;; | ||
upgrade) | ||
;; | ||
*) | ||
echo "postinst called with unknown argument \`\$1'" >&2 | ||
;; | ||
esac | ||
# empty |
12 changes: 10 additions & 2 deletions
12
src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/debian/preinst-template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
${{header}} | ||
${{control-functions}} | ||
# ------------------------------------------------------------------------------------ | ||
# ____ _ _ _ | ||
# / ___| ___ _ ____ _____ _ __ / \ _ __ ___| |__ ___| |_ _ _ _ __ ___ | ||
# \___ \ / _ \ '__\ \ / / _ \ '__| / _ \ | '__/ __| '_ \ / _ \ __| | | | '_ \ / _ \ | ||
# ___) | __/ | \ V / __/ | / ___ \| | | (__| | | | __/ |_| |_| | |_) | __/ | ||
# |____/ \___|_| \_/ \___|_| /_/ \_\_| \___|_| |_|\___|\__|\__, | .__/ \___| | ||
# |___/|_| | ||
# ------------------------------------------------------------------------------------ | ||
|
||
# empty |
10 changes: 9 additions & 1 deletion
10
src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/debian/prerm-template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
${{header}} | ||
# ------------------------------------------------------------------------------------ | ||
# ____ _ _ _ | ||
# / ___| ___ _ ____ _____ _ __ / \ _ __ ___| |__ ___| |_ _ _ _ __ ___ | ||
# \___ \ / _ \ '__\ \ / / _ \ '__| / _ \ | '__/ __| '_ \ / _ \ __| | | | '_ \ / _ \ | ||
# ___) | __/ | \ V / __/ | / ___ \| | | (__| | | | __/ |_| |_| | |_) | __/ | ||
# |____/ \___|_| \_/ \___|_| /_/ \_\_| \___|_| |_|\___|\__|\__, | .__/ \___| | ||
# |___/|_| | ||
# ------------------------------------------------------------------------------------ | ||
|
||
${{loader-functions}} | ||
|
||
stopService ${{app_name}} || echo "${{app_name}} wasn't even running!" |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/main/resources/com/typesafe/sbt/packager/debian/preinst-template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
${{header}} | ||
${{control-functions}} |
1 change: 1 addition & 0 deletions
1
src/main/resources/com/typesafe/sbt/packager/debian/prerm-template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
${{header}} | ||
${{control-functions}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,5 @@ trait JavaAppKeys { | |
| APP_DEFINES - the defines to go into the app | ||
| """.stripMargin | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/main/scala/com/typesafe/sbt/packager/archetypes/MaintainerScriptHelper.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.typesafe.sbt.packager.archetypes | ||
|
||
import sbt._ | ||
import com.typesafe.sbt.SbtNativePackager.autoImport.maintainerScripts | ||
|
||
/** | ||
* == Maintainer Script Helper == | ||
* | ||
* Provides utility methods to configure package maintainerScripts. | ||
*/ | ||
trait MaintainerScriptHelper { | ||
|
||
/** | ||
* Use this method to override preexisting configurations with custom file | ||
* definitions. | ||
* | ||
* @example {{{ | ||
* import DebianConstants._ | ||
* maintainerScripts in Debian := maintainerScriptsFromDirectory( | ||
* sourceDirectory.value / DebianSource / DebianMaintainerScripts, | ||
* Seq(Preinst, Postinst, Prerm, Postrm) | ||
* ) | ||
* }}} | ||
* @param dir from where to load files | ||
* @param scripts - a list of script names that should be used | ||
* @return filename to content mapping | ||
*/ | ||
def maintainerScriptsFromDirectory(dir: File, scripts: Seq[String]): Map[String, Seq[String]] = { | ||
scripts.map(dir / _) | ||
.filter(_.exists) | ||
.map { script => | ||
script.getName -> IO.readLines(script) | ||
}.toMap | ||
} | ||
|
||
/** | ||
* Use this method to append additional script content to specific maintainer scripts. | ||
* | ||
* @example Adding content from a string | ||
* {{{ | ||
* import RpmConstants._ | ||
* maintainerScripts in Rpm := maintainerScriptsAppend((maintainerScripts in Rpm).value)( | ||
* Pretrans -> "echo 'hello, world'", | ||
* Post -> s"echo 'installing ${(packageName in Rpm).value}'" | ||
* ) | ||
* }}} | ||
* | ||
* | ||
* @param current maintainer scripts | ||
* @param scripts scriptName -> scriptContent pairs | ||
* @return maintainerScripts with appended `scripts` | ||
* @see [[maintainerScriptsAppendFromFile]] | ||
*/ | ||
def maintainerScriptsAppend(current: Map[String, Seq[String]] = Map.empty)(scripts: (String, String)*): Map[String, Seq[String]] = { | ||
val appended = scripts.map { | ||
case (key, script) => key -> (current.getOrElse(key, Seq.empty) :+ script) | ||
}.toMap | ||
current ++ appended | ||
} | ||
|
||
/** | ||
* Use this method to append additional script content to specific maintainer scripts. | ||
* Note that you won't have any scriptReplacements available. | ||
* | ||
* @example Adding content from a string | ||
* {{{ | ||
* import RpmConstants._ | ||
* maintainerScripts in Rpm := maintainerScriptsAppendFromFile((maintainerScripts in Rpm).value)( | ||
* Pretrans -> (sourceDirectory.value / "rpm" / "pretrans"), | ||
* Post -> (sourceDirectory.value / "rpm" / "posttrans") | ||
* ) | ||
* }}} | ||
* | ||
* | ||
* @param current maintainer scripts | ||
* @param scripts scriptName -> scriptFile pairs | ||
* @return maintainerScripts with appended `scripts` | ||
* @see [[maintainerScriptsAppend]] for pure strings where you can insert arbitrary settings and tasks values | ||
*/ | ||
def maintainerScriptsAppendFromFile(current: Map[String, Seq[String]] = Map.empty)(scripts: (String, File)*): Map[String, Seq[String]] = { | ||
val appended = scripts.map { | ||
case (key, script) if script.exists && script.isFile => key -> (current.getOrElse(key, Seq.empty) ++ IO.readLines(script)) | ||
case (key, script) => sys.error(s"The maintainer script $key doesn't exist here: ${script.getAbsolutePath}") | ||
}.toMap | ||
current ++ appended | ||
} | ||
|
||
} |
Oops, something went wrong.