# -*-eselect-*- vim: ft=eselect # Copyright 1999-2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id$ inherit config DESCRIPTION="Manage /etc/init.d scripts in runlevels" MAINTAINER="eselect@gentoo.org" SVN_DATE='$Date$' VERSION=$(svn_date_to_version "${SVN_DATE}") # source_rc_functions PRIVATE # API for OpenRC or baselayout-1 source_rc_functions() { [[ ${RC_GOT_FUNCTIONS} = yes ]] && return source "${EPREFIX}/etc/init.d/functions.sh" \ || die "Failed to source functions.sh" # baselayout-1 compatibility if [[ -e ${svclib}/sh/rc-services.sh ]]; then source "${svclib}/sh/rc-services.sh" \ || die "Failed to source rc-services.sh" fi } # get_runlevel PRIVATE # determine the current runlevel # this is only functional if source_rc_functions has been called before get_runlevel() { if type rc_runlevel &>/dev/null; then rc_runlevel || die "rc_runlevel failed" elif [[ -n ${SOFTLEVEL} ]]; then echo "${SOFTLEVEL}" else die "Cannot determine runlevel" fi } # list_runlevels PRIVATE # list runlevels for file $1 list_runlevels() { [[ $# -eq 1 ]] || return local x runlevels for x in "${EROOT}"/etc/runlevels/* ; do [[ -d ${x} && -L ${x}/${1} ]] \ && runlevels=(${runlevels[@]} "${x##*/}") done echo -ne "${runlevels[@]}" } # is_script PRIVATE # check if file $1 is a valid init script is_script() { local file=${1} [[ -n ${file} \ && ${file%%.sh} = ${file} \ && ${file%%\~} = ${file} \ && -e ${file} ]] \ && grep "^#\!/sbin/runscript" "${file}" &>/dev/null } # find_scripts PRIVATE # browse directory $1 for init scripts and return a list find_scripts() { for file in ${1}/* ; do is_script ${file} && echo "${file##*/}" done } # find_unused_scripts PRIVATE # find scripts in /etc/init.d not belonging to any runlevel find_unused_scripts() { local file x for file in $(find_scripts "${EROOT}/etc/init.d"); do for x in "${EROOT}"/etc/runlevels/*; do [[ -d ${x} && -L ${x}/${file} ]] && continue 2 done echo "${file##*/}" done } # show_script_status PRIVATE # output list entry for script $1 and show its status show_script_status() { local script=${1} status=unknown x for x in stopping starting inactive started stopped; do if service_${x} ${script}; then status=${x} break fi done case ${status} in stopped) write_kv_list_entry ${script} [${x}] ;; started) write_kv_list_entry ${script} "$(highlight [${x}])" ;; *) write_kv_list_entry ${script} "$(highlight_warning [${x}])" ;; esac } # run_runscript PRIVATE # run RC_RUNSCRIPT with script $2- and command $1 run_runscript() { local command=${1} shift for script in "$@"; do is_script "${EROOT}/etc/init.d/${script}" \ && /sbin/runscript "${EROOT}/etc/init.d/${script}" "${command}" done } ### add action describe_add() { echo "Add script to existing runlevel(s)" } describe_add_parameters() { echo "