@@ -111,8 +111,8 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin {
111
111
chmod(cfile, " 0644" )
112
112
cfile
113
113
},
114
- debianExplodedPackage <<= (linuxPackageMappings, debianControlFile, debianMaintainerScripts, debianConffilesFile, debianControlScriptsReplacements, linuxPackageSymlinks, target)
115
- map { (mappings, _, maintScripts, _, replacements, symlinks, t) =>
114
+ debianExplodedPackage <<= (linuxPackageMappings, debianControlFile, debianMaintainerScripts, debianConffilesFile, debianControlScriptsReplacements, linuxPackageSymlinks, target, streams )
115
+ map { (mappings, _, maintScripts, _, replacements, symlinks, t, streams ) =>
116
116
117
117
// Create files and directories
118
118
mappings foreach {
@@ -142,6 +142,32 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin {
142
142
filterAndFixPerms(targetFile, replacements, LinuxFileMetaData ())
143
143
}
144
144
145
+ // Check for non root user/group and append to postinst / postrm
146
+ // filter all root mappings, map to (user,group) key, group by, append everything
147
+ mappings filter {
148
+ case LinuxPackageMapping (_, LinuxFileMetaData (" root" , " root" , _, _, _), _) => false
149
+ case _ => true
150
+ } map {
151
+ case LinuxPackageMapping (paths, LinuxFileMetaData (user, group, _, _, _), _) => (user, group) -> paths
152
+ } groupBy (_._1) foreach {
153
+ case ((user, group), pathList) =>
154
+ streams.log info (" Altering postrm/postinst files to add user " + user + " and group " + group)
155
+ val postinst = t / " DEBIAN" / " postinst"
156
+ val postrm = t / " DEBIAN" / " postrm"
157
+
158
+ val replacements = Seq (" group" -> group, " user" -> user)
159
+ IO .append(postinst, TemplateWriter .generateScript(DebianPlugin .postinstGroupaddTemplateSource, replacements))
160
+ IO .append(postinst, TemplateWriter .generateScript(DebianPlugin .postinstUseraddTemplateSource, replacements))
161
+
162
+ // remove key, flatten it and then go through each file
163
+ pathList.map(_._2).flatten foreach {
164
+ case (_, target) =>
165
+ val pathReplacements = replacements :+ (" path" -> target.toString)
166
+ IO .append(postinst, TemplateWriter .generateScript(DebianPlugin .postinstChownTemplateSource, pathReplacements))
167
+ }
168
+
169
+ IO .append(postrm, TemplateWriter .generateScript(DebianPlugin .postrmPurgeTemplateSource, replacements))
170
+ }
145
171
t
146
172
},
147
173
debianMD5sumsFile <<= (debianExplodedPackage, target) map {
@@ -180,3 +206,10 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin {
180
206
}))
181
207
182
208
}
209
+
210
+ object DebianPlugin {
211
+ private def postinstGroupaddTemplateSource : java.net.URL = getClass.getResource(" postinst-groupadd" )
212
+ private def postinstUseraddTemplateSource : java.net.URL = getClass.getResource(" postinst-useradd" )
213
+ private def postinstChownTemplateSource : java.net.URL = getClass.getResource(" postinst-chown" )
214
+ private def postrmPurgeTemplateSource : java.net.URL = getClass.getResource(" postrm-purge" )
215
+ }
0 commit comments