aboutsummaryrefslogtreecommitdiff
path: root/documentation/content/zh-tw/books/porters-handbook/pkg-files/_index.adoc
blob: 35c9bb111e7371e2b09fb50b33b3f90a8fff1835 (plain) (blame)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
---
title: Chapter 9. pkg-*
prev: books/porters-handbook/plist
next: books/porters-handbook/testing
description: Tricks about the pkg-* files
tags: ["pkg", "pkg-message", "UCL", "pkg-install", "pkg-deinstall"]
showBookMenu: true
weight: 9
path: "/books/porters-handbook/pkg-files/"
---

[[pkg-files]]
= pkg-*
:doctype: book
:toc: macro
:toclevels: 1
:icons: font
:sectnums:
:sectnumlevels: 6
:sectnumoffset: 9
:partnums:
:source-highlighter: rouge
:experimental:
:images-path: books/porters-handbook/

ifdef::env-beastie[]
ifdef::backend-html5[]
:imagesdir: ../../../../images/{images-path}
endif::[]
ifndef::book[]
include::shared/authors.adoc[]
include::shared/mirrors.adoc[]
include::shared/releases.adoc[]
include::shared/attributes/attributes-{{% lang %}}.adoc[]
include::shared/{{% lang %}}/teams.adoc[]
include::shared/{{% lang %}}/mailing-lists.adoc[]
include::shared/{{% lang %}}/urls.adoc[]
toc::[]
endif::[]
ifdef::backend-pdf,backend-epub3[]
include::../../../../../shared/asciidoctor.adoc[]
endif::[]
endif::[]

ifndef::env-beastie[]
toc::[]
include::../../../../../shared/asciidoctor.adoc[]
endif::[]

There are some tricks we have not mentioned yet about the [.filename]#pkg-*# files that come in handy sometimes.

[[porting-message]]
== pkg-message

To display a message when the package is installed, place the message in [.filename]#pkg-message#.
This capability is often useful to display additional installation steps to be taken after a `pkg install` or `pkg upgrade`.

[IMPORTANT]
====
* [.filename]#pkg-message# must contain only information that is _vital_ to setup and operation on FreeBSD, and that is unique to the port in question.
* Setup information should only be shown on initial install. Upgrade instructions should be shown only when upgrading from the relevant version.
* Do not surround the messages with either whitespace or lines of symbols (like `----------`, `**********`, or `==========`). Leave the formatting to man:pkg[8].
* Committers have blanket approval to constrain existing messages to install or upgrade ranges using the UCL format specifications.

====

pkg-message supports two formats:

raw::
A regular plain text file.
Its message is only displayed on install.

UCL::
If the file starts with "`[`" then it is considered to be a UCL file.
The UCL format is described on https://github.com/vstakhov/libucl[libucl's GitHub page].

[NOTE]
====
Do not add an entry for [.filename]#pkg-message# in [.filename]#pkg-plist#.
====

[[porting-message-ucl]]
=== UCL in pkg-message

The format is the following.
It should be an array of objects.
The objects themselves can have these keywords:

`message`::
The actual message to be displayed.
This keyword is mandatory.

`type`::
When the message should be displayed.

`maximum_version`::
Only if `type` is `upgrade`.
Display if upgrading from a version strictly lower than the version specified.

`minimum_version`::
Only if `type` is `upgrade`.
Display if upgrading from a version stictly greater than the version specified.

The `maximum_version` and `minimum_version` keywords can be combined.

The `type` keyword can have three values:

`install`::
The message should only be displayed when the package is installed.

`remove`::
The message should only be displayed when the package is removed.

`upgrade`::
the message should only be displayed during an upgrade of the package..

[IMPORTANT]
====
To preserve the compatibility with non UCL [.filename]#pkg-message# files,
the first line of a UCL [.filename]#pkg-message# _MUST be_ a single "`[`", and the last line _MUST be_ a single "`]`".
====

[[porting-message-ucl-short-ex]]
.UCL Short Strings
[example]
====

The message is delimited by double quotes `"`, this is used for simple single line strings:

[.programlisting]
....
[
{ type: install
  message: "Simple message"
}
]
....

====

[[porting-message-ucl-multiline-ex]]
.UCL Multiline Strings
[example]
====

Multiline strings use the standard here document notation.
The multiline delimiter _must_ start just after `<<` symbols without any whitespace and it _must_ consist of capital letters only.
To finish a multiline string, add the delimiter string on a line of its own without any whitespace.
The message from <<porting-message-ucl-short-ex>> can be written as:

[.programlisting]
....
[
{ type: install
  message: <<EOM
Simple message
EOM
}
]
....

====

[[porting-message-ucl-ex2]]
.Display a Message on Install/Deinstall
[example]
====

When a message only needs to be displayed on installation or uninstallation, set the type:

[.programlisting]
....
[
{
  type: remove
  message: "package being removed."
}
{ type: install, message: "package being installed."}
]
....

====

[[porting-message-ucl-ex3]]
.Display a Message on Upgrade
[example]
====

When a port is upgraded, the message displayed can be even more tailored to the port's needs.

[.programlisting]
....
[
{
  type: upgrade
  message: "Package is being upgraded."
}
{
  type: upgrade
  maximum_version: "1.0"
  message: "Upgrading from before 1.0 need to do this."
}
{
  type: upgrade
  minimum_version: "1.0"
  message: "Upgrading from after 1.0 should do that."
}
{
  type: upgrade
  maximum_version: "3.0"
  minimum_version: "1.0"
  message: "Upgrading from > 1.0 and < 3.0 remove that file."
}
]
....

[IMPORTANT]
****
When displaying a message on upgrade, it is important to limit when it is being shown to the user.
Most of the time it is by using `maximum_version` to limit its usage to upgrades from before a certain version when something specific needs to be done.
****

====

[[pkg-install]]
== pkg-install

If the port needs to execute commands when the binary package is installed with `pkg add` or `pkg install`, use [.filename]#pkg-install#.
This script will automatically be added to the package.
It will be run twice by `pkg`, the first time as `${SH} pkg-install ${PKGNAME} PRE-INSTALL` before the package is installed, and the second time as `${SH} pkg-install ${PKGNAME} POST-INSTALL` after it has been installed.
`$2` can be tested to determine which mode the script is being run in.
The `PKG_PREFIX` environmental variable will be set to the package installation directory.

[IMPORTANT]
====
This script is here to help you set up the package so that it is as ready to use as possible.
It _must not_ be abused to start services, stop services, or run any other commands that will modify the currently running system.
====

[[pkg-deinstall]]
== pkg-deinstall

This script executes when a package is removed.

This script will be run twice by `pkg delete`.
The first time as `${SH} pkg-deinstall ${PKGNAME} DEINSTALL` before the port is de-installed and the second time as `${SH} pkg-deinstall ${PKGNAME} POST-DEINSTALL` after the port has been de-installed.
`$2` can be tested to determine which mode the script is being run in.
The `PKG_PREFIX` environmental variable will be set to the package installation directory

[IMPORTANT]
====
This script is here to help you set up the package so that it is as ready to use as possible.
It _must not_ be abused to start services, stop services, or run any other commands that will modify the currently running system.
====

[[pkg-names]]
== Changing the Names of pkg-*

All the names of [.filename]#pkg-\*# are defined using variables that can be changed in the [.filename]#Makefile# if needed.
This is especially useful when sharing the same [.filename]#pkg-*# files among several ports or when it is necessary to write to one of these files.
See crossref:porting-dads[porting-wrkdir,writing to places other than `WRKDIR`] for why it is a bad idea to write directly into the directory containing the [.filename]#pkg-*# files.

Here is a list of variable names and their default values.
(`PKGDIR` defaults to `${MASTERDIR}`.)

[.informaltable]
[cols="1,1", frame="none", options="header"]
|===
| Variable
| Default value

|`DESCR`
|`${PKGDIR}/pkg-descr`

|`PLIST`
|`${PKGDIR}/pkg-plist`

|`PKGINSTALL`
|`${PKGDIR}/pkg-install`

|`PKGDEINSTALL`
|`${PKGDIR}/pkg-deinstall`

|`PKGMESSAGE`
|`${PKGDIR}/pkg-message`
|===

[[using-sub-files]]
== Making Use of `SUB_FILES` and `SUB_LIST`

`SUB_FILES` and `SUB_LIST` are useful for dynamic values in port files, such as the installation `PREFIX` in [.filename]#pkg-message#.

`SUB_FILES` specifies a list of files to be automatically modified.
Each [.filename]#file# in the `SUB_FILES` list must have a corresponding [.filename]#file.in# present in `FILESDIR`.
A modified version will be created as [.filename]#${WRKDIR}/file#.
Files defined as a value of `USE_RC_SUBR` are automatically added to `SUB_FILES`.
For the files [.filename]#pkg-message#, [.filename]#pkg-install#, and [.filename]#pkg-deinstall#, the corresponding Makefile variable is automatically set to point to the processed version.

`SUB_LIST` is a list of `VAR=VALUE` pairs.
For each pair, `%%VAR%%` will be replaced with `VALUE` in each file listed in `SUB_FILES`.
Several common pairs are automatically defined: `PREFIX`, `LOCALBASE`, `DATADIR`, `DOCSDIR`, `EXAMPLESDIR`, `WWWDIR`, and `ETCDIR`.
Any line beginning with `@comment` followed by a space, will be deleted from resulting files after a variable substitution.

This example replaces `%%ARCH%%` with the system architecture in a [.filename]#pkg-message#:

[.programlisting]
....
SUB_FILES=	pkg-message
SUB_LIST=	ARCH=${ARCH}
....

Note that for this example, [.filename]#pkg-message.in# must exist in `FILESDIR`.

Example of a good [.filename]#pkg-message.in#:

[.programlisting]
....
Now it is time to configure this package.
Copy %%PREFIX%%/shared/examples/putsy/%%ARCH%%.conf into your home directory
as .putsy.conf and edit it.
....