From f7551870209efce978493991f723d839803534f0 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Sun, 13 Jan 2008 13:55:23 +0000 Subject: Change lib name during make, not install. --- mk/scripts.mk | 4 +-- sh/Makefile | 22 ++++++-------- sh/functions.in | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ sh/functions.sh | 86 ------------------------------------------------------ sh/rc-functions.in | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++ sh/rc-functions.sh | 80 -------------------------------------------------- 6 files changed, 177 insertions(+), 181 deletions(-) create mode 100644 sh/functions.in delete mode 100644 sh/functions.sh create mode 100644 sh/rc-functions.in delete mode 100755 sh/rc-functions.sh diff --git a/mk/scripts.mk b/mk/scripts.mk index a7f3dd87..efbca780 100644 --- a/mk/scripts.mk +++ b/mk/scripts.mk @@ -33,6 +33,6 @@ install: realinstall ${INSTALLAFTER} # A lot of scripts don't have anything to clean # Also, some rm implentation require a file argument regardless of error # so we ensure that it has a bogus argument -CLEANFILES?= .bogus +CLEANFILES+= ${OBJS} clean: - rm -f ${OBJS} ${CLEANFILES} + if test -n "${CLEANFILES}"; then rm -f ${CLEANFILES}; fi diff --git a/sh/Makefile b/sh/Makefile index 6ee88013..3412b630 100644 --- a/sh/Makefile +++ b/sh/Makefile @@ -1,29 +1,25 @@ DIR= ${RC_LIB}/sh -INC= functions.sh init-common-post.sh rc-functions.sh rc-mount.sh +SRCS= functions.in rc-functions.in +OBJS= ${SRCS:.in=.sh} +INC= init-common-post.sh rc-mount.sh ${OBJS} BIN= gendepends.sh net.sh runscript.sh MK= ../mk - -INSTALLAFTER= _installafter - # To get NET_LO include ${MK}/os.mk include Makefile.${SUBOS} - include ${MK}/scripts.mk +# Ensure that the lib name is correct +.SUFFIXES: .in .sh +.in.sh: + sed -e 's:/lib/:/${LIBNAME}/:g' $< > $@ + +INSTALLAFTER= _installafter _installafter: - @# Handle lib correctly - if test ${LIBNAME} != "lib"; then \ - sed -i'.bak' -e 's,/lib/,/${LIBNAME}/,g' ${DESTDIR}/${RC_LIB}/sh/functions.sh || exit $$?; \ - rm -f ${DESTDIR}/${RC_LIB}/sh/functions.sh.bak; \ - sed -i'.bak' -e 's,/lib/,/${LIBNAME}/,g' ${DESTDIR}/${RC_LIB}/sh/rc-functions.sh || exit $$?; \ - rm -f ${DESTDIR}/${RC_LIB}/sh/rc-functions.sh.bak; \ - fi ${INSTALL} -d ${DESTDIR}/etc/init.d @# Provide an init script for the loopback interface ln -snf ${RC_LIB}/sh/net.sh ${DESTDIR}/etc/init.d/${NET_LO} || exit $$? @# Put functions.sh into the init.d dir so 3rd party apps don't have to @# be multilib aware ln -snf ${RC_LIB}/sh/functions.sh ${DESTDIR}/etc/init.d || exit $$? - diff --git a/sh/functions.in b/sh/functions.in new file mode 100644 index 00000000..effce67d --- /dev/null +++ b/sh/functions.in @@ -0,0 +1,86 @@ +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +# Allow any sh script to work with einfo functions and friends +# We also provide a few helpful functions for other programs to use + +RC_GOT_FUNCTIONS="yes" + +eindent() +{ + EINFO_INDENT=$((${EINFO_INDENT:-0} + 2)) + [ "${EINFO_INDENT}" -gt 40 ] && EINFO_INDENT=40 + export EINFO_INDENT +} + +eoutdent() +{ + EINFO_INDENT=$((${EINFO_INDENT:-0} - 2)) + [ "${EINFO_INDENT}" -lt 0 ] && EINFO_INDENT=0 + return 0 +} + +yesno() +{ + [ -z "$1" ] && return 1 + + case "$1" in + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;; + [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;; + esac + + local value= + eval value=\$${1} + case "${value}" in + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;; + [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;; + *) vewarn "\$${1} is not set properly"; return 1;; + esac +} + +_sanitize_path() +{ + local IFS=":" p= path= + for p in ${PATH}; do + case "${p}" in + /lib/rc/sbin|/bin|/sbin|/usr/bin|/usr/sbin|/usr/pkg/bin|/usr/pkg/sbin|/usr/local/bin|/usr/local/sbin);; + *) path="${path}:${p}";; + esac + done + + echo "${path}" +} + +# Allow our scripts to support zsh +if [ -n "${ZSH_VERSION}" ]; then + emulate sh + NULLCMD=: + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +fi + +# Add our bin to $PATH +export PATH="/lib/rc/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/pkg/bin:/usr/pkg/sbin:/usr/local/bin:/usr/local/sbin$(_sanitize_path "${PATH}")" +unset _sanitize_path + +for arg; do + case "${arg}" in + --nocolor|--nocolour|-C) + export EINFO_COLOR="NO" + ;; + esac +done + +if [ -t 1 ] && yesno "${EINFO_COLOR:-YES}"; then + if [ -z "${GOOD}" ]; then + eval $(eval_ecolors) + fi +else + # We need to have shell stub functions so our init scripts can remember + # the last ecmd + for _e in ebegin eend error errorn einfo einfon ewarn ewarnn ewend \ + vebegin veend veinfo vewarn vewend; do + eval "${_e}() { local _r; /lib/rc/bin/${_e} \"\$@\"; _r=$?; \ + export EINFO_LASTCMD=${_e}; return \$_r; }" + done +fi diff --git a/sh/functions.sh b/sh/functions.sh deleted file mode 100644 index effce67d..00000000 --- a/sh/functions.sh +++ /dev/null @@ -1,86 +0,0 @@ -# Copyright 2007-2008 Roy Marples -# All rights reserved. Released under the 2-clause BSD license. - -# Allow any sh script to work with einfo functions and friends -# We also provide a few helpful functions for other programs to use - -RC_GOT_FUNCTIONS="yes" - -eindent() -{ - EINFO_INDENT=$((${EINFO_INDENT:-0} + 2)) - [ "${EINFO_INDENT}" -gt 40 ] && EINFO_INDENT=40 - export EINFO_INDENT -} - -eoutdent() -{ - EINFO_INDENT=$((${EINFO_INDENT:-0} - 2)) - [ "${EINFO_INDENT}" -lt 0 ] && EINFO_INDENT=0 - return 0 -} - -yesno() -{ - [ -z "$1" ] && return 1 - - case "$1" in - [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;; - [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;; - esac - - local value= - eval value=\$${1} - case "${value}" in - [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;; - [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;; - *) vewarn "\$${1} is not set properly"; return 1;; - esac -} - -_sanitize_path() -{ - local IFS=":" p= path= - for p in ${PATH}; do - case "${p}" in - /lib/rc/sbin|/bin|/sbin|/usr/bin|/usr/sbin|/usr/pkg/bin|/usr/pkg/sbin|/usr/local/bin|/usr/local/sbin);; - *) path="${path}:${p}";; - esac - done - - echo "${path}" -} - -# Allow our scripts to support zsh -if [ -n "${ZSH_VERSION}" ]; then - emulate sh - NULLCMD=: - alias -g '${1+"$@"}'='"$@"' - setopt NO_GLOB_SUBST -fi - -# Add our bin to $PATH -export PATH="/lib/rc/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/pkg/bin:/usr/pkg/sbin:/usr/local/bin:/usr/local/sbin$(_sanitize_path "${PATH}")" -unset _sanitize_path - -for arg; do - case "${arg}" in - --nocolor|--nocolour|-C) - export EINFO_COLOR="NO" - ;; - esac -done - -if [ -t 1 ] && yesno "${EINFO_COLOR:-YES}"; then - if [ -z "${GOOD}" ]; then - eval $(eval_ecolors) - fi -else - # We need to have shell stub functions so our init scripts can remember - # the last ecmd - for _e in ebegin eend error errorn einfo einfon ewarn ewarnn ewend \ - vebegin veend veinfo vewarn vewend; do - eval "${_e}() { local _r; /lib/rc/bin/${_e} \"\$@\"; _r=$?; \ - export EINFO_LASTCMD=${_e}; return \$_r; }" - done -fi diff --git a/sh/rc-functions.in b/sh/rc-functions.in new file mode 100644 index 00000000..2a57709c --- /dev/null +++ b/sh/rc-functions.in @@ -0,0 +1,80 @@ +# Copyright 2007 Gentoo Foundation +# Copyright 2007-2008 Roy Marples +# All rights reserved. Released under the 2-clause BSD license. + +has_addon() +{ + [ -e "${RC_LIBDIR}/addons/$1.sh" ] || [ -e /lib/rcscripts/addons/"$1".sh ] +} + +import_addon() +{ + if [ -e "${RC_LIBDIR}/addons/$1.sh" ]; then + . "${RC_LIBDIR}/addons/$1.sh" + elif [ -e /lib/rcscripts/addons/"$1".sh ]; then + . /lib/rcscripts/addons/"$1".sh + else + return 1 + fi +} + +start_addon() +{ + ( import_addon "$1-start" ) +} + +stop_addon() +{ + ( import_addon "$1-stop" ) +} + +net_fs_list="afs cifs coda davfs fuse gfs ncpfs nfs nfs4 ocfs2 shfs smbfs" +is_net_fs() +{ + [ -z "$1" ] && return 1 + + # Check OS specific flags to see if we're local or net mounted + mountinfo --quiet --netdev "$1" && return 0 + mountinfo --quiet --nonetdev "$1" && return 1 + + # Fall back on fs types + local t=$(mountinfo --fstype "$1") + for x in ${net_fs_list}; do + [ "${x}" = "${t}" ] && return 0 + done + return 1 +} + +is_union_fs() +{ + [ ! -x /sbin/unionctl ] && return 1 + unionctl "$1" --list >/dev/null 2>&1 +} + +get_bootparam() +{ + local match="$1" + [ -z "${match}" -o ! -r /proc/cmdline ] && return 1 + + set -- $(cat /proc/cmdline) + while [ -n "$1" ]; do + case "$1" in + gentoo=*) + local params="${1##*=}" + local IFS=, x= + for x in ${params}; do + [ "${x}" = "${match}" ] && return 0 + done + ;; + esac + shift + done + + return 1 +} + +# Add our sbin to $PATH +case "${PATH}" in + /lib/rc/sbin|/lib/rc/sbin:*);; + *) export PATH="/lib/rc/sbin:${PATH}";; +esac diff --git a/sh/rc-functions.sh b/sh/rc-functions.sh deleted file mode 100755 index 2a57709c..00000000 --- a/sh/rc-functions.sh +++ /dev/null @@ -1,80 +0,0 @@ -# Copyright 2007 Gentoo Foundation -# Copyright 2007-2008 Roy Marples -# All rights reserved. Released under the 2-clause BSD license. - -has_addon() -{ - [ -e "${RC_LIBDIR}/addons/$1.sh" ] || [ -e /lib/rcscripts/addons/"$1".sh ] -} - -import_addon() -{ - if [ -e "${RC_LIBDIR}/addons/$1.sh" ]; then - . "${RC_LIBDIR}/addons/$1.sh" - elif [ -e /lib/rcscripts/addons/"$1".sh ]; then - . /lib/rcscripts/addons/"$1".sh - else - return 1 - fi -} - -start_addon() -{ - ( import_addon "$1-start" ) -} - -stop_addon() -{ - ( import_addon "$1-stop" ) -} - -net_fs_list="afs cifs coda davfs fuse gfs ncpfs nfs nfs4 ocfs2 shfs smbfs" -is_net_fs() -{ - [ -z "$1" ] && return 1 - - # Check OS specific flags to see if we're local or net mounted - mountinfo --quiet --netdev "$1" && return 0 - mountinfo --quiet --nonetdev "$1" && return 1 - - # Fall back on fs types - local t=$(mountinfo --fstype "$1") - for x in ${net_fs_list}; do - [ "${x}" = "${t}" ] && return 0 - done - return 1 -} - -is_union_fs() -{ - [ ! -x /sbin/unionctl ] && return 1 - unionctl "$1" --list >/dev/null 2>&1 -} - -get_bootparam() -{ - local match="$1" - [ -z "${match}" -o ! -r /proc/cmdline ] && return 1 - - set -- $(cat /proc/cmdline) - while [ -n "$1" ]; do - case "$1" in - gentoo=*) - local params="${1##*=}" - local IFS=, x= - for x in ${params}; do - [ "${x}" = "${match}" ] && return 0 - done - ;; - esac - shift - done - - return 1 -} - -# Add our sbin to $PATH -case "${PATH}" in - /lib/rc/sbin|/lib/rc/sbin:*);; - *) export PATH="/lib/rc/sbin:${PATH}";; -esac -- cgit v1.2.3