# -*-eselect-*- vim: ft=eselect # Copyright 2005-2020 Gentoo Authors # Distributed under the terms of the GNU GPL version 2 or later inherit config DESCRIPTION="Manage /etc/init.d scripts in runlevels" MAINTAINER="eselect@gentoo.org" # get_runlevel PRIVATE # determine the current runlevel get_runlevel() { if type rc-status &>/dev/null; then rc-status -r || die "rc_status failed" 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 line [[ -n ${file} \ && ${file%%.sh} = "${file}" \ && ${file%%\~} = "${file}" \ && -f ${file} \ && -x ${file} ]] \ && read line <"${file}" \ && [[ ${line} =~ ^#!.*(runscript|openrc-run) ]] } # 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 local PATH=/lib/rc/bin:/lib64/rc/bin:${PATH} # path to service_* commands 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; do is_script "${EROOT}/etc/init.d/${script}" \ && "${EROOT}/etc/init.d/${script}" "${command}" done } ### add action describe_add() { echo "Add script to existing runlevel(s)" } describe_add_parameters() { echo "