# Copyright 1999-2005 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id: kernel.eselect 342 2006-11-08 22:20:47Z kugelfang $ DESCRIPTION="Manage /sbin/init symlink" MAINTAINER="rmh3093@gmail.com" init_progs="einit jinit initng sysvinit runit" # find a list of init symlink targets find_targets() { for f in $init_progs ; do [[ -f ${ROOT}/sbin/${f} ]] && echo $(basename ${f} ) done } # try to remove the kernel symlink remove_symlink() { rm "${ROOT}/sbin/init" } # set the kernel symlink set_symlink() { target=${1} if is_number "${target}" ; then targets=( $(find_targets ) ) target=${targets[$(( ${target} - 1 ))]} fi if [[ -z ${target} ]] ; then die -q "Target \"${1}\" doesn't appear to be valid!" elif [[ -f "${ROOT}/sbin/${target}" ]] ; then ln -s "${ROOT}/sbin/${target}" "/sbin/init" else die -q "Target \"${1}\" doesn't appear to be valid!" fi } ### show action ### describe_show() { echo "Show the current init symlink" } do_show() { local init write_list_start "Current init symlink:" if [[ -L "${ROOT}/sbin/init" ]] ; then init=$(canonicalise ${ROOT}/sbin/init ) write_kv_list_entry "${init%/}" "" else write_kv_list_entry "(unset)" "" fi } ### list action ### describe_list() { echo "List available init symlink targets" } do_list() { targets=( $(find_targets ) ) write_list_start "Available init symlink targets:" if [[ -n ${targets[@]} ]] ; then local i for (( i = 0 ; i < ${#targets[@]} ; i = i + 1 )) ; do [[ ${targets[${i}]} == $(basename $(canonicalise ${ROOT}/sbin/init)) ]] && \ targets[${i}]="${targets[${i}]} $(highlight '*' )" done write_numbered_list "${targets[@]}" else write_kv_list_entry "(none found)" "" fi } ### set action ### describe_set() { echo "Set a new init symlink target" } describe_set_parameters() { echo "" } describe_set_options() { echo "target : Target name or number (from 'list' action)" } do_set() { if [[ -z ${1} ]] ; then # no parameter die -q "You didn't tell me what to set the symlink to" elif [[ -L "${ROOT}/sbin/init" ]] ; then # existing symlink if ! remove_symlink ; then die -q "Couldn't remove existing symlink" elif ! set_symlink "${1}" ; then die -q "Couldn't set a new symlink" fi elif [[ -e "${ROOT}/sbin/init" ]] ; then # we have something strange die -q "Sorry, ${ROOT}/sbin/init confuses me" else set_symlink "${1}" || die -q "Couldn't set a new symlink" fi } # vim: set ft=eselect :