7.3. Configuration files
前一頁 | 章 7. Advanced `pkg-plist` practices | 下一頁

## 7.3. Configuration files

If your port requires some configuration files in ``PREFIX`/etc`, do not just install them and list them in `pkg-plist`. That will cause pkg_delete(1) to delete files carefully edited by the user and a new installation to wipe them out.

Instead, install sample files with a suffix (``filename`.sample` will work well). Copy the sample file as the real configuration file, if it does not exist. On deinstall, delete the configuration file, but only if it was not modified by the user. You need to handle this both in the port `Makefile`, and in the `pkg-plist` (for installation from the package).

Example of the `Makefile` part:

post-install: @if [ ! -f ${PREFIX}/etc/orbit.conf ]; then \ ${CP} -p ${PREFIX}/etc/orbit.conf.sample ${PREFIX}/etc/orbit.conf ; \ fi

Example of the `pkg-plist` part:

@unexec if cmp -s %D/etc/orbit.conf.sample %D/etc/orbit.conf; then rm -f %D/etc/orbit.conf; fi etc/orbit.conf.sample @exec if [ ! -f %D/etc/orbit.conf ] ; then cp -p %D/%F %B/orbit.conf; fi

Alternatively, print out a message pointing out that the user has to copy and edit the file before the software can be made to work.

前一頁 | 上一層 | 下一頁
7.2. Empty directories | 起始頁 | 7.4. Dynamic vs. static package list

本文及其他文件，可由此下載： ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/。

若有 FreeBSD 方面疑問，請先閱讀 FreeBSD 相關文件，如不能解決的話，再洽詢 <questions@FreeBSD.org>。
關於本文件的問題，請洽詢 <doc@FreeBSD.org>。