#!/bin/bash # ----------- # policy-rc.d # ----------- # # ---------------------------------------------------------- # Lliurex Policy layer (/usr/sbin/policy-rc.d) interface # Sept 2006. Luis Garcia for LliureX # ---------------------------------------------------------- # # ------------------------------------------------------------------------- # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA # ------------------------------------------------------------------------- # set -e # ---------- # VARIABLES # ---------- ACTION_ALLOWED=0 ACTION_FORBIDDEN=101 SYNTAX_ERROR=103 UNKNOWN_ACTION=1 UNKNOWN_INIT_SCRIPT=100 USE_FALLBACK=106 DEFAULT_POLICY=${ACTION_ALLOWED} DEFAULT_CONF="/etc/default/llxcfg-policy" [ ! -r "$DEFAULT_CONF" ] || . ${DEFAULT_CONF} LIST_MODE="" QUIET_MODE="" POLICY_LIB="/usr/share/lliurex/llxcfg-runtime/llxcfg-policyfuncs.sh" [ -e ${POLICY_LIB} ] || error_msg "ERROR: File \"${POLICY_LIB}\" not found" . ${POLICY_LIB} # ---------- # FUNCTIONS # ---------- usage() { error_msg "Usage: $0 [--quiet] [--list] []" } error_msg() { [ -z "${QUIET_MODE}" ] && echo "${1}" >&2 exit ${SYNTAX_ERROR} } # ----- # MAIN # ----- [ -z "$1" ] && usage END_OPTIONS="" while [ -z "${END_OPTIONS}" ] ; do case "$1" in "--quiet") QUIET_MODE="Y" shift ;; "--list") LIST_MODE="Y" shift ;; *) END_OPTIONS="YES" ;; esac done [ -z "$1" ] && usage INIT_SCRIPT="$1" if [ "${LIST_MODE}" ]; then shift echo -n "policy for ${INIT_SCRIPT}" [ "$1" ] && echo -n " (runlevel ${1})" if $0 --quiet ${INIT_SCRIPT} start $@ ; then echo -e ":\n ALL ACTIONS ENABLED" else echo -e ":\n DISABLED FOR: start|restart|reload|force-reload" fi exit 0 fi [ -z "$2" ] && usage ACTIONS="$2" RUN_LEVEL="$3" for ACTION0 in ${ACTIONS}; do ACTION="`echo ${ACTION0} |tr -d "()"`" case "${ACTION}" in start|restart|reload|force-reload) if ! llxpol_test_active_script "${INIT_SCRIPT}" ; then exit ${ACTION_FORBIDDEN} fi ;; stop|force-stop|status) exit ${DEFAULT_POLICY} ;; *) # exit ${UNKNOWN_ACTION} exit ${DEFAULT_POLICY} ;; esac done exit ${DEFAULT_POLICY}