@@ -60,35 +60,22 @@ case class RpmScripts(pretrans: Option[String] = None,
60
60
preun : Option [String ] = None ,
61
61
postun : Option [String ] = None ) {
62
62
63
- def pretransContent (): String =
64
- pretrans.fold(" " )(" \n %pretrans\n " + _ + " \n\n " )
65
-
66
- def preContent (): String =
67
- pre.fold(" " )(" \n %pre\n " + _ + " \n\n " )
68
-
69
- def postContent (buildSymlinkScript : Option [String ]): String = {
70
- val scripts = Seq (post, buildSymlinkScript).flatten
71
- if (scripts.isEmpty)
72
- " "
73
- else
74
- " \n %post\n " + scripts.mkString(" \n " ) + " \n\n "
75
- }
76
-
77
- def posttransContent (): String =
78
- posttrans.fold(" " )(" \n %posttrans\n " + _ + " \n\n " )
79
-
80
- def verifyscriptContent (): String =
81
- verifyscript.fold(" " )(" \n %verifyscript\n " + _ + " \n\n " )
82
-
83
- def preunContent (): String =
84
- preun.fold(" " )(" \n %preun\n " + _ + " \n\n " )
85
-
86
- def postunContent (tearDownSymlinkScript : Option [String ]): String = {
87
- val scripts = Seq (postun, tearDownSymlinkScript).flatten
88
- if (scripts.isEmpty)
89
- " "
90
- else
91
- " \n %postun\n " + scripts.mkString(" \n " ) + " \n\n "
63
+ def pretransContent (): String = buildScript(" pretrans" , pretrans)
64
+ def preContent (): String = buildScript(" pre" , pre)
65
+ def postContent (): String = buildScript(" post" , post)
66
+ def posttransContent (): String = buildScript(" posttrans" , posttrans)
67
+ def verifyscriptContent (): String = buildScript(" verifyscript" , verifyscript)
68
+ def preunContent (): String = buildScript(" preun" , preun)
69
+ def postunContent (): String = buildScript(" postun" , postun)
70
+
71
+ private def buildScript (name : String , script : Option [String ]): String = {
72
+ script.map { code =>
73
+ s """
74
+ |% $name
75
+ | $code
76
+ |
77
+ | """ .stripMargin
78
+ } getOrElse " "
92
79
}
93
80
94
81
@ deprecated(
@@ -207,6 +194,8 @@ case class RpmSpec(meta: RpmMetadata,
207
194
mapping <- mappings
208
195
(file, dest) <- mapping.mappings
209
196
} sb append makeFilesLine(dest, mapping.fileData, file.isDirectory)
197
+
198
+ symlinks foreach (l => sb append s " ${l.link}\n " )
210
199
sb.toString
211
200
}
212
201
@@ -276,11 +265,11 @@ case class RpmSpec(meta: RpmMetadata,
276
265
// write scriptlets
277
266
sb append scriptlets.pretransContent()
278
267
sb append scriptlets.preContent()
279
- sb append scriptlets.postContent(buildSymlinkScript(meta.name, installDir, symlinks) )
268
+ sb append scriptlets.postContent()
280
269
sb append scriptlets.verifyscriptContent()
281
270
sb append scriptlets.posttransContent()
282
271
sb append scriptlets.preunContent()
283
- sb append scriptlets.postunContent(teardownSymlinkScript(meta.name, installDir, symlinks) )
272
+ sb append scriptlets.postunContent()
284
273
285
274
// Write file mappings
286
275
sb append fileSection
@@ -296,45 +285,4 @@ case class RpmSpec(meta: RpmMetadata,
296
285
}
297
286
sb.toString
298
287
}
299
-
300
- private def buildSymlinkScript (appName : String , installDir : String , symlinks : Seq [LinuxSymlink ]): Option [String ] =
301
- if (symlinks.isEmpty)
302
- None
303
- else {
304
- val relocateLinks = symlinks
305
- .map { symlink =>
306
- s """ rm -rf $$ (relocateLink ${symlink.link} $installDir $appName $$ RPM_INSTALL_PREFIX) && ln -s $$ (relocateLink ${symlink.destination} $installDir $appName $$ RPM_INSTALL_PREFIX) $$ (relocateLink ${symlink.link} $installDir $appName $$ RPM_INSTALL_PREFIX) """
307
- }
308
- .mkString(" \n " )
309
-
310
- Some (relocateLinkFunction + " \n " + relocateLinks)
311
- }
312
-
313
- private def teardownSymlinkScript (appName : String , installDir : String , symlinks : Seq [LinuxSymlink ]): Option [String ] =
314
- if (symlinks.isEmpty)
315
- None
316
- else {
317
- val checkUninstall = " if [ $1 -eq 0 ] ;\n then"
318
- val sourceAppConfig =
319
- s """ [ -e /etc/sysconfig/ $appName ] && . /etc/sysconfig/ $appName"""
320
- val cleanupLinks = symlinks
321
- .map { symlink =>
322
- s """ rm -rf $$ (relocateLink ${symlink.link} $installDir $appName $$ PACKAGE_PREFIX) """
323
- }
324
- .mkString(" \n " )
325
-
326
- Some (relocateLinkFunction + " \n " + checkUninstall + " \n " + sourceAppConfig + " \n " + cleanupLinks + " \n fi" )
327
- }
328
-
329
- private def relocateLinkFunction : String =
330
- """
331
- |relocateLink() {
332
- | if [ -n "$4" ] ;
333
- | then
334
- | RELOCATED_INSTALL_DIR="$4/$3"
335
- | echo "${1/$2/$RELOCATED_INSTALL_DIR}"
336
- | else
337
- | echo "$1"
338
- | fi
339
- |}""" .stripMargin
340
288
}
0 commit comments