public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [RFC] /etc/resolv.conf symlink through net-dns/resolvconf-symlink
@ 2011-08-10  9:55 Michał Górny
  2011-08-10 10:37 ` Sergei Trofimovich
  2011-08-11  2:03 ` Mike Frysinger
  0 siblings, 2 replies; 11+ messages in thread
From: Michał Górny @ 2011-08-10  9:55 UTC (permalink / raw
  To: gentoo-dev


[-- Attachment #1.1: Type: text/plain, Size: 1239 bytes --]

Hello,

Many modern systems have their /etc/resolv.conf files autogenerated at
runtime with DHCP, PPP or so on. Thus, storing that file in /etc seems
no longer correct as that directory may be mounted read-only.

I'm attaching a net-dns/resolvconf-symlink ebuild which
replaces /etc/resolv.conf with a symlink to a runtime-writable location
when installed. That package could be added to PDEPEND of packages like
net-misc/networkmanager or net-dns/openresolv.

Right now, that location is /var/run/resolv.conf. Using /run seems
better for it but that directory is not yet in our baselayout.

The package has USE=symlink which could be disabled by users which want
to keep /etc/resolv.conf as-is.

Right now, pkg_preinst() ensures that /etc/resolv.conf is autogenerated
(tested with resolvconf and networkmanager) or doesn't exist and refuses
to install otherwise. In future, this will be expanded to support more
cases if necessary.

In addition to that, pkg_preinst() and pkg_postrm() handle moving
resolv.conf there and back to avoid leaving user with no nameservers.

I also covered a similar idea in bug #377595 [1].

[1]:https://bugs.gentoo.org/show_bug.cgi?id=377595

-- 
Best regards,
Michał Górny

[-- Attachment #1.2: resolvconf-symlink-0.ebuild --]
[-- Type: application/octet-stream, Size: 1506 bytes --]

# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI=4

DESCRIPTION="Make /etc/resolv.conf a symlink to runtime-writable location"
HOMEPAGE="http://www.gentoo.org"
SRC_URI=""

LICENSE="public-domain"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="+symlink"

S=${WORKDIR}

pkg_preinst() {
	if use symlink; then
		if [[ -f "${ROOT}"etc/resolv.conf && ! -L "${ROOT}"etc/resolv.conf ]]
		then # migrate existing resolv.conf
			if [[ "$(head -n 1 "${ROOT}"etc/resolv.conf)" \
					!= "# Generated by "* ]]; then

				eerror "${ROOT}etc/resolv.conf seems not to be autogenerated."
				eerror "Aborting build to avoid removing user data. If that file is supposed"
				eerror "to be autogenerated, please remove it manually. Otherwise, please"
				eerror "set USE=-symlink to avoid installing resolv.conf symlink."

				die "${ROOT}etc/resolv.conf not autogenerated"
			else
				ebegin "Moving ${ROOT}etc/resolv.conf to ${ROOT}var/run/"
				mv "${ROOT}"etc/resolv.conf "${ROOT}"var/run/
				eend ${?} || die
			fi
		fi
	fi
}

src_install() {
	# XXX: /run should be more correct, when it's supported by baselayout

	use symlink && dosym /var/run/resolv.conf /etc/resolv.conf
}

pkg_postrm() {
	# Don't leave the user with no resolv.conf
	if [[ ! -e "${ROOT}"etc/resolv.conf && -f "${ROOT}"var/run/resolv.conf ]]; then
		ebegin "Moving ${ROOT}var/run/resolv.conf to ${ROOT}etc/"
		mv "${ROOT}"var/run/resolv.conf "${ROOT}"etc/
		eend ${?} || die
	fi
}

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 316 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-08-11  9:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-10  9:55 [gentoo-dev] [RFC] /etc/resolv.conf symlink through net-dns/resolvconf-symlink Michał Górny
2011-08-10 10:37 ` Sergei Trofimovich
2011-08-10 10:44   ` Michał Górny
2011-08-10 11:28     ` Sergei Trofimovich
2011-08-10 11:32       ` Michał Górny
2011-08-10 20:06         ` Robin H. Johnson
2011-08-10 20:13           ` Rich Freeman
2011-08-10 20:23             ` Robin H. Johnson
2011-08-10 20:47           ` Michał Górny
2011-08-11  2:03 ` Mike Frysinger
2011-08-11  9:00   ` Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox