From c9338e89cdb603c1e08998bba28fbc977a62fc51 Mon Sep 17 00:00:00 2001 From: Michael Haubenwallner Date: Thu, 21 Mar 2019 10:01:32 +0100 Subject: [PATCH] add prefix support per Makefile target 'install' * Add explicit @GENTOO_PORTAGE_EPREFIX@ placeholder to source files, substituted during 'make install', because the heuristic of hprefixify in the ebuild is false positive on CONFIG_PROTECT_MASK at least. * Be explicit in the Makefile about files to be installed. * Allow for src_configure to define variables like OS and EPREFIX once. * To avoid modifying source files, the in file substitution is done in DESTDIR, so better require DESTDIR not to be empty for 'make install'. --- Makefile | 61 +++++++++++++++++++++++++++++++++++++++--- etc/env.d/50baselayout | 10 +++---- etc/profile | 26 +++++++++--------- etc/shells | 24 ++++++++--------- share.Linux/passwd | 26 +++++++++--------- 5 files changed, 100 insertions(+), 47 deletions(-) diff --git a/Makefile b/Makefile index 05ed3e7..123328b 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,11 @@ INSTALL_EXE = install -m 0755 INSTALL_FILE = install -m 0644 INSTALL_SECURE = install -m 0600 +# src_configure may find and update these lines, but +# if not, take them from environment, or use fallbacks +OS ?= +EPREFIX ?= + ifeq ($(OS),) OS=$(shell uname -s) ifneq ($(OS),Linux) @@ -49,6 +54,40 @@ KEEP_DIRS = $(KEEP_DIRS-$(OS)) \ /var/log \ /var/spool +ETCFILES-BSD += \ + etc.BSD/COPYRIGHT \ + etc.BSD/login.conf +ETCFILES-Linux += \ + etc.Linux/filesystems \ + etc.Linux/inputrc \ + etc.Linux/modprobe.d/aliases.conf \ + etc.Linux/modprobe.d/i386.conf \ + etc.Linux/sysctl.conf +ETCFILES = $(ETCFILES-$(OS)) \ + etc.$(OS)/issue \ + etc.$(OS)/issue.logo \ + etc.$(OS)/os-release \ + etc/env.d/50baselayout \ + etc/hosts \ + etc/networks \ + etc/profile \ + etc/protocols \ + etc/services \ + etc/shells + +SHAREFILES-OS += \ + share.$(OS)/fstab \ + share.$(OS)/group +SHAREFILES-BSD += \ + $(SHAREFILES-OS) \ + share.BSD/master.passwd +SHAREFILES-Linux += \ + $(SHAREFILES-OS) \ + share.Linux/issue.devfix \ + share.Linux/passwd \ + share.Linux/shadow +SHAREFILES = $(SHAREFILES-$(OS)) + all: changelog: @@ -57,10 +96,24 @@ changelog: clean: install: - $(INSTALL_DIR) $(DESTDIR)/etc - cp -pPR etc/* etc.$(OS)/* $(DESTDIR)/etc/ - $(INSTALL_DIR) $(DESTDIR)/usr/share/baselayout - cp -pPR share.$(OS)/* $(DESTDIR)/usr/share/baselayout/ + test -n '$(DESTDIR)' + instfiles= ; \ + for srcf in $(ETCFILES) ; do \ + instf=/$${srcf#*/} ; \ + instd=$${instf%/*} ; \ + $(INSTALL_DIR) $(DESTDIR)$(EPREFIX)/etc$${instd} || exit $$?; \ + $(INSTALL_FILE) $${srcf} $(DESTDIR)$(EPREFIX)/etc$${instf} || exit $$?; \ + instfiles="$${instfiles} $(DESTDIR)$(EPREFIX)/etc$${instf}" ; \ + done ; \ + for srcf in $(SHAREFILES) ; do \ + instf=/$${srcf#*/} ; \ + instd=$${instf%/*} ; \ + $(INSTALL_DIR) $(DESTDIR)$(EPREFIX)/usr/share/baselayout$${instd} || exit $$?; \ + $(INSTALL_FILE) $${srcf} $(DESTDIR)$(EPREFIX)/usr/share/baselayout$${instf} || exit $$?; \ + instfiles="$${instfiles} $(DESTDIR)$(EPREFIX)/usr/share/baselayout$${instf}" ; \ + done ; \ + sed -e 's|@GENTOO_PORTAGE_EPREFIX@|$(EPREFIX)|g' \ + -i $${instfiles} layout-dirs: # Create base filesytem layout diff --git a/etc/env.d/50baselayout b/etc/env.d/50baselayout index 694a233..736230d 100644 --- a/etc/env.d/50baselayout +++ b/etc/env.d/50baselayout @@ -1,8 +1,8 @@ -# /etc/env.d/50baselayout +# @GENTOO_PORTAGE_EPREFIX@/etc/env.d/50baselayout # Do not edit this file -PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin" -ROOTPATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin" -MANPATH="/usr/local/share/man:/usr/share/man" -INFOPATH="/usr/share/info" +PATH="@GENTOO_PORTAGE_EPREFIX@/usr/local/sbin:@GENTOO_PORTAGE_EPREFIX@/usr/local/bin:@GENTOO_PORTAGE_EPREFIX@/usr/sbin:@GENTOO_PORTAGE_EPREFIX@/usr/bin:@GENTOO_PORTAGE_EPREFIX@/sbin:@GENTOO_PORTAGE_EPREFIX@/bin:@GENTOO_PORTAGE_EPREFIX@/opt/bin" +ROOTPATH="@GENTOO_PORTAGE_EPREFIX@/usr/local/sbin:@GENTOO_PORTAGE_EPREFIX@/usr/local/bin:@GENTOO_PORTAGE_EPREFIX@/usr/sbin:@GENTOO_PORTAGE_EPREFIX@/usr/bin:@GENTOO_PORTAGE_EPREFIX@/sbin:@GENTOO_PORTAGE_EPREFIX@/bin:@GENTOO_PORTAGE_EPREFIX@/opt/bin" +MANPATH="@GENTOO_PORTAGE_EPREFIX@/usr/local/share/man:@GENTOO_PORTAGE_EPREFIX@/usr/share/man" +INFOPATH="@GENTOO_PORTAGE_EPREFIX@/usr/share/info" CONFIG_PROTECT_MASK="/etc/gentoo-release" diff --git a/etc/profile b/etc/profile index 2afd51d..4417c41 100644 --- a/etc/profile +++ b/etc/profile @@ -5,23 +5,23 @@ # # Load environment settings from profile.env, which is created by -# env-update from the files in /etc/env.d -if [ -e /etc/profile.env ] ; then - . /etc/profile.env +# env-update from the files in @GENTOO_PORTAGE_EPREFIX@/etc/env.d +if [ -e '@GENTOO_PORTAGE_EPREFIX@/etc/profile.env' ] ; then + . '@GENTOO_PORTAGE_EPREFIX@/etc/profile.env' fi # You should override these in your ~/.bashrc (or equivalent) for per-user -# settings. For system defaults, you can add a new file in /etc/profile.d/. -export EDITOR=${EDITOR:-/bin/nano} -export PAGER=${PAGER:-/usr/bin/less} +# settings. For system defaults, you can add a new file in @GENTOO_PORTAGE_EPREFIX@/etc/profile.d/. +export EDITOR=${EDITOR:-@GENTOO_PORTAGE_EPREFIX@/bin/nano} +export PAGER=${PAGER:-@GENTOO_PORTAGE_EPREFIX@/usr/bin/less} # 077 would be more secure, but 022 is generally quite realistic umask 022 unset ROOTPATH -# process *.sh files in /etc/profile.d -for sh in /etc/profile.d/*.sh ; do +# process *.sh files in @GENTOO_PORTAGE_EPREFIX@/etc/profile.d +for sh in '@GENTOO_PORTAGE_EPREFIX@/etc/profile.d'/*.sh ; do [ -r "$sh" ] && . "$sh" done unset sh @@ -30,15 +30,15 @@ if [ -n "${BASH_VERSION-}" ] ; then # Newer bash ebuilds include /etc/bash/bashrc which will setup PS1 # including color. We leave out color here because not all # terminals support it. - if [ -f /etc/bash/bashrc ] ; then - # Bash login shells run only /etc/profile - # Bash non-login shells run only /etc/bash/bashrc - # Since we want to run /etc/bash/bashrc regardless, we source it + if [ -f '@GENTOO_PORTAGE_EPREFIX@/etc/bash/bashrc' ] ; then + # Bash login shells run only @GENTOO_PORTAGE_EPREFIX@/etc/profile + # Bash non-login shells run only @GENTOO_PORTAGE_EPREFIX@/etc/bash/bashrc + # Since we want to run @GENTOO_PORTAGE_EPREFIX@/etc/bash/bashrc regardless, we source it # from here. It is unfortunate that there is no way to do # this *after* the user's .bash_profile runs (without putting # it in the user's dot-files), but it shouldn't make any # difference. - . /etc/bash/bashrc + . '@GENTOO_PORTAGE_EPREFIX@/etc/bash/bashrc' else PS1='\u@\h \w \$ ' fi diff --git a/etc/shells b/etc/shells index db18c43..6d0b795 100644 --- a/etc/shells +++ b/etc/shells @@ -1,12 +1,12 @@ -# /etc/shells: valid login shells -/bin/bash -/bin/csh -/bin/dash -/bin/esh -/bin/fish -/bin/ksh -/bin/mksh -/bin/sash -/bin/sh -/bin/tcsh -/bin/zsh +# @GENTOO_PORTAGE_EPREFIX@/etc/shells: valid login shells +@GENTOO_PORTAGE_EPREFIX@/bin/bash +@GENTOO_PORTAGE_EPREFIX@/bin/csh +@GENTOO_PORTAGE_EPREFIX@/bin/dash +@GENTOO_PORTAGE_EPREFIX@/bin/esh +@GENTOO_PORTAGE_EPREFIX@/bin/fish +@GENTOO_PORTAGE_EPREFIX@/bin/ksh +@GENTOO_PORTAGE_EPREFIX@/bin/mksh +@GENTOO_PORTAGE_EPREFIX@/bin/sash +@GENTOO_PORTAGE_EPREFIX@/bin/sh +@GENTOO_PORTAGE_EPREFIX@/bin/tcsh +@GENTOO_PORTAGE_EPREFIX@/bin/zsh diff --git a/share.Linux/passwd b/share.Linux/passwd index 28b54e8..942d683 100644 --- a/share.Linux/passwd +++ b/share.Linux/passwd @@ -1,13 +1,13 @@ -root:x:0:0:root:/root:/bin/bash -bin:x:1:1:bin:/bin:/bin/false -daemon:x:2:2:daemon:/sbin:/bin/false -adm:x:3:4:adm:/var/adm:/bin/false -lp:x:4:7:lp:/var/spool/lpd:/bin/false -sync:x:5:0:sync:/sbin:/bin/sync -shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown -halt:x:7:0:halt:/sbin:/sbin/halt -news:x:9:13:news:/var/spool/news:/bin/false -uucp:x:10:14:uucp:/var/spool/uucp:/bin/false -operator:x:11:0:operator:/root:/sbin/nologin -portage:x:250:250:portage:/var/tmp/portage:/bin/false -nobody:x:65534:65534:nobody:/var/empty:/bin/false +root:x:0:0:root:@GENTOO_PORTAGE_EPREFIX@/root:@GENTOO_PORTAGE_EPREFIX@/bin/bash +bin:x:1:1:bin:@GENTOO_PORTAGE_EPREFIX@/bin:@GENTOO_PORTAGE_EPREFIX@/bin/false +daemon:x:2:2:daemon:@GENTOO_PORTAGE_EPREFIX@/sbin:@GENTOO_PORTAGE_EPREFIX@/bin/false +adm:x:3:4:adm:@GENTOO_PORTAGE_EPREFIX@/var/adm:@GENTOO_PORTAGE_EPREFIX@/bin/false +lp:x:4:7:lp:@GENTOO_PORTAGE_EPREFIX@/var/spool/lpd:@GENTOO_PORTAGE_EPREFIX@/bin/false +sync:x:5:0:sync:@GENTOO_PORTAGE_EPREFIX@/sbin:@GENTOO_PORTAGE_EPREFIX@/bin/sync +shutdown:x:6:0:shutdown:@GENTOO_PORTAGE_EPREFIX@/sbin:@GENTOO_PORTAGE_EPREFIX@/sbin/shutdown +halt:x:7:0:halt:@GENTOO_PORTAGE_EPREFIX@/sbin:@GENTOO_PORTAGE_EPREFIX@/sbin/halt +news:x:9:13:news:@GENTOO_PORTAGE_EPREFIX@/var/spool/news:@GENTOO_PORTAGE_EPREFIX@/bin/false +uucp:x:10:14:uucp:@GENTOO_PORTAGE_EPREFIX@/var/spool/uucp:@GENTOO_PORTAGE_EPREFIX@/bin/false +operator:x:11:0:operator:@GENTOO_PORTAGE_EPREFIX@/root:@GENTOO_PORTAGE_EPREFIX@/sbin/nologin +portage:x:250:250:portage:@GENTOO_PORTAGE_EPREFIX@/var/tmp/portage:@GENTOO_PORTAGE_EPREFIX@/bin/false +nobody:x:65534:65534:nobody:@GENTOO_PORTAGE_EPREFIX@/var/empty:@GENTOO_PORTAGE_EPREFIX@/bin/false