Introduce LOCAL_PREFIX for a user maintained script location.

This commit is contained in:
Roy Marples 2008-03-03 10:33:42 +00:00
parent 5971d14afd
commit 0aedc02860
7 changed files with 65 additions and 16 deletions

3
README
View File

@ -14,6 +14,7 @@ MKPAM=pam
MKTERMCAP=ncurses MKTERMCAP=ncurses
MKTERMCAP=termcap MKTERMCAP=termcap
PKG_PREFIX=/usr/pkg PKG_PREFIX=/usr/pkg
LOCAL_PREFIX=/usr/local
PREFIX=/usr/local PREFIX=/usr/local
We don't support building a static OpenRC with PAM. We don't support building a static OpenRC with PAM.
@ -23,6 +24,8 @@ You can also brand OpenRC if you so wish like so
BRANDING=\"Gentoo/$(uname -s)\" BRANDING=\"Gentoo/$(uname -s)\"
PKG_PREFIX should be set to where packages install to by default. PKG_PREFIX should be set to where packages install to by default.
LOCAL_PREFIX should be set when to where user maintained packages are.
Only set LOCAL_PREFIX if different from PKG_PREFIX.
PREFIX should be set when OpenRC is not installed to /. PREFIX should be set when OpenRC is not installed to /.
If any of the following files exist then we do not overwrite them If any of the following files exist then we do not overwrite them

View File

@ -16,10 +16,10 @@ include ${MK}/os.mk
# Tweak our shell scripts # Tweak our shell scripts
.SUFFIXES: .sh.in .in .SUFFIXES: .sh.in .in
.sh.in.sh: .sh.in.sh:
sed -e 's:@SHELL@:${SH}:g' -e 's:@LIB@:${LIBNAME}:g' -e 's:@PREFIX@:${PREFIX}:g' -e 's:@PKG_PREFIX@:${PKG_PREFIX}:g' $< > $@ sed -e 's:@SHELL@:${SH}:g' -e 's:@LIB@:${LIBNAME}:g' -e 's:@PREFIX@:${PREFIX}:g' -e 's:@PKG_PREFIX@:${PKG_PREFIX}:g' -e 's:@LOCAL_PREFIX@:${LOCAL_PREFIX}:g' $< > $@
.in: .in:
sed -e 's:@PREFIX@:${PREFIX}:g' -e 's:@PKG_PREFIX@:${PKG_PREFIX}:g' $< > $@ sed -e 's:@PREFIX@:${PREFIX}:g' -e 's:@PKG_PREFIX@:${PKG_PREFIX}:g' -e 's:@LOCAL_PREFIX@:${LOCAL_PREFIX}:g' $< > $@
all: ${OBJS} all: ${OBJS}

View File

@ -31,8 +31,21 @@ depend() {
: :
} }
for _dir in @PREFIX@/etc/init.d @PKG_PREFIX@/etc/init.d; do _done_dirs=
for _dir in \
@PREFIX@/etc/init.d \
@PKG_PREFIX@/etc/init.d \
@LOCAL_PREFIX@/etc/init.d
do
[ -d "${_dir}" ] || continue [ -d "${_dir}" ] || continue
# Don't do the same dir twice
for _d in ${_done_dirs}; do
[ "${_d}" = "${_dir}" ] && continue 2
done
unset _d
_done_dirs="${_done_dirs} ${_dir}"
cd "${_dir}" cd "${_dir}"
for SVCNAME in *; do for SVCNAME in *; do
[ -x "${SVCNAME}" ] || continue [ -x "${SVCNAME}" ] || continue

View File

@ -40,23 +40,25 @@ describe()
yesno ${RC_DEBUG} && set -x yesno ${RC_DEBUG} && set -x
_conf_d=${1%/*}/../conf.d
# If we're net.eth0 or openvpn.work then load net or openvpn config # If we're net.eth0 or openvpn.work then load net or openvpn config
_c=${SVCNAME%%.*} _c=${SVCNAME%%.*}
if [ -n "${_c}" -a "${_c}" != "${SVCNAME}" ]; then if [ -n "${_c}" -a "${_c}" != "${SVCNAME}" ]; then
if [ -e "/etc/conf.d/${_c}.${RC_SOFTLEVEL}" ]; then if [ -e "${_conf_d}/${_c}.${RC_SOFTLEVEL}" ]; then
. "/etc/conf.d/${_c}.${RC_SOFTLEVEL}" . "${_conf_d}/${_c}.${RC_SOFTLEVEL}"
elif [ -e "/etc/conf.d/${_c}" ]; then elif [ -e "${_conf_d}/${_c}" ]; then
. "/etc/conf.d/${_c}" . "${_conf_d}//${_c}"
fi fi
fi fi
unset _c unset _c
# Overlay with our specific config # Overlay with our specific config
if [ -e "/etc/conf.d/${SVCNAME}.${RC_SOFTLEVEL}" ]; then if [ -e "${_conf_d}/${SVCNAME}.${RC_SOFTLEVEL}" ]; then
. "/etc/conf.d/${SVCNAME}.${RC_SOFTLEVEL}" . "${_conf_d}/${SVCNAME}.${RC_SOFTLEVEL}"
elif [ -e "/etc/conf.d/${SVCNAME}" ]; then elif [ -e "${_conf_d}/${SVCNAME}" ]; then
. "/etc/conf.d/${SVCNAME}" . "${_conf_d}/${SVCNAME}"
fi fi
unset _conf_d
# Load any system overrides # Load any system overrides
[ -e @PREFIX@/etc/rc.conf ] && . @PREFIX@/etc/rc.conf [ -e @PREFIX@/etc/rc.conf ] && . @PREFIX@/etc/rc.conf

View File

@ -62,7 +62,14 @@
* /usr/pkg. */ * /usr/pkg. */
#ifdef PKG_PREFIX #ifdef PKG_PREFIX
# define RC_PKG_INITDIR PKG_PREFIX "/etc/init.d" # define RC_PKG_INITDIR PKG_PREFIX "/etc/init.d"
# define RC_PKG_CONFDIR PKG_PREFIX "/usr/local/etc/conf.d" # define RC_PKG_CONFDIR PKG_PREFIX "/etc/conf.d"
#endif
/* LOCAL_PREFIX is for user written stuff, which the base OS and package
* manger don't touch. */
#ifdef LOCAL_PREFIX
# define RC_LOCAL_INITDIR LOCAL_PREFIX "/etc/init.d"
# define RC_LOCAL_CONFDIR LOCAL_PREFIX "/etc/conf.d"
#endif #endif
#define RC_KSOFTLEVEL RC_SVCDIR "/ksoftlevel" #define RC_KSOFTLEVEL RC_SVCDIR "/ksoftlevel"

View File

@ -701,6 +701,12 @@ bool rc_deptree_update_needed (void)
#endif #endif
#ifdef RC_PKG_CONFDIR #ifdef RC_PKG_CONFDIR
! rc_newer_than (RC_DEPTREE, RC_PKG_CONFDIR) || ! rc_newer_than (RC_DEPTREE, RC_PKG_CONFDIR) ||
#endif
#ifdef RC_LOCAL_INITDIR
! rc_newer_than (RC_DEPTREE, RC_LOCAL_INITDIR) ||
#endif
#ifdef RC_LOCAL_CONFDIR
! rc_newer_than (RC_DEPTREE, RC_LOCAL_CONFDIR) ||
#endif #endif
! rc_newer_than (RC_DEPTREE, "/etc/rc.conf")) ! rc_newer_than (RC_DEPTREE, "/etc/rc.conf"))
return (true); return (true);

View File

@ -313,6 +313,7 @@ char *rc_service_resolve (const char *service)
if (service[0] == '/') if (service[0] == '/')
return (xstrdup (service)); return (xstrdup (service));
/* First check started services */
file = rc_strcatpaths (RC_SVCDIR, "started", service, (char *) NULL); file = rc_strcatpaths (RC_SVCDIR, "started", service, (char *) NULL);
if (lstat (file, &buf) || ! S_ISLNK (buf.st_mode)) { if (lstat (file, &buf) || ! S_ISLNK (buf.st_mode)) {
free (file); free (file);
@ -324,6 +325,14 @@ char *rc_service_resolve (const char *service)
} }
memset (buffer, 0, sizeof (buffer)); memset (buffer, 0, sizeof (buffer));
/* Nope, so lets see if the user has written it */
#ifdef RC_LOCAL_INITDIR
snprintf (buffer, sizeof (buffer), RC_LOCAL_INITDIR "/%s", service);
if (stat (buffer, &buf) == 0)
return (xstrdup (buffer));
#endif
if (file) { if (file) {
r = readlink (file, buffer, sizeof (buffer)); r = readlink (file, buffer, sizeof (buffer));
free (file); free (file);
@ -332,7 +341,7 @@ char *rc_service_resolve (const char *service)
} }
snprintf (buffer, sizeof (buffer), RC_INITDIR "/%s", service); snprintf (buffer, sizeof (buffer), RC_INITDIR "/%s", service);
/* So we don't exist in /etc/init.d - check /usr/local/etc/init.d */ /* So we don't exist in /etc/init.d - check RC_PKG_INITDIR */
#ifdef RC_PKG_INITDIR #ifdef RC_PKG_INITDIR
if (stat (buffer, &buf) != 0) { if (stat (buffer, &buf) != 0) {
snprintf (buffer, sizeof (buffer), RC_PKG_INITDIR "/%s", service); snprintf (buffer, sizeof (buffer), RC_PKG_INITDIR "/%s", service);
@ -787,19 +796,28 @@ char **rc_services_in_runlevel (const char *runlevel)
char **list = NULL; char **list = NULL;
if (! runlevel) { if (! runlevel) {
#ifdef RC_PKG_INITDIR #if defined(RC_PKG_INITDIR) || defined(RC_LOCAL_INITDIR)
int i; int i;
char **local = ls_dir (RC_PKG_INITDIR, LS_INITD); #endif
#ifdef RC_PKG_INITDIR
char **pkg = ls_dir (RC_PKG_INITDIR, LS_INITD);
#endif
#ifdef RC_LOCAL_INITDIR
char **local = ls_dir (RC_LOCAL_INITDIR, LS_INITD);
#endif #endif
list = ls_dir (RC_INITDIR, LS_INITD); list = ls_dir (RC_INITDIR, LS_INITD);
#ifdef RC_PKG_INITDIR #ifdef RC_PKG_INITDIR
STRLIST_FOREACH (pkg, dir, i)
rc_strlist_addsortu (&list, dir);
rc_strlist_free (pkg);
#endif
#ifdef RC_LOCAL_DIR
STRLIST_FOREACH (local, dir, i) STRLIST_FOREACH (local, dir, i)
rc_strlist_addsortu (&list, dir); rc_strlist_addsortu (&list, dir);
rc_strlist_free (local); rc_strlist_free (local);
#endif #endif
return (list); return (list);
} }